New to working with C based languages. I'm confused by the types that I keep getting told I can't convert or cast from one kind to another.
I have a sketch on my ESP8266 that takes user information from a web page (user enters an ID for a LIFX bulb). I save that data into EEPROM, and then after a restart, I pull it back out, as such:
// Load Saved Configuration from EEPROM
boolean loadSavedConfig() {
Serial.println("Reading Saved Config....");
String ssid = "";
String password = "";
String eventnm = "";
String lifxbulbid = "";
if (EEPROM.read(0) != 0) {
for (int i = 0; i < 32; ++i) {
ssid += char(EEPROM.read(i));
}
Serial.print("SSID: ");
Serial.println(ssid);
for (int i = 32; i < 96; ++i) {
password += char(EEPROM.read(i));
}
Serial.print("Password: ");
Serial.println(password);
for (int i = 96; i < 128; ++i) {
lifxbulbid += char(EEPROM.read(i)); //local variable for immediate temporary use
lifx_Id += char(EEPROM.read(i)); //global variable for use in sending UDP packet data
}
Serial.print("Lifx Bulb ID: ");
Serial.println(lifxbulbid);
WiFi.begin(ssid.c_str(), password.c_str());
return true;
}
else {
Serial.println("Saved Configuration not found.");
return false;
}
}
Once I have this value, I am told I need it in a uint8_t array to pass onto the LIFX UDP LAN protocol.
ie:
uint8_t dest[] = {0xd0, 0x73, 0xd5, 0x13, 0xe7, 0x10};
An example of the Id of the bulb is normally (printed on the bulb): D073D513E710 but I can enter them into the webpage however I want - so I can convert to the "hex" code manually or not.
I've been working with my variable " lifx_Id " as a String and as char - but haven't been able to convert or cast it for the protocol to use. How can I do that?
I'm assuming it's easier to parse it out of the webpage - but EEPROM memory isn't huge, so I felt that saving it as a 12 digit string was easiest and then casting it appropriately after would work. But so far no luck.
So to summarize - ideally - take a string or char value like - "ABCD12345678" and cast it to a uint8_t array as such: "uint8_t dest[] where it equals {0xd0, 0x73, 0xd5, 0x13, 0xe7, 0x10}"
Thanks for any insight and assistance!