diff --git a/config.toml b/config.toml index e797b22..c87af19 100644 --- a/config.toml +++ b/config.toml @@ -359,6 +359,21 @@ theme = "doc-theme" parent = "tutorials@all" weight = 10 +[[menu.main]] + name = "PyGate" + url = "/tutorials/all/PyGate/" + identifier = "tutorials@all@PyGate" + parent = "tutorials@all" + weight = 10 + +[[menu.main]] + name = "PoE" + url = "/tutorials/all/PoE/" + identifier = "tutorials@all@PoE" + parent = "tutorials@all" + weight = 12 + + [[menu.main]] name = "WLAN" url = "/tutorials/all/wlan/" diff --git a/content/firmwareapi/pycom/machine/pygate.md b/content/firmwareapi/pycom/machine/pygate.md new file mode 100644 index 0000000..d7b1e7a --- /dev/null +++ b/content/firmwareapi/pycom/machine/pygate.md @@ -0,0 +1,39 @@ +--- +title: "Pygate" +aliases: + - firmwareapi/pycom/machine/pygate.html + - firmwareapi/pycom/machine/pygate.md + - chapter/firmwareapi/pycom/machine/pygate +--- + +The Pygate is an 8-channel LoRaWAN gateway. Connect a WiPy, Gpy or LoPy4 board to the Pygate and flash the Pygate firmware. See the [Pygate tutorial](/tutorials/all/pygate) to get started. + +## Methods + +#### machine.pygate\_init(buff) + +This function is used to initialize the Pygate + +- `buff`: the data contents of the gateway global config json file + +#### machine.pygate\_deinit() + +This shuts down the concentrator. + +#### machine.callback(trigger, handler=None, arg=None) + +- `trigger`: A trigger event(s) for invoking the callback function `handler`, the triggers/events are: + + `machine.PYGATE_START_EVT` + + `machine.PYGATE_STOP_EVT` + + `machine.MP_QSTR_PYGATE_ERROR_EVT` + +- `handler`: The callback function to be called. When not passed to function, any pre-registered callback will be disabled/removed. + +- `arg`: Optional argument to be passed to the callback function. + +#### machine.events() + +Get the Pygate events diff --git a/content/firmwareapi/pycom/network/eth.md b/content/firmwareapi/pycom/network/eth.md new file mode 100644 index 0000000..2e307de --- /dev/null +++ b/content/firmwareapi/pycom/network/eth.md @@ -0,0 +1,70 @@ +--- +title: "Ethernet" +aliases: + - firmwareapi/pycom/network/eth.html + - firmwareapi/pycom/network/eth.md + - chapter/firmwareapi/pycom/network/eth +--- + +The ETH class enables the use of an ethernet connection via the PyEthernet board plugged into a Pygate. + +--- +*NOTE* : +Ethernet support is only available in the Pygate firmware build. + +--- + +*NOTE2* : +The PyEthernet board is connected via SPI bus 3 and GPIO's 17-19 and 21-23. So this bus and pins cannot be used concurrently with ethernet. This also means that on a LoPy4 with Pygate firmware, the LoRa module of the LoPy4 is disabled, since it is also connected via SPI 3. Of course you can still use the LoRa gateway functionality since this uses the LoRa modules on the the Pygate board itself. + +--- + +## Constructors + +### class network.ETH(id=0, ...) + +Create and configure an ETH object. See init for params of configuration. + +```python +from network import ETH +eth = ETH() +``` + +## Methods + + +### eth.init(hostname=None) + +This function starts the Ethernet interface and enables the ethernet adapter. + +`hostname`: set the interface hostname + +### eth.ifconfig(config=\['dhcp' or configtuple\]) + +With no parameters given, this returns a 4-tuple of (ip, subnet mask, gateway, DNS server). + +Optionally specify the configuration parameter: + +- `config='dhcp'` + +If 'dhcp' is passed as a parameter, then the DHCP client is enabled and the IP parameters are negotiated with the DHCP server. + +- `config=(ip, nm, gw, dns)` + +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'))`. + +### eth.hostname(string) + +Set the interface host name. + +### eth.mac() + +Get the ethernet interface mac address. + +### eth.deinit() + +Shuts down the ethernet interface. + +### eth.isconnected() + +Returns `True` if the ethernet link is up and IP is accquired, `False` otherwise. diff --git a/content/tutorials/all/PoE.md b/content/tutorials/all/PoE.md new file mode 100644 index 0000000..2394a21 --- /dev/null +++ b/content/tutorials/all/PoE.md @@ -0,0 +1,22 @@ +--- +title: "PoE" +aliases: + - tutorials/all/PoE.html + - tutorials/all/PoE.md + - chapter/tutorials/all/PoE +--- + +The PyEthernet module has onboard Power over Ethernet (PoE) power supply. This means that you can power your hardware with only an ethernet cable coming from a power injector. However, since the PoE is non-isolated, you must adhere to the following warning! + +WARNING: + +PoE power supply of PyEthernet module has no galvanic isolation. This means, that in accordance with +IEEE 802.3-2005 standard you must make sure that when powered from PoE power injector there are no other external connections to any part of the module or other hardware where it is installed. Such as USB cable, serial to USB bridge, logic analyser, an oscilloscope, etc. + +As in certain hardware configurations it can lead to unrecoverable damage of not only the PyEthernet module but all hardware connected to it. + +Be aware - violation of that requirement voids Pycom warranty. + +The use of battery with PoE is allowed. + +![](/gitbook/assets/PoE-NI.png) diff --git a/content/tutorials/all/PyGate.md b/content/tutorials/all/PyGate.md new file mode 100644 index 0000000..e29202e --- /dev/null +++ b/content/tutorials/all/PyGate.md @@ -0,0 +1,278 @@ +## Pygate + +The Pygate is an 8-channel LoRaWAN gateway. This page will help you get started with it. + +The Pygate board can have an PyEthernet adapter connected which allows an ethernet connection. The PyEthernet also support PoE. Do check the separate [page and warning for PoE-NI!](/tutorials/all/poe) + +### Quickstart + +To connect your Pygate to a LoRa server, follow these steps: + +1. Attach a WiPy, GPy or LoPy4 to the Pygate. The RGB LED of the development board should be aligned with the USB port of the Pygate. +1. Attach the LoRa Antenna to the Pygate. +1. Flash the Pycom Device with with a firmware build where Pygate functionality is enabled. +1. Create a `config.json` for your Pygate and upload it. +1. Create a `main.py` that creates an uplink (wifi, ethernet or lte) and runs the LoRa packet fowarder. +1. Run the `main.py`. +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. +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. + + +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. + + +### Example TTN Wifi + +The following example shows the script and json file to run the Pygate over Wifi connecting to [The Things Network](https://www.thethingsnetwork.org/). + +1. log in to https://console.thethingsnetwork.org/ +1. go to Gateways and register a new gateway +1. select "I'm using a legacy packet forwarder" +1. make up a EUI (8 byte hexadecimal value) and register it on the TTN website +1. enter the EUI in your `config.json` under `gateway_ID` (Just enter the hex digits without the "eui-" prefix and without spaces) +1. select your Frequency Plan +1. select a router - also enter the hostname in your `config.json` under `server_address` +1. enter your wifi SSID and password in `main.py` +1. upload `config.json` and `main.py` and reset the board +1. you will see how it creates the uplink connection and then start the LoRa GW. It will print out some debug information while it is running. After some initialization it will print "LoRa GW started" and the LED will turn green. + + + +```python +from network import WLAN +import time +import machine +from machine import RTC +import pycom + +# Disable Hearbeat +pycom.heartbeat(False) + +# Define callback function for Pygate events +def machine_cb (arg): + evt = machine.events() + if (evt & machine.PYGATE_START_EVT): + # Green + pycom.rgbled(0x103300) + elif (evt & machine.PYGATE_ERROR_EVT): + # Red + pycom.rgbled(0x331000) + elif (evt & machine.PYGATE_STOP_EVT): + # RGB off + pycom.rgbled(0x000000) + +# register callback function +machine.callback(trigger = (machine.PYGATE_START_EVT | machine.PYGATE_STOP_EVT | machine.PYGATE_ERROR_EVT), handler=machine_cb) + +# Connect to a Wifi Network +wlan = WLAN(mode=WLAN.STA) +wlan.connect(ssid='', auth=(WLAN.WPA2, "")) + +while not wlan.isconnected(): + time.sleep(1) + +print("Wifi Connection established") + +# Sync time via NTP server for GW timestamps on Events +rtc = RTC() +rtc.ntp_sync(server="0.pool.ntp.org") + +# Read the GW config file from Filesystem +fp = open('/flash/config.json','r') +buf = fp.read() + +# Start the Pygate +machine.pygate_init(buf) + +``` + +A sample `config.json` file for gateway configuration in EU868 region: + +```json +{ + "SX1301_conf": { + "lorawan_public": true, + "clksrc": 1, + "antenna_gain": 0, + "radio_0": { + "enable": true, + "type": "SX1257", + "freq": 867500000, + "rssi_offset": -164.0, + "tx_enable": true, + "tx_freq_min": 863000000, + "tx_freq_max": 870000000 + }, + "radio_1": { + "enable": true, + "type": "SX1257", + "freq": 868500000, + "rssi_offset": -164.0, + "tx_enable": false + }, + "chan_multiSF_0": { + "enable": true, + "radio": 1, + "if": -400000 + }, + "chan_multiSF_1": { + "enable": true, + "radio": 1, + "if": -200000 + }, + "chan_multiSF_2": { + "enable": true, + "radio": 1, + "if": 0 + }, + "chan_multiSF_3": { + "enable": true, + "radio": 0, + "if": -400000 + }, + "chan_multiSF_4": { + "enable": true, + "radio": 0, + "if": -200000 + }, + "chan_multiSF_5": { + "enable": true, + "radio": 0, + "if": 0 + }, + "chan_multiSF_6": { + "enable": true, + "radio": 0, + "if": 200000 + }, + "chan_multiSF_7": { + "enable": true, + "radio": 0, + "if": 400000 + }, + "chan_Lora_std": { + "enable": true, + "radio": 1, + "if": -200000, + "bandwidth": 250000, + "spread_factor": 7 + }, + "chan_FSK": { + "enable": true, + "radio": 1, + "if": 300000, + "bandwidth": 125000, + "datarate": 50000 + }, + "tx_lut_0": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_1": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_2": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_3": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_4": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_5": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_6": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 9, + "dig_gain": 3 + }, + "tx_lut_7": { + "pa_gain": 0, + "mix_gain": 6, + "rf_power": 11, + "dig_gain": 3 + }, + "tx_lut_8": { + "pa_gain": 0, + "mix_gain": 5, + "rf_power": 13, + "dig_gain": 2 + }, + "tx_lut_9": { + "pa_gain": 0, + "mix_gain": 8, + "rf_power": 14, + "dig_gain": 3 + }, + "tx_lut_10": { + "pa_gain": 0, + "mix_gain": 6, + "rf_power": 15, + "dig_gain": 2 + }, + "tx_lut_11": { + "pa_gain": 0, + "mix_gain": 6, + "rf_power": 16, + "dig_gain": 1 + }, + "tx_lut_12": { + "pa_gain": 0, + "mix_gain": 9, + "rf_power": 17, + "dig_gain": 3 + }, + "tx_lut_13": { + "pa_gain": 0, + "mix_gain": 10, + "rf_power": 18, + "dig_gain": 3 + }, + "tx_lut_14": { + "pa_gain": 0, + "mix_gain": 11, + "rf_power": 19, + "dig_gain": 3 + }, + "tx_lut_15": { + "pa_gain": 0, + "mix_gain": 12, + "rf_power": 20, + "dig_gain": 3 + } + }, + + "gateway_conf": { + "gateway_ID": "XXXXXXXXXXXXXXXX", + "server_address": "router.eu.thethings.network", + "serv_port_up": 1700, + "serv_port_down": 1700, + "keepalive_interval": 10, + "stat_interval": 30, + "push_timeout_ms": 100, + "forward_crc_valid": true, + "forward_crc_error": false, + "forward_crc_disabled": false + } +} +``` diff --git a/static/gitbook/assets/PoE-NI.png b/static/gitbook/assets/PoE-NI.png new file mode 100644 index 0000000..0216805 Binary files /dev/null and b/static/gitbook/assets/PoE-NI.png differ