joining OTAA and then sending location data

  • @dan nothing in lopy4 is mounted on the pytrack and powered by USB. LED heartbeat was flashing until I uploaded the below code to the board.

    from network import LoRa
    import socket
    import time
    import ubinascii
    # Initialise LoRa in LORAWAN mode.
    # Please pick the region that matches where you are using the device:
    # Asia = LoRa.AS923
    # Australia = LoRa.AU915
    # Europe = LoRa.EU868
    # United States = LoRa.US915
    lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.IN865)
    # create an OTAA authentication parameters
    app_eui = ubinascii.unhexlify('xxxxxxxxxxxxx')
    app_key = ubinascii.unhexlify('xxxxxxxxxxxxxxxxx')
    # join a network using OTAA (Over the Air Activation)
    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():
        print('Not yet joined...')
    # 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
    # (waits for the data to be sent and for the 2 receive windows to expire)
    # send some data
    s.send(bytes([0x01, 0x02, 0x03]))
    # make the socket non-blocking
    # (because if there's no data received it will block forever...)
    # get any data received (if any...)
    data = s.recv(64)

  • @abhishek2101 Hi! Do you have anything in your Do you have anything connected to it? Is the LED heartbeat flashing?

  • @robert-hh i was able to upload but it does not run automatically after i disconnect and reconnect the module. Am i missing something ?

  • @abhishek2101 FTP. See the related section in the manual.

Log in to reply

Pycom on Twitter