0

I've tried all the supposed solutions for the exact error, pasted into google, that I could find on every forum including this one and no matter the alleged solution I will either get the error about unsigned int to char*, the error below, or invalid pointers.

Why is this platform so completely unfriendly in data type conversion? It's almost as if the creator/s never wanted any data types to be able convert.

Here's my code that is apparently useless:

  char* DeviceName = "Device-" +  ESP.getChipId();
  wifiManager.autoConnect(DeviceName);

Error: invalid conversion from 'const char*' to 'char*' [-fpermissive] char* DeviceName = "Device-" + ESP.getChipId();

Then I tried to use the pointers, but I have no idea what I'm doing and I keep getting invalid pointer errors, and/or invalid conversion errors.

3

1 Answer 1

0

You can use the c function sprintf(, , ...) The char array has to be big enough to hold your text plus a null to terminate the string.

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
  delay(1000);
  char out[20];
  sprintf(out, "Device-%08X",ESP.getChipId()); // %08X\n formats the hex and pads with 0s.

  Serial.println(out);
}

void loop() {}

Output:

Device-005D4D9D
3
  • Thank you! I tried this and it does output a numeric ID, but I wanted the string ID. ESP8266 Chip ID = 005D4D9D <- this should be the ID... Device-6114717 <- not the numeric conversion here Nov 26, 2018 at 2:12
  • you are welcome - helpful user changed the format string to output 8 hex digits instead since that is what you seem to be looking for.
    – SEngstrom
    Nov 26, 2018 at 2:25
  • Learning is good. To eliminate extra characters you can also use sprintf(out, "Device-%X",ESP.getChipId()); Nov 26, 2018 at 2:52

Your Answer

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

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