timmbogner / Farm-Data-Relay-System

A system that uses ESP-NOW, LoRa, and other protocols to transport sensor data in remote areas without relying on WiFi.
MIT License
525 stars 116 forks source link

Add leading hex zero to addresses #227

Open timmbogner opened 5 months ago

timmbogner commented 5 months ago

@aviateur17 Hey so this is something that has stumped us both before, but your irrigation code gave me an idea. Here's the proof of concept I wrote:

  Serial.begin(115200);
  uint8_t x = 2;
  Serial.println("It's 0x" + String((x < 16) ? "0" : "") + String(x, HEX));

I applied it to the gateway's ESP-NOW functions and it seems to work. However, when I started expanding it further I realized there are a lot of spots where we'd use this, especially in LoRa. I think we can probably transform it into a reusable function to keep things neat. What do you think?

aviateur17 commented 4 months ago

That looks excellent. We could use a macro like the ones at the top of fdrs_lora.h

#define LZ(a) (" 0x" + String(a < 16) ? "0" : "") + String(a, HEX))

Something like that and then just insert LZ(5) or whatever in the code Great idea!