I'm relatively new to this so I'm struggling to find the right solution to my woes.
I currently have a Lora Node transmitting some Barometric Data to my Lora Receiver/Arduino stack up, this part works fine, a connection between sender and receiver is made and the packet data from the sender appears in the serial monitor.
The issue I have is trying to turn the packet data into variables which I can then use for an IOT dashboard.
I will post the code when I can but essentially the packet data is this;
Packet Received: Temp 22.45
Packet Received: ATP 12.22
Previously all my readings have been in one string such as;
Packet Received: Temp 22.45 ATP 12.22
In the instance of a single string I would just use the substring function to pick out the individual readings and use these.
However with the strings in two packets the substring function seems to get lost because it doesn't actually know which packet im referring to.
Is there an if solution somewhere to look at the string first and if Temp appears then create the temp variable, else create an ATP variable?
You already answered above!! So ignore the below, however I will leave it there for critique.
Thanks a bunch cotestatnt, I'll go have a play with this.
So when doing the below would the rest of this be correct, after checking the packet contains the string I need, I create my variable using the substring function to locate the value only and put these into double.
String packet = "Packet Received: Temp 22.45";
if (packet.indexOf("Temp") > -1) {
temp = packet.substring(22);
}
else if (packet.indexOf("ATP") > -1) {
atp = packet.substring(21);
}
Do bear in mind that you can simplify the receipt of different types of data by sending an array that includes an identifier byte decribing the datatype.
If you used 1 to identify the Temp and 2 to identify ATP, and the data is a float (4 bytes) then you can send 5 byte packets;
For Temp 1,xx,xx,xx,xx
For ATP 2,yy,yy,yy,yy
Or if your sending text based packets, set the first character of the packet to 'T' or 'A' so you dont need to search the packet at all, just read the identifier from the first character.