sandeepmistry / arduino-LoRa

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

How can i convert a byte to an integer? #636

Open martinmmi opened 1 year ago

martinmmi commented 1 year ago

Hello,

i have a short question. How can i convert one byte (0x0a) to an Integer (10)?

I transmit the lora tx power from the base to the receiver, that every unit have the same txpower.

I use this example: https://github.com/sandeepmistry/arduino-LoRa/blob/master/examples/LoRaDuplexCallback/LoRaDuplexCallback.ino

Thats my code in the base, where is the txpower value transmitted.

void sendMessage(String message) { LoRa.beginPacket();
LoRa.write(destination);
LoRa.write(localAddress);
LoRa.write(byte_txpower);
LoRa.write(msgCount);
LoRa.write(message.length());
LoRa.print(message);
LoRa.endPacket();
msgCount++;
}

Now when iam reading the transmitted data with byte incomingTxPower = LoRa.read(); // incoming txpower

And the value was a 17, I get only the 23.

I read in this forum, but i didnt understand it.

https://stackoverflow.com/questions/12240299/convert-bytes-to-int-uint-in-c

Geetings -Martin

AAJAY5 commented 10 months ago

You need to read in this sequence to get txpower.

byte recvID= LoRa.read(); // incoming txpower byte sendID= LoRa.read(); // incoming txpower byte txpower = LoRa.read(); // incoming txpower