sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.7k stars 638 forks source link

Display 2 different variables in my display #401

Closed Eduardix2020 closed 4 years ago

Eduardix2020 commented 4 years ago

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!!

IoTThinks commented 4 years ago

Send the first variable as first byte. Followed by second variable as second byte.

Depends on how big is your variable . Or worst case, send a json var1:xxx, var2:yyy