I tested my LoRa RA-02 SX1278 and everything is working fine. What it brings me here, is a question in how to receive 2 different variables in my receiver and receive them separately.
Basically, I copied the following code in my LoRa sender:
Serial.print("Current Floor from LoRa: ");
Serial.println(currentFloor);
// send packet current Floor
LoRa.beginPacket();
LoRa.print(currentFloor);
LoRa.endPacket();
Serial.print("Current state from LoRa: ");
Serial.println(elevator_state);
// send packet current Floor
LoRa.beginPacket();
LoRa.print(elevator_state);
LoRa.endPacket();
Basically here I have 2 different variables to be sent (current floor and elevator state).
Following, the receiver code that I copied in my LoRa receiver.
void loop() {
char value;
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
value = (char)LoRa.read();
Serial.print(value);
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}
As you can see, this last code in the receiver, reads both variables and stores them in "value", regardless if the variable is currentFloor or elevator_state coming from the sender.
What would it be the best way to store these 2 values separately?, Should I write a conditional function? I think it must be a better way to do this.
At the end, my goal is to print these 2 values in my display connected via I2C, that is why they cannot be store in the same "value" since they need to be displayed separately.
I can provide more details to clarify my question.
Hello community,
I tested my LoRa RA-02 SX1278 and everything is working fine. What it brings me here, is a question in how to receive 2 different variables in my receiver and receive them separately.
Basically, I copied the following code in my LoRa sender:
Serial.print("Current Floor from LoRa: "); Serial.println(currentFloor);
// send packet current Floor LoRa.beginPacket(); LoRa.print(currentFloor); LoRa.endPacket();
Serial.print("Current state from LoRa: "); Serial.println(elevator_state);
// send packet current Floor LoRa.beginPacket(); LoRa.print(elevator_state); LoRa.endPacket();
Basically here I have 2 different variables to be sent (current floor and elevator state). Following, the receiver code that I copied in my LoRa receiver.
void loop() { char value; int packetSize = LoRa.parsePacket(); if (packetSize) { // received a packet Serial.print("Received packet '"); // read packet while (LoRa.available()) { value = (char)LoRa.read(); Serial.print(value); } // print RSSI of packet Serial.print("' with RSSI "); Serial.println(LoRa.packetRssi()); } }
As you can see, this last code in the receiver, reads both variables and stores them in "value", regardless if the variable is currentFloor or elevator_state coming from the sender.
What would it be the best way to store these 2 values separately?, Should I write a conditional function? I think it must be a better way to do this.
At the end, my goal is to print these 2 values in my display connected via I2C, that is why they cannot be store in the same "value" since they need to be displayed separately.
I can provide more details to clarify my question.
Thanks a lot in advance!!