LoPy ABP Example

As firmware is updated quite often I am not entirely sure. I’m running 0.9.6.B1 at the moment

I am running 0.9.5.B1 which works fine. havent tested the newer one yet.

Just noticed there is an installer for 0.9.6.b1a available now too. Will try this one this evening and let you know the results

@kruisdraad (And everyone that is interested ofcourse) Here is the OTAA code that I used on my Lopy (V0.9.6.B1) to submit a message. After sending one message it needs to be rebooted to send another message.

from network import LoRa
import socket
import binasci

lora = LoRa(mode=LoRa.LORAWAN)

app_eui = binascii.unhexlify('0000000000000000')
app_key = binascii.unhexlify('00000000000000000000000000000000')

lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)

while not lora.has_joined():
    time.sleep(2.5)
    print('Not joined yet...') 

print('joined network!')
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
s.setblocking(False)
s.send(binascii.unhexlify('48656c6c6f20576f726c6421202853656e742066726f6d206d79204c6f507929'))

data = s.recv(64)
print(data)

Ofcourse you do need to set the app_eui and app_key correctly :slight_smile:

Right, but if you loop true s.send you’ll see you can send multiple message

if you press ‘run code’ multiple times you’d hit a but i alraedy reported last week. running a init again seems to break the library or something.

Yesterday I also tried to loop (lora.has_joined() = true) on the s.recv(1) and printing it but only the first 3 bytes came in from TTN. The loop kept on going so has_joined remained true but the lopy did not receive any more messages.

Are you saying that if I create a script without the 3 import lines and run that (After running this normal script) it should also send the message because the libs are already loaded?

Made some progress now have ABP working.

while not lora.has_joined():
print(‘Trying to join LoRa network’)
sleep(1)
pass
print(‘Joined LoRa Network’)

pycom.rgbled(0x00ff00)
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setblocking(False)

while True:
print(‘Sending Packet’)
s.send(‘LoPy’)
print(‘Done sending’)
pycom.rgbled(0x00ffff)
sleep(60)

Now to get it doing something worthwhile.

Hi, can you tell me what changes would apply to connect the Lopy with a Conduit gateway configured for AU915?

Hello,

I used the code of @kruisdraad.
Pymkr says that the lopy joined the network and it says it is sending.
But i can’t see the data on the things network site.

What is going wrong or am i not in range of any gateway?

To get back to my post…

I wasn’t in range of a gateway.
Now i have a ic880a gateway with a raspberry pi 3.
Now it all works.

1 Like

Have a look at: https://github.com/pycom/pycom-libraries/tree/master/examples/lorawan-nano-gateway for working code for:

  1. The Nano Gateway (useful if you have 2+ LoPy’s and no real gateway within range)
  2. Node with OTAA authentication
  3. Node with ABP authentication

As I write hier: https://ictoblog.nl/2017/04/02/lorawan-the-things-network-still-some-love-left it can be rather frustrating to get it all to work, but at the moment (knocks on wood) my LoPy Nano gateway and the LoPy node using ABP work reliably (as far as you can conclude that after 2 days without problems).

I’ve got a MultiTech Conduit in my house, and my other node (MCCI Catena 4450) is online, however, my LoPy doesn’t join. I’ve checked the app_eui and app_key, and they both match that of the device I created. Does anybody have any hints for what I might be doing wrong?

[sorry for ABP off topic] You can find working LoPy OTAA code here: https://github.com/keptenkurk/pyTTNmap and some general experience on dealing with the LoPy here. Hope it helps.

Have you made sure it’s running the latest firmware? Usually it’s required to fix a few issues I found.

os.uname().release says ‘1.17.3.b1’, updated just a few days ago.

I got the module to work. Not quite sure what I had done wrong.

* changed category to Pycom