Convert String to HEX
Posted: Sat Jun 06, 2015 8:41 pm
I'm having trouble with some strings when posting a MAC Address.
This returns as a series of numbers:
However, I believe it should be something much more akin to this:
I tried including ",HEX" in the String(), unfortunately it fails to compile. I'm not getting an error, it simply hangs on compilation, as illustrated in the example code below:
I realize this is more of a Arduino question, less of a ESP8266 question -- but I was hoping someone could offer a simple fix. If anyone has experience combining strings and sees any improvements I could make, even that would be greatly appreciated.
Code: Select all
WiFi.macAddress(mac);
String PostData="submission={\"DeviceID\":\"";
PostData=String(PostData+mac[5]);PostData=PostData+":";
PostData=String(PostData+mac[4]);PostData=PostData+":";
PostData=String(PostData+mac[3]);PostData=PostData+":";
PostData=String(PostData+mac[2]);PostData=PostData+":";
PostData=String(PostData+mac[1]);PostData=PostData+":";
PostData=String(PostData+mac[0]);
PostData=PostData+"\",";
PostData=PostData+"\"RSSI\":\"";
PostData=String(PostData+rssi);
PostData=PostData+"\"}";
Serial.println(PostData);
This returns as a series of numbers:
Code: Select all
submission={"DeviceID":"217:126:163:52:254:24","RSSI":"-44"}
However, I believe it should be something much more akin to this:
Code: Select all
00:0a:95:9d:68:16 (example only)
I tried including ",HEX" in the String(), unfortunately it fails to compile. I'm not getting an error, it simply hangs on compilation, as illustrated in the example code below:
Code: Select all
PostData=String(PostData+mac[2],HEX);PostData=PostData+":";
I realize this is more of a Arduino question, less of a ESP8266 question -- but I was hoping someone could offer a simple fix. If anyone has experience combining strings and sees any improvements I could make, even that would be greatly appreciated.