EDIT [2018-06-05]: I have updated the code with the Firmware 1.18.+ releases. The code is available at our Growing Data Foundation Github.
These notes are to assist Australian IoT enthusiasts to get started in connecting a LoPy to The Things Network as it is unfortunately (not yet) straight forward to make them work with the current AU-915 TTN Channel plans. As the initiator of the local Adelaide Community of The Things Network I have been experimenting with a number of devices to connect sensors to #TTNADL. One of my personal favourites is the Pycom LoPy as a nice middle-ground between capabilities and technical complexity.
However I ran into a problem where the LoPy would not get a signal back from the TTN network when joining over OTAA even though the TTN Console (http://console.thethingsnetwork.org/) the device showed as connected. With some friendly help from Jose Marcelino at the Pycom Forum this turned out to be an issue with the 915MHz frequency regions. Since there is no actual a standard governing which of the channels are used by TTN gateways, what is outlined here is what is implemented by most TTN communities down under (I know that at least ADL, BNE, SYD and WOL adhere to those). This is the typical Sub-band 2 (Channel 8-15) implementation of AU ISM 915 with TTN Gateways.
This channel plan is also implemented by the install script for the MultiTech Conduit Gateways which are currently the most common gateways installed across Australia (see https://github.com/TheThingsNetwork/gateway-conf/blob/master/AU-global_conf.json)
Channel# | Direction | Frequency MHz | Bandwidth kHz | Data rate |
---|---|---|---|---|
8 | up | 916.8 | 125 | DR0 – DR3 |
9 | up | 917.0 | 125 | DR0 – DR3 |
10 | up | 917.2 | 125 | DR0 – DR3 |
11 | up | 917.4 | 125 | DR0 – DR3 |
12 | up | 917.6 | 125 | DR0 – DR3 |
13 | up | 917.7 | 125 | DR0 – DR3 |
14 | up | 918.0 | 125 | DR0 – DR3 |
15 | up | 918.2 | 125 | DR0 – DR3 |
65 | up | 917.5 | 500 | DR4 |
0 | down | 923.3 | 500 | DR8 – DR13 |
1 | down | 923.9 | 500 | DR8 – DR13 |
2 | down | 924.5 | 500 | DR8 – DR13 |
3 | down | 925.1 | 500 | DR8 – DR13 |
4 | down | 925.7 | 500 | DR8 – DR13 |
5 | down | 926.3 | 500 | DR8 – DR13 |
6 | down | 926.9 | 500 | DR8 – DR13 |
7 | down | 927.5 | 500 | DR8 – DR13 |
To set the LoPy unit up it needs to have the set frequency plan removed and the region specific frequency plan loaded (even though they were bought as 915Mhz units). I have created some quick Python code to set up the LoPy with the above channel structure as the default settings for those devices do not work. Note that you have to remove the default channel settings and add the correct ones before you can successfully register and send data.
Below is my adaptation of the LoPy LoraWAN example to work with TTN in Australia. Please note that the LoPy Lora class only accepts DR values from 1-7. Suggestions more than welcome.
from network import LoRa | |
import time | |
import binascii | |
import pycom | |
pycom.heartbeat(False) #needs to be disabled for LED functions to work | |
pycom.rgbled(0x7f0000) #red | |
#Set AppEUI and AppKey - use your values from the device settings --> https://console.thethingsnetwork.org/ | |
app_eui = binascii.unhexlify('1234567890ABCDEF') | |
app_key = binascii.unhexlify('1234567890ABCDEF1234567890ABCDEF') | |
lora = LoRa(mode=LoRa.LORAWAN, public=1, adr=0, tx_retries=0) | |
# Remove default channels | |
for index in range(0, 72): | |
lora.remove_channel(index) | |
# Set AU ISM 915 channel plan for TTN Australia | |
for index in range(8, 15): | |
lora.add_channel(index, frequency=915200000+index*200000, dr_min=0, dr_max=3) | |
lora.add_channel(65, frequency=917500000, dr_min=4, dr_max=4) | |
for index in range(0, 7): | |
lora.add_channel(index, frequency=923300000+index*600000, dr_min=0, dr_max=3) | |
#Join TTN Network via OTAA | |
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) | |
# wait until the module has joined the network | |
while not lora.has_joined(): | |
pycom.rgbled(0x7f7f00) #yellow | |
time.sleep(5) | |
print('Trying to join TTN Network!') | |
pass | |
print('Network joined!') | |
pycom.rgbled(0x007f00) #green |
Hope this helps other LoPy owners in Australia to connect to The Things Network. And if you are in Adelaide why don’t you come along to our OpenData and IoT Meetup ? Let’s build this thing together.
Leo, a massive thanks for writing this. I have been plugging away in Perth to get a LoPy connected to TTN without much success!
Unfortunately I am stuck at the previous step; unable to connect to TTN in the first place!
I note your post was a few months ago now. Has Pycom adjusted their firmware to include any of the adjusted channel frequencies?
This code used to work for me and my team, but lately when we’ve been trying (on multiple devices) it seems to never work. TTN can see the join requests coming through, but has_joined() is never True on the LoPy.
I had a similar issue after the upgrade of the TTN backend a few months ago. Upgrading the LoPy firmware to the latest version fixed that issue for me.
Hi Leo,
Thanks for this data — it has worked for me. I would like to understand it a bit better though. I’m using DR4, which means with this setup I can use only 1 frequency, which seems to violate the LoRa standards.
It seems to me that the issue would be between the LoPy and the Multitech conduit. Is there an issue with the Multitech configuration script from TTN, a hardware issue, or a spectrum issue? It seems that I should be able to change configuration on the Multitech, then change the LoPy code configuring the channels and then the LoPy LoRaWan stack would change channels after every transmission. Or am I looking at things too simply?
Thanks for you help,
Brian
Hi Leo, I am working through trying to connect my lopy with help from Marcelino from the Pycom forum to a multitech conduit gateway . I thought i would just try your code and it doesn’t work for me.. What settings do I need on the conduit? I change it to Sub band 2 but what else??,
Cheers
Sean
Hi Sean,
My conduits are set up using Jac Kersing’s install script on GitHub. The code has changed recently (Jose has actually posted this on the TTN Slack). I will do an update to that article when I have a moment.
Cheers,
Leo
[mammoth thread bump]
Is this still the recommended code, or can it be simplified a bit now? It is actually working on my LoPy 1 on 1.20.2.r4, but I’m wondering whether the code can be simplified now, after all this time.