I am trying to get the WWN of an ESP8266 to use as a unique code. Whenever I try to concat it into a string using a loop, the last entry always trashes the contents. (Yes, I can write 6 lines to do it one-by-one, but thats a rubbish coding standard that I want to avoid)
According the Arduino rules, the string length is not exceeded, and the variable scope should be correct. I have reversed the order in case element 0 had some special characters but no change. So why does Arduino keep stuffing the data at the end?
pass1 - forward
String strFull="";
String strWork;
// Loop around appending to strFull
for (int x = 6; x > 0; x--) {
int intX = x - 1;
strWork=String(myMac[intX], HEX);
strFull.concat(strWork);
// Serial.printf("MYMAC:%i %s\n", x, String(myMac[x], HEX));
Serial.printf("MYMAC:%i :%s:\n", intX, strWork);
Serial.printf("MYMAC_prog: %s\n", strFull);
}
Serial.printf("concat strFull: %s\n", strFull);
14:13:14.159 -> MYMAC_prog: c5
14:13:14.191 -> MYMAC:4 :86:
14:13:14.191 -> MYMAC_prog: c586
14:13:14.226 -> MYMAC:3 :7:
14:13:14.226 -> MYMAC_prog: c5867
14:13:14.257 -> MYMAC:2 :ae:
14:13:14.257 -> MYMAC_prog: c5867ae
14:13:14.290 -> MYMAC:1 :11:
14:13:14.290 -> MYMAC_prog: c5867ae11
14:13:14.326 -> MYMAC:0 :4c:
14:13:14.326 -> MYMAC_prog: ��?
14:13:14.357 -> concat strFull: ��?
pass 2 - backwards
// Loop around appending to strFull
String strFull="";
String strWork;
for (byte intX = 0; intX < 6; intX++) {
strWork=String(myMac[intX], HEX);
strFull.concat(strWork);
// Serial.printf("MYMAC:%i %s\n", x, String(myMac[x], HEX));
Serial.printf("MYMAC:%i :%s:\n", intX, strWork);
Serial.printf("MYMAC_prog: %s\n", strFull);
}
Serial.printf("concat strFull: %s\n", strFull);
14:21:59.883 -> MYMAC_prog: 4c
14:21:59.920 -> MYMAC:1 :11:
14:21:59.920 -> MYMAC_prog: 4c11
14:21:59.956 -> MYMAC:2 :ae:
14:21:59.956 -> MYMAC_prog: 4c11ae
14:22:00.023 -> MYMAC:3 :7:
14:22:00.023 -> MYMAC_prog: 4c11ae7
14:22:00.023 -> MYMAC:4 :86:
14:22:00.023 -> MYMAC_prog: 4c11ae786
14:22:00.051 -> MYMAC:5 :c5:
14:22:00.051 -> MYMAC_prog: ��?
14:22:00.085 -> concat strFull: ��?
Regards, Ian
[sterretje edit]
fixed code tags