PYTHON   22

join_ttn.py

Guest on 12th August 2021 01:19:23 PM

  1. from network import LoRa
  2. import time
  3. import binascii
  4. import socket
  5. import time
  6.  
  7. lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
  8.  
  9. lora.remove_channel(1)
  10. lora.remove_channel(2)
  11. lora.remove_channel(3)
  12.  
  13. lora.add_channel(1, frequency=865062500, dr_min=0, dr_max=5)
  14. lora.add_channel(2, frequency=865402500, dr_min=0, dr_max=5)
  15. lora.add_channel(3, frequency=865985000, dr_min=0, dr_max=5)
  16.  
  17.  
  18. app_eui = binascii.unhexlify('70B3D57ED000A388')
  19. app_key = binascii.unhexlify('B699CC6932B7FACF66BA1582F2638D8C')
  20.  
  21. lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
  22.  
  23. # wait until the module has joined the network
  24. while not lora.has_joined():
  25.     time.sleep(2.5)
  26.     print('Not joined yet...')
  27.  
  28. print('Network joined!')
  29.  
  30. s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
  31. s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
  32. s.setblocking(False)
  33. s.send(bytes([1, 2, 3]))
  34. time.sleep(3.0) # wait for the tx and rx to complete
  35. rx_pkt = s.recv(64)   # get the packet received (if any)
  36. print(rx_pkt)

Raw Paste


Login or Register to edit or fork this paste. It's free.