Good day. I have been trying to publish the BLE 31 byte string to the cloud for the past 2 days. I can’t seem to get the correct string together. I either get ASCII, singular bytes, or way too much data.
If someone can assist on how to get the uint8_t buf array to a 31 byte string array so I can publish it.
Thanks so much. One of my attempts to build the string below
void loop() {
int count = BLE.scan(results, SCAN_RESULT_COUNT); // scan how many beacons are around
if (count > 0)
{
uint8_t buf[BLE_MAX_ADV_DATA_LEN];
size_t len;
Serial.printf("%d devices are found:", count);// how many beacons were found
for (int i = 0; i < count; i++) {
BleAddress address = results[i].address; // mac address
Serial.printf("MAC: %s\r\n", address.toString().c_str());
len = results[i].advertisingData(buf, sizeof(buf));
if (len > 0)
{
Serial.printf("Advertising data length: %02d\r\n", results[i].advertisingData.length());
for (size_t j = 0; j < len; j++)
{
Serial.printf("%02x,", buf[j]);
memmove (AdvData,buf,31); // copy the buffer to advdata
}
for (int i=0; i<(sizeof(buf)/sizeof(buf[0]));i++)
{
char s [32];
sprintf(s,"%d",buf[i]);
strcat (AdvData_publish,s);
}
Particle.publish(EVENT_NAME, AdvData_publish , PRIVATE);
String Beacon_name = results[i].advertisingData.deviceName(); // check if the results have an name
if (Beacon_name.length() > 0) {Serial.printlnf("Name: %s", Beacon_name.c_str());}
Serial.println("\r\n");
}
len = results[i].scanResponse(buf, sizeof(buf));
if (len > 0) {
Serial.printf("Scan response data length: %02d\r\n", results[i].scanResponse.length());
for (size_t j = 0; j < len; j++) {
Serial.printf("%02x,", buf[j]);
}
Serial.println("\r\n");
}
}
}
delay(5000);
}