LoPy ABP Example


#21

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

#22

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


#23

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 ?


#24

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


#25

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:


#26

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


#29

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.


#30

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?


#31

This topic is probably a good starter for your question.

For more information please refer to this nice starting point:


#32

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

https://www.thethingsnetwork.org/docs/draft/lopy/

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


#33

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

That includes building docs


#34

think there has been an update !


#35

think its still not working, not even the new examples


#36

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


#37

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

https://www.thethingsnetwork.org/forum/t/pycom-announcing-a-new-module-fipy/4094/5


#38

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)

lora.BW_125KHZ
lora.CODING_4_5

# 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.
s.setblocking(True)

while True:
    #Do you stuff make data and then send in a loop
    print("sending")
    s.send('hello')
    print("done")
    sleep(5)

(Dave Thornton) #39

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


#40

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


#41

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).


#42

are you running the latest firmware?