Hi! I have 2 LoRa Sx1278 Ra-02 modules, one working as a TX, and one as a RX. The TX sends an integer code like 1653401, but when reading it on the RX I receive something else, I think this has to do with the "char" form LoRa.read()? How to fix this, so I can receive the sent code?
it's 8 bit. The max value you can represent on an int is 32767
use a long if you want to represent 1653401
the other issue remains. You need to receive the message fully and it will be ASCII text - not a value, add a trailing null char to the receiving array to build a cString and convert this text into a long (strtol() can do that). Then you can compare the value.
yes - it opens another can of worms (like endianness, padding in structures, variable types format across platforms, ...) but can be explored for sure.
Well, what you gave me it's working, but I can't get it to work for my needs, so to summerize what I want to do, the TX sends a code, the RX will activate a servo only if it verified that the message from the TX matches so it wouldn't go crazy over other interference and only listen to the TX commands.
Something like:
if(code == buffer) {Servo.write(90);}
Where the code will be initializated with what value you want
I've never used it but I think there is a LoRa.readString() function, so may be something like this could work
const long code = 1469543;
...
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
long value = LoRa.readString().toInt();
if (code == value) {Serial.print("Correct");}
}
}