Thanks again, it's working!
My next step is to parse a bssid mqtt payload (using pubsubclient) into a format accepted by
WiFi.begin(ssid, password, 0, targetBSSID);
Something like
uint8_t targetBSSID[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
My mqtt callback function is
void callback(char* _topic, byte* _payload, unsigned int _length)
Is there a str function to do this? I've spent a fair bit of time reading but I get lost in the data types/pointers. This is what I have so far.
if (strstr(_topic, "cmd/bssid")){
if (_length == 17){
//Serial << "\r\nBSSID\r\n";
char bssidStr[7] = { 0 };
byte bssidCnt = 0;
byte dec = 0;
byte cnt = 0;
for (byte i = 0; i < 17; i++){
if (cnt == 1) dec *= 16;
//Serial << i << ":" << _payload[i] << " " << dec << " " << cnt << "\r\n";
if (_payload[i] >= '0' && _payload[i] <= '9'){
dec += _payload[i] - '0';
cnt++;
} else if (_payload[i] >= 'A' && _payload[i] <= 'F'){
dec += _payload[i] - 55;
cnt++;
} // else { // if (_payload[i] == ':'){
//Serial << i << ":" << _payload[i] << " " << dec << " " << cnt << "\r\n";
if (cnt >= 2){
Serial.print("\r\n ");
Serial.print(i);
Serial.print(":");
Serial.print(dec, HEX);
//Serial.print(":");
//bssidStr[bssidCnt] = printf("%02X", dec);
sprintf(&bssidStr[bssidCnt], "%02X", dec);
bssidCnt++;
cnt = 0;
dec = 0;
i++;
//targetBSSID =
}
}
bssidStr[6] = 0;
Serial << "\r\nBSSID: " << bssidStr;
}
//sprintf(bssidStr, "%02X%02X%02X%02X%02X%02X", _payload[1], _payload[4], _payload[7],_payload[10], _payload[13], _payload[16]);
//bssidStr[6] = 0;
//Serial << "\r\ncmd/bssid >" << bssidStr;
/* if (_length == 17){
char* ptr; //start and end pointer for strtol
targetBSSID[0] = strtol(_payload, &ptr, HEX);
for (byte i = 1; i < 6; i++){
//targetBSSID[i] = strtol(ptr+1, &ptr, HEX);
}
}
return;
}
My serial output
0000:00:00:04.478 Mqtt in [test/esp01/cmd/bssid] >AA:BB:CC:DD:EE:FF<
1:AA
4:BB
7:CC
10:DD
13:EE
16:FF
BSSID: ABCDEF
So I'm getting the segments assembled but the sprintf output isn't what I expected. It doesn't seem to be outputting HEX.