0
\$\begingroup\$

I am trying to communicate using LoRa modules with an ESP32. I can easly communicate with two LoRa modules, but if I want to learn the sender address, the Arduino returns an undefined character. I am using an E70 433nw30s and it has a document for reading and sending a struct like this:

enter image description here

I am using 2 for OUTPUT format which is data + short addres

I am sending this data for testing:

Node 2  deger 222.

as HEX:

4E 6F 64 65 20 32 20 20 64 65 67 65 72 20 32 32 32 2E 

Receiving this data, it has a tail which is the adress of sender, like this:

4E 6F 64 65 20 32 20 20 64 65 67 65 72 20 32 32 32 2E 0D 0A 00 04

The adress of sender is 00 04 and 0A is new line, 0D actually I don't know. The Arduino serial monitor returns undefined characters to the address of the sender.

enter image description here

Output:

12:33:50.084 -> Node 2  deger 222.
12:33:50.084 -> Node 2  deger 222.
12:33:52.916 -> Node 2  deger 222.
12:33:56.073 -> Node 2  deger 222.

How can I properly read the sender address with data?

I am receving this data with this simple code:

HardwareSerial fixajSerial(1);

void setup() {
  Serial.begin(115200);
  fixajSerial.begin(115200, SERIAL_8N1, TX, RX);
}
    
void loop() {
  if (Serial.available()) {
    fixajSerial.write(Serial.read());
  }
    
  while (fixajSerial.available()) { 
    Serial.write(fixajSerial.read());
  } 
}

This is the output with external program:

enter image description here

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

0D is Carriage Return 0A is Line Feed

0D 0A is a standard CR+LF end of line sequence.

It's not the serial reading that returns undefined characters. It's the sender that is sending them, it is just data.

Bytes 00 and 04 are not printable ASCII characters. They are read properly, but you just print them directly as characters, which is invalid. So don't do that.

If you want to print them in human readable format, Arduino likey has a function to print a byte as hex or decimal or binary or whatever number format you like, just read Arduino manual.

\$\endgroup\$
2
\$\begingroup\$

So if you indeed receive your data + address (00 04) what is the problem?

The reason arduino serial monitor shows it as undefined character is because serial monitor is supposed to be used with text only, and 00 04 is not text, it is your two-byte address. But that doesn't mean the data itself is invalid, you just have to treat it as address, not as text.

I would suggest that after you receive a packet of data over UART you look for your end marker (0D 0A) and separate the two bytes after that as address into uint16_t variable. Then do whatever you need to do with that address, you can print it as hex value using Serial.println(addr, HEX); or in decimal with simply Serial.println(addr); if you want. (This is assuming that your data itself won't contain the 0D 0A sequence in the middle, only at the end)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.