How to customize images?

User avatar
framps
Posts: 3
Joined: Fri Jul 03, 2020 8:48 pm

How to customize images?

Postby framps » Wed Jul 08, 2020 8:46 pm

I'm new to the ESP32 world and managed to create a sensor which publishes the measured data via MQTT. Everything works fine so far.

I now want to clone the sensor multiple times. The code is identical all the time but there are some configuration parameters like the MQTT topic and other parameters which will be different for every sensor. On a normal computer I would use environment variables or a JSON config file for this.

What's the suggested way or which alternatives exist to handle this on an ESP?
"Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect." Linus Benedict Torvalds, 28.9.2003

User avatar
framps
Posts: 3
Joined: Fri Jul 03, 2020 8:48 pm

Re: How to customize images?

Postby framps » Tue Aug 04, 2020 7:55 pm

I finally found a solution:

Just use the mac address of the ESP32 and use this to lockup a table which holds the data.

In my case I want to use different mqtt topics and I used the following code to lookup the mqtt topic:

Code: Select all

typedef struct
{
    uint64_t uuid;
    char topic[16];
} esp_hardware_descriptor;

static esp_hardware_descriptor esp_hardware[] = {
  { 0x246ffffbf564, "/sensor/1" },
  { 0xfcf5cccceecc, "/sensor/2" },
  { 0x2462aaaa0464, "/sensor/3" }
};
...

    uint8_t mac[6];
    ESP_ERROR_CHECK(esp_base_mac_addr_get(mac));
    uint64_t uuid=(uint64_t)mac[0] << 40 | (uint64_t)mac[1] << 32 | (uint64_t)mac[2] << 24 | (uint64_t)mac[3] << 16 | (uint64_t)mac[4] << 8 | (uint64_t)mac[5];

  char topic[16]="";
    for (int i=0; i<sizeof(esp_hardware); i++) {
      if ( esp_hardware[i].uuid == uuid ) {
        strcpy(topic,esp_hardware[i].topic);
      }
    }
"Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect." Linus Benedict Torvalds, 28.9.2003

Who is online

Users browsing this forum: No registered users and 126 guests