joining OTAA and then sending location data
-
@abhishek2101 There is always a main.py. The question is, whether it is the right one. You could try to give your file a different name, like otaa_test.py, and start it form the REPL prompt with:
import otaa_test
Thatis anyhow the preferred method - putting you own logic in separate files and start that from main.py with import xxxxx -
@robert-hh i have put the following code in mylora.py and uploaded the same to the board using pymakr plugin for atom. When I upload I see a directory structure created (image attached) under flash directory. Now, if I want this code to run everytime the module is powered on what should I do ?
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('xxxxxxxx') app_key = ubinascii.unhexlify('xxxxxxxxxx') # 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(): time.sleep(2.5) 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) s.setblocking(True) # 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...) s.setblocking(False) # get any data received (if any...) data = s.recv(64) print(data)
-
@abhishek2101 Add a statement:
import mylora
to main.py -
@robert-hh unfortunately, that is not working for me.
-
@abhishek2101 Does it work, if you call:
import mylora
from the REPL prompt?
if yes, and this statement is inside main.py, do not reset from pymakr, instead push the reset button on the Lopy4.
Pymakr may do a safe boot, which prevents boot.py and main.py from running.
Using my firmware package, you can check the content of main.py and boot.py from the REPL command line by:from upysh import * cat("main.py") cat("boot.py") -
@abhishek2101 You can also look into files using Chrome or the linux file manager, by connecting to:
ftp://<lopy_ip_address>
e.g.
ftp://192.168.4.1 -
@robert-hh it does not work from REPL prompt also. I have also tried reseting from the button.
screenshot attached.
-
@abhishek2101 What I see:
main.py starts and calls mylora.py, and that runs into an error at line 5. So check your script. -
@robert-hh here is the code, dont see any problem with line 5
the same code when i run (using pymakr plugin in atom) without uploading is able to run and join the TTN.
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('xxxxxxx') app_key = ubinascii.unhexlify('xxxxxxx') # 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(): time.sleep(2.5) 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) s.setblocking(True) # 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...) s.setblocking(False) # get any data received (if any...) data = s.recv(64) print(data)``` -
@abhishek2101 There is a difference. When you run the code from pymakr, it is freshly uploaded. If you call it from main.py fro in the terminal window of pymakr, you run the local copy on the device.
What happens, if in the REPL prompt, you enter the command:
import mylora -
@robert-hh nothing happens
attached screenshot

-
@abhishek2101 Since you have importedthat already in main.py, the second one is not executed. You have to remove that "import mylora" first from main.py
-
@robert-hh got it working !!
since i was cutting and pasting the code, there were some truncation problems which were causing the errors. -
@abhishek2101 That's good. besides that, make yourself familiar with ftp (file transfer protocol), who's only purpose is to transfer files. That avoids any copying errros.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login