LoPy ABP Example


But if I convert the DevAddr assigned by TTN to INT it results in 2590387051 and this also gives an error:

>>> # create an ABP authentication tuple (NwkSKey, AppSKey, DevAddr)
>>> auth = (bytes([0x58, 0xB9, 0x47, 0x74, 0xAF, 0x6F, 0x97, 0x43, 0xEA, 0x0C, 0x58, 0xC5, 0x12, 0xA1, 0xDE, 0x68]), bytes([0x32, 0x83, 0xB1, 0xD7, 0x99, 0x05, 0x83, 0x29, 0x8F, 0xE5, 0xE4, 0xE8, 0x1A, 0xE7, 0x0E, 0xD6]), 2590387051)
>>> # join a network using ABP (Activation By Personalization)
>>> lora.join(activation=LoRa.ABP, auth=auth, timeout=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word


Just experimented a little: Values up to 0x7FFFFFFF are OK but 0x80000000 and higher raise an overflow
My guess is that a signed type was used instead of an unsigned type to represent the dev-addr
You can work around this by choosing a dev-addr that is below 0x80000000

But As @kruisdraad mentions ABP isn't working yet, only the first package arrivés, but if that feels like an achievement, just go ahead :slight_smile:

A few things seem to be missing from the code?
import pycom
setting of GREEN to 0x00FF00


Thanks for your tips...
Indeed the code was missing some lines :grinning:

But one more question: in ABP I cannot choose my own dev-addr as far a I know? So how should I choose one below 0x7FFFFFFF ?


Use the ttnctl command like mentioned here by @arjanvanb
And please change your keys because now they are known to the world :blush:


Thank you so much....finally I got my first message through!!!

Now time for my sodaq :wink:

(and yes, I will change those keys :wink:


perhaps @danicampora can that that value type / signed / unsigned in account with the next release


Yes I hope so, I reported the problem on the Pycom forum. But at least there is a workaround by choosing your device address when using the ttnctl command as mentioned above. So it's not as blocking as the 1 packet issue.


I probably don't need it if I don't know what it is--but I'm curious and can't help asking. What's ABP?


This topic is probably a good starter for your question.

For more information please refer to this nice starting point:


Hi all, Daniel Campora is working on a guide for using TTN with LoPy. You can find the current draft at:


If you have corrections or suggestions, just use the edit button to do a quick PR!


as long as stuff aint working, i am not spending another minute on the LoPy

That includes building docs


think there has been an update !


think its still not working, not even the new examples


Cant get the wifi working wither to be able to upload files to the LoPy with the new firmware. When I setup wifi to be a station it crashes


posted a working example using a Lopy with the latest firmware using OTAA and a Pi3 gateway in this topic:



The LoPy Works. Upgrade to latest PyMakr and firmware from the website and you can use the following example:

from network import LoRa
from time import sleep

import socket
import binascii
import struct

# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN, sf=7, tx_power=14)


# create an ABP authentication params
dev_addr = struct.unpack(">l", binascii.unhexlify('XX XX XX XX'.replace(' ','')))[0]
nwk_swkey = binascii.unhexlify('XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX'.replace(' ',''))
app_swkey = binascii.unhexlify('XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX'.replace(' ',''))

# join a network using ABP (Activation By Personalization)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))

# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)

# make the socket blocking.

while True:
    #Do you stuff make data and then send in a loop

(Dave Thornton) #39

Hi, I see a couple of likes but can anyone confirm they have this code working?


try it, it works fine ... as long as you don't want to change the DR/SF


When I'm using the ABP method it always returns true on lora.has_joined(),
I've tried to send a few messages with this method but only one actually came through to TTN.

I did also try the OTAA message, in this case the has_joined function does seem to work and messages get through to TTN more often (But after one message I need to reset the board).


are you running the latest firmware?