user59508: I have been trying to push the data of temp, humidity, and pressure from a sensor to MQTT using ESP 32Cam, and was able to do using the following code:
pressure = bme.readPressure();

//Convert the value to a char array
char preString[16];
dtostrf(pressure, 1, 2, preString);
Serial.print("Pressure: ");
Serial.println(preString);
client.publish("esp32/pressure", preString);

When I started off with the following code for getting the mac address:
chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.

But when I tried to publish the Chip id, that I was getting on the serial monitor, to the MQTT, an error came up with this:
call of overloaded 'String(uint64_t)' is ambiguous
Here's my code that I tried:
char macValue[16];
String(ESP.getEfuseMac()).toCharArray(macValue,16);
client.publish("esp32/ChipID", macValue);


user4143: You would be better off formatting it nicely instead of relying on String...
char macValue[17]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEFuseMac();
sprintf(macValue, "%016x", mac);
client.publish("esp32/ChipID", macValue);

However, I'm not certain that sprintf can cope with a 64 bit value like that directly. If not, you can split it:
char macValue[17]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEFuseMac();
uint32_t hi = mac >> 32;
uint32_t lo = mac;
sprintf(macValue, "%08x%08x", hi, lo);
client.publish("esp32/ChipID", macValue);


59508: <p>I have been trying to push the data of temp, humidity, and pressure from a sensor to MQTT using ESP 32Cam, and was able to do using the following code:</p>

<pre><code>pressure = bme.readPressure();

//Convert the value to a char array
char preString[16];
dtostrf(pressure, 1, 2, preString);
Serial.print("Pressure: ");
Serial.println(preString);
client.publish("esp32/pressure", preString);
</code></pre>

<p>When I started off with the following code for getting the mac address:</p>

<pre><code>chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid&gt;&gt;32));//print High 2 bytes
Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.
</code></pre>

<p>But when I tried to publish the Chip id, that I was getting on the serial monitor, to the MQTT, an error came up with this:</p>

<p><code>call of overloaded 'String(uint64_t)' is ambiguous</code></p>

<p>Here's my code that I tried:</p>

<pre><code>char macValue[16];
String(ESP.getEfuseMac()).toCharArray(macValue,16);
client.publish("esp32/ChipID", macValue);
</code></pre>
 4143: <p>You would be better off formatting it nicely instead of relying on String...</p>

<pre><code>char macValue[17]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEFuseMac();
sprintf(macValue, "%016x", mac);
client.publish("esp32/ChipID", macValue);
</code></pre>

<p>However, I'm not certain that sprintf can cope with a 64 bit value like that directly. If not, you can split it:</p>

<pre><code>char macValue[17]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEFuseMac();
uint32_t hi = mac &gt;&gt; 32;
uint32_t lo = mac;
sprintf(macValue, "%08x%08x", hi, lo);
client.publish("esp32/ChipID", macValue);
</code></pre>
