Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martinmmi opened this issue Mar 15, 2023 · 1 comment
Open

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

martinmmi opened this issue Mar 15, 2023 · 1 comment

Comments

@martinmmi
Copy link

martinmmi commented Mar 15, 2023

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
Copy link

AAJAY5 commented Aug 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants