I need working code for LoRaWAN
I have been reading the forum for over 6 months, however I am still unable to write a working code. Could someone share a working core for OTAA LoRAWAN connection with some sensor data being collected and send(the sensor doesnt't matter, I have almost every type of sensor).
@rachelsimida I gave up. I have my LoPy for 1 year and I cannot find a single working code that reads a sensor (dht22 for example) and sends it to the things network.
@miroslav-petrov Hi I am new as you too. The same problem of you, may I ask if you finish the connection now, if worked can you share your code. Many thanks!
@jcaron I am also curious where this "Network joined!' comes from. I guess its something build in the lopy firmware. I am 100% sure that I am running this code.
@Iplooky I will try to swap the lines and see if it works
@miroslav-petrov There's something weird in your screenshot... The console output shows "Network joined!", but that does not appear in your code? Are you sure you are running the right script?
Iplooky last edited by
@miroslav-petrov that b' ' means that you recieved and empty package, otherwise you should have b'your_message_here'. I think you should swipe line 19 and 18, setblocking it before the data transmision.
t takes quite a while to join, which probably indicates
I am using a local LoRa operator and I don't know where the gateway is. But I don't think the bad connection is the problem since I get a "Network joined!" Do you happen to know where this b" comes from?
@miroslav-petrov try setting the data rate explicitly to 0. How far away is the gateway? Is in indoors or outdoors? What kind of antenna are you using?
It takes quite a while to join, which probably indicates pretty bad communication...
This is a screenshot showing my code and a telnet window to my LoPy after opening the script. I got this "B'" " after executing the script and I get nothing in the application.
@miroslav-petrov There are many ways to do it, but you can do it this way:
s.send(bytes([0x03, 0x67, 0x01, 0x10, 0x05, 0x67, 0x00, 0xff]))
An alternative would be:
s.send(binascii.unhexlify("03 67 01 10 05 67 00 FF".replace(" ","")))
The latter requires an
import binasciiif you don't already have it, but you probably have it already for the OTAA credentials.
@jcaron I want to send the following bytes: Payload (Hex) 03 67 01 10 05 67 00 FF
Can you show me the correct formating I should use in the brackets?
Once you have successfully joined, sending data is simple:
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # Can be used to force a specific data rate / spread factor #s.setsockopt(socket.SOL_LORA, socket.SO_DR, 0) s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, 0) s.send(bytes([your,data,here]));
hat’s your actual issue? Getting the data from the sensor? Joining? Sending data? What netwo
I am trying with both ttn and a local company using everynet servers with cayenne. I am able to get OTAA auth using the example code, but I am not able to write a code in which to send a payload. I just need a good example code that works.
@miroslav-petrov with or without deep sleep, and if so, using what hardware?
What’s your actual issue? Getting the data from the sensor? Joining? Sending data? What network are you connected to? What kind of gateway are you using, how far is it?
You’ll need to provide quite a bit more information for someone to be able to help.