Skip to content

Commit 21d3913

Browse files
authored
Added Pygate Docs (#265)
Added pygate/pyeth: split into api and tutorial
1 parent 5a8bbc0 commit 21d3913

File tree

4 files changed

+153
-146
lines changed

4 files changed

+153
-146
lines changed

config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,13 @@ theme = "doc-theme"
702702
parent = "firmwareapi@pycom@machine"
703703
weight = 60
704704

705+
[[menu.main]]
706+
name = "Pygate"
707+
url = "/firmwareapi/pycom/machine/pygate/"
708+
identifier = "firmwareapi@pycom@machine@pygate"
709+
parent = "firmwareapi@pycom@machine"
710+
weight = 65
711+
705712
[[menu.main]]
706713
name = "RMT"
707714
url = "/firmwareapi/pycom/machine/rmt/"
@@ -779,6 +786,13 @@ theme = "doc-theme"
779786
parent = "firmwareapi@pycom@network"
780787
weight = 20
781788

789+
[[menu.main]]
790+
name = "Ethernet"
791+
url = "/firmwareapi/pycom/network/eth/"
792+
identifier = "firmwareapi@pycom@network@eth"
793+
parent = "firmwareapi@pycom@network"
794+
weight = 25
795+
782796
[[menu.main]]
783797
name = "Bluetooth"
784798
url = "/firmwareapi/pycom/network/bluetooth/"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: "Pygate"
3+
aliases:
4+
- firmwareapi/pycom/machine/pygate.html
5+
- firmwareapi/pycom/machine/pygate.md
6+
- chapter/firmwareapi/pycom/machine/pygate
7+
---
8+
9+
The Pygate is an 8-channel LoRaWAN gateway. You connect a WiPy or Gpy board to the Pygate and flash a firmware build where the Pygate functionality is enabled. See the [Pygate tutorial](/tutorials/all/pygate) to get started.
10+
11+
## Methods
12+
13+
#### machine.pygate\_init(buff)
14+
15+
This function is used to initialize the Pygate
16+
17+
- `buff`: the data contents of the gateway global config json file
18+
19+
#### machine.pygate\_deinit()
20+
21+
This shuts down the concentrator.
22+
23+
#### machine.callback(trigger, handler=None, arg=None)
24+
25+
- `trigger`: A trigger event(s) for invoking the callback function `handler`, the triggers/events are:
26+
27+
`machine.PYGATE_START_EVT`
28+
29+
`machine.PYGATE_STOP_EVT`
30+
31+
`machine.MP_QSTR_PYGATE_ERROR_EVT`
32+
33+
- `handler`: The callback function to be called. When not passed to function, any pre-registered callback will be disabled/removed.
34+
35+
- `arg`: Optional argument to be passed to the callback function.
36+
37+
#### machine.events()
38+
39+
Get the Pygate events
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "Ethernet"
3+
aliases:
4+
- firmwareapi/pycom/network/eth.html
5+
- firmwareapi/pycom/network/eth.md
6+
- chapter/firmwareapi/pycom/network/eth
7+
---
8+
9+
The ETH class enables the use of an ethernet connection via the PyEthernet board plugged into a Pygate.
10+
11+
---
12+
*NOTE* :
13+
Ethernet support is only available in special Gpy or WiPy firmware builds where this feature has been enabled.
14+
15+
---
16+
17+
## Constructors
18+
19+
### class network.ETH(id=0, ...)
20+
21+
Create and configure an ETH object. See init for params of configuration.
22+
23+
```python
24+
from network import ETH
25+
eth = ETH()
26+
```
27+
28+
## Methods
29+
30+
31+
### eth.init(hostname=None)
32+
33+
This function starts the Ethernet interface and enables the ethernet adapter.
34+
35+
`hostname`: set the interface hostname
36+
37+
### eth.ifconfig(config=\['dhcp' or configtuple\])
38+
39+
With no parameters given, this returns a 4-tuple of (ip, subnet mask, gateway, DNS server).
40+
41+
Optionally specify the configuration parameter:
42+
43+
- `config='dhcp'`
44+
45+
If 'dhcp' is passed as a parameter, then the DHCP client is enabled and the IP parameters are negotiated with the DHCP server.
46+
47+
- `config=(ip, nm, gw, dns)`
48+
49+
If the 4-tuple config is given then a static IP is configured. For example: `eth.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))`.
50+
51+
### eth.hostname(string)
52+
53+
Set the interface host name.
54+
55+
### eth.mac()
56+
57+
Get the ethernet interface mac address.
58+
59+
### eth.deinit()
60+
61+
Shuts down the ethernet interface.
62+
63+
### eth.isconnected()
64+
65+
Returns `True` if the ethernet link is up and IP is accquired, `False` otherwise.

content/tutorials/all/PyGate.md

Lines changed: 35 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
## Pygate
22

3-
__To connect your Pygate to a LoRa server, follow these steps:__
3+
The Pygate is an 8-channel LoRaWAN gateway. This page will help you get started with it.
44

5-
1- Attach a Pycom development board e.g. a Wipy, LoPy4, GPy, to the Pygate. (The RGB LED of the development board should be aligned with the USB port of PyGate)
5+
### Quickstart
66

7-
2- Attach the LoRa Antenna to the Pygate
7+
To connect your Pygate to a LoRa server, follow these steps:
88

9-
3- Flash the Pycom Device with latest PyGate Firmware.
9+
1. Attach a Wipy, or GPy to the Pygate. The RGB LED of the development board should be aligned with the USB port of the Pygate.
10+
1. Attach the LoRa Antenna to the Pygate.
11+
1. Flash the Pycom Device with with a firmware build where Pygate functionality is enabled.
12+
1. Create a `config.json` for your Pygate and upload it.
13+
1. Create a `main.py` that creates an uplink and runs the Pygate packet fowarder.
14+
1. Run the `main.py`.
15+
1. Now it is operational. The communication from other LoRa nodes such as a LoPy4 will now reach the gateway and will receive up and downlink via the PyGate.
16+
1. To stop the Pygate at any time press Ctrl-C on the REPL and run `machine.pygate_deinit()`. It will take a few seconds to stop the gateway tasks and safely power-off the concentrator.
1017

11-
4- Upload the Gateway configuration json file onto the attached Pycom device (via Pymakr on Atom or VSCode). Depending on the type of Pygate (EU868/US915) you should have different config files.
1218

13-
__The following example will demonstrate a simple script for getting started with a Pygate via a Wifi connection for the EU868 region:__
19+
Make sure you supply a config matching your region (EU868, US915, etc), e.g. https://github.com/Lora-net/packet_forwarder/tree/master/lora_pkt_fwd/cfg. If you are in EU region, it should be sufficent to update the example below with your GW ID, the LoRa server address and port number.
20+
21+
22+
### Example TTN Wifi
23+
24+
The following example shows the script and json file to run the Pygate over Wifi connecting to [The Things Network](https://www.thethingsnetwork.org/).
25+
26+
* log in to https://console.thethingsnetwork.org/
27+
* go to Gateways and register a new gateway
28+
* select "I'm using a legacy packet forwarder"
29+
* enter a EUI (8 byte hexadecimal value) - also enter this in your `config.json` for `gateway_ID` (Just enter the digits without the "eui-" prefix)
30+
* select your Frequency Plan
31+
* select a router - also enter the hostname in your `config.json` for `server_address`
32+
* enter your wifi SSID and password in `main.py`
33+
1434

15-
You can use the same file, just enter your GW unique ID, the LoRa server address and port numbers.
1635

1736
```python
1837
from network import WLAN
@@ -21,10 +40,10 @@ import machine
2140
from machine import RTC
2241
import pycom
2342

24-
#Disable Hearbeat
43+
# Disable Hearbeat
2544
pycom.heartbeat(False)
2645

27-
#Define callback function for Pygate Events
46+
# Define callback function for Pygate events
2847
def machine_cb (arg):
2948
evt = machine.events()
3049
if (evt & machine.PYGATE_START_EVT):
@@ -36,10 +55,9 @@ def machine_cb (arg):
3655
elif (evt & machine.PYGATE_STOP_EVT):
3756
# RGB off
3857
pycom.rgbled(0x000000)
39-
40-
# register Callback func
41-
machine.callback(trigger = (machine.PYGATE_START_EVT |
42-
machine.PYGATE_STOP_EVT | machine.PYGATE_ERROR_EVT), handler=machine_cb)
58+
59+
# register callback function
60+
machine.callback(trigger = (machine.PYGATE_START_EVT | machine.PYGATE_STOP_EVT | machine.PYGATE_ERROR_EVT), handler=machine_cb)
4361

4462
# Connect to a Wifi Network
4563
wlan = WLAN(mode=WLAN.STA)
@@ -50,20 +68,20 @@ while not wlan.isconnected():
5068

5169
print("Wifi Connection established")
5270

53-
#Sync time via NTP server for GW timestamps on Events
71+
# Sync time via NTP server for GW timestamps on Events
5472
rtc = RTC()
5573
rtc.ntp_sync(server="0.nl.pool.ntp.org")
5674

57-
#Read the GW config file from Filesystem
75+
# Read the GW config file from Filesystem
5876
fp = open('/flash/config.json','r')
5977
buf = fp.read()
6078

61-
# Start Pygate
79+
# Start the Pygate
6280
machine.pygate_init(buf)
6381

6482
```
6583

66-
A sample Config json file for GW configuration on EU868 region:
84+
A sample `config.json` file for gateway configuration in EU868 region:
6785

6886
```json
6987
{
@@ -253,132 +271,3 @@ A sample Config json file for GW configuration on EU868 region:
253271
}
254272
}
255273
```
256-
To stop the Pygate at any time use:
257-
258-
- REPL -> use CTRL-C
259-
- using deinit function `machine.pygate_deinit()`
260-
261-
This will stop GW tasks and safely power-off the Concentrator.
262-
263-
264-
__Note__: The Pygate packet forwarder is a legacy packet forwarder, so you must make sure you use select the legacy packet forwarder option in TTN as shown below.
265-
266-
![alt_text](https://wiki.dragino.com/images/c/c6/TTN_Create_Gateway_0.png)
267-
268-
269-
## Pygate APIs
270-
271-
###machine Module
272-
273-
#### machine.pygate\_init([buff])
274-
275-
This function is used to initialize the Pygate
276-
277-
- `buff`: the data contents of the gateway global config json file
278-
279-
When no parameter is passed to function the Pygate is just powered on. (will be useful when using pygate as just a concentrator controllable via uart by another device eg. RPi)
280-
281-
#### machine.pygate\_deinit()
282-
283-
This shuts down the concentrator.
284-
285-
#### machine.pygate\_cmd\_decode(buff)
286-
287-
This sends the LoRa gateway command to the concentrator. This is useful when packet forwarder / HAL software is run on a different device (e.g. Rpi) and commands to the concentrator are passed to the Pygate via UART.
288-
289-
#### machine.pygate\_cmd\_get()
290-
291-
This gets the command execution result from concentrator.
292-
293-
An example script demonstrating running packet forwarder software on a different device:
294-
295-
```python
296-
from machine import UART
297-
import machine
298-
import time
299-
import os
300-
import gc
301-
302-
machine.pygate_init(None)
303-
time.sleep(3)
304-
305-
uart = UART(1, 115200, timeout_chars=40, pins=('P23', 'P22'))
306-
307-
while True:
308-
if uart.any():
309-
rx_data = uart.read()
310-
machine.pygate_cmd_decode(rx_data)
311-
tx_data = machine.pygate_cmd_get()
312-
l = uart.write(tx_data)
313-
else:
314-
time.sleep_us(10)
315-
```
316-
317-
#### machine.callback(trigger, handler=None, arg=None)
318-
319-
- `trigger`: A trigger event(s) for invoking the callback function `handler`, the triggers/events are:
320-
321-
`machine.PYGATE_START_EVT`
322-
323-
`machine.PYGATE_STOP_EVT`
324-
325-
`machine.MP_QSTR_PYGATE_ERROR_EVT`
326-
327-
- `handler`: The callback function to be called. When not passed to function, any pre-registered callback will be disabled/removed.
328-
329-
- `arg`: Optional arg to be bassed to callback function.
330-
331-
#### machine.events()
332-
333-
Get the Pygate events
334-
335-
336-
## Pygate Ethernet adapter APIs
337-
338-
`network.ETH` module
339-
340-
### ETH.init(hosname=None)
341-
342-
This function starts the Ethernet interface and enables the ethernet adapter.
343-
344-
`hostname`: set the interface hostname
345-
346-
### ETH. ifconfig(config=\['dhcp' or configtuple\])
347-
348-
With no parameters given, this returns a 4-tuple of (ip, subnet_mask, gateway, DNS_server).
349-
350-
If DHCP is passed as a parameter, then the DHCP client is enabled and the IP params are negotiated with the DHCP server.
351-
352-
If the 4-tuple config is given then a static IP is configured. For instance:
353-
354-
`eth.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))`
355-
356-
### ETH.hostname(string)
357-
358-
Set the interface host name.
359-
360-
### ETH.mac()
361-
362-
Get the ethernet interface mac address.
363-
364-
### ETH.deinit()
365-
366-
Shuts down the ethernet interface.
367-
368-
### ETH.isconnected(Bool)
369-
370-
Returns `True` if the ethernet link is up and IP is accquired, `Fasle` if otherwise
371-
372-
### ETH.register(reg, cmd, value)
373-
374-
Write/read specific register from/to the ksz8851 ethernet controller
375-
376-
`cmd`: 0 to read , 1 to write
377-
378-
Ex: to read register 0x90
379-
380-
`eth.register(0x90,0)`
381-
382-
To write:
383-
384-
`eth.register(0x90, 1, 0x0000)`

0 commit comments

Comments
 (0)