Hi there, in my project, I need to use a Heltec WIFI Lora 32 as a receiver and three others as the Lora sender labelled 1,2 and 3, sending temperature and humidity data. Im using your module 11 as reference and edited some of the code according to my need, but it seems not work. So my question is;
- How to sort out the incoming data into specific variable based on the labelled lora sender? for example, temperature and humidity data from sender#2 will go into variable temperature2 and humidity2 respectively.
- How can I determine the data is coming from which sender? because function Lora.readString() can grab any incoming Lora data right?
Hope you can help me, thank you.
Hi.
To sort out the data and figure out where it came from, I suggest that you add some sort of identification to the message on the sender side.
For example, sender number 1 sends a message in the following format:
“1#Temperature/Humidity”
The message from sender 2:
“2#Temperature/Humidity”
Then, in the receiver side add an if statement to associate each measurement with the corresponding variable.
Something as we do in this code, lines 222 to 229: https://github.com/RuiSantosdotme/ESP32-Course/blob/master/code/LoRa_Project/LoRa_Receiver/LoRa_Receiver.ino
for example:
// checks if the message contains the "1#" characters if senderID = LoRaData.indexOf(1#)>0{ //this is data from sensor 1 //save the data on corresponding variables }
add some more if statements to identify the messages from other senders.
The LoRa.readString() method grabs any incoming data nomatter where it cames from, unless you set a syncword (this is more useful for a single receiver and sender).
In your case, you can try to use the strategy I’ve described, or you can take a look at the LoRaSimpleGateway and LoRaSimpleNode example on the library examples: https://github.com/sandeepmistry/arduino-LoRa/tree/master/examples
Please note, that I haven’t tested those examples, so I’m not sure if they will work for your scenario.
I hope this helps.
Regards,
Rui
Thanks for the idea, right now its work by using this code below:
senderID = LoRaData.substring(0, pos1);
if (senderID == “1”){
display.setCursor(0,0);
display.print(“SenderID: “);
display.setCursor(80,0);
display.print(senderID);
display.display();
temperature = LoRaData.substring(pos1+1, pos2);
humidity = LoRaData.substring(pos2+1, pos3);
batteryLevel = LoRaData.substring(pos3+1, LoRaData.length());
display.setCursor(0,8);
display.print(“Temperature: “);
display.setCursor(80,8);
display.print(temperature);
display.display();
display.setCursor(0,16);
display.print(“Humidity: “);
display.setCursor(80,16);
display.print(humidity);
display.display();
}
if (senderID == “2”){
display.setCursor(0,0);
display.print(“SenderID: “);
display.setCursor(80,0);
display.print(senderID);
display.display();
temperature_2 = LoRaData.substring(pos1+1, pos2);
humidity_2 = LoRaData.substring(pos2+1, pos3);
batteryLevel_2 = LoRaData.substring(pos3+1, LoRaData.length());
display.setCursor(0,8);
display.print(“Temperature: “);
display.setCursor(80,8);
display.print(temperature_2);
display.display();
display.setCursor(0,16);
display.print(“Humidity: “);
display.setCursor(80,16);
display.print(humidity_2);
display.display();
}
But there is a question in my head now, is it possible for both of them to receive the data at the same time? If so, am I gonna lose some information from a sender?
I don’t think so, LoRa can’t guarantee the message will receive the data… Only if you send an extra message to the sender to confirm the message. Sorry for taking so long to get back to you, but I was without internet for the last couple of days during a trip.
You can also give a progressive number in a sender message, so you can know if you loose something.
Something like this :
1000000001+msg
1000000002+msg
and so on..
Yes, you can do that, but as you said it’s never guaranteed the message will be received and if you need 100% accuracy LoRa is not a good option-