@@ -79,27 +79,24 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
79
79
return ;
80
80
}
81
81
82
- uint8_t *payLoad = advertisedDevice-> getPayload () ;
82
+ BLEUUID eddyUUID = ( uint16_t ) 0xfeaa ;
83
83
84
- BLEUUID checkUrlUUID = (uint16_t )0xfeaa ;
85
-
86
- if (advertisedDevice->getServiceUUID ().equals (checkUrlUUID))
84
+ if (advertisedDevice->getServiceUUID ().equals (eddyUUID))
87
85
{
88
- if (payLoad[11 ] == 0x10 )
86
+ std::string serviceData = advertisedDevice->getServiceData (eddyUUID);
87
+ if (serviceData[0 ] == 0x10 )
89
88
{
90
89
Serial.println (" Found an EddystoneURL beacon!" );
91
90
BLEEddystoneURL foundEddyURL = BLEEddystoneURL ();
92
- std::string eddyContent ((char *)&payLoad[11 ]); // incomplete EddystoneURL struct!
93
91
94
- foundEddyURL.setData (eddyContent );
92
+ foundEddyURL.setData (serviceData );
95
93
std::string bareURL = foundEddyURL.getURL ();
96
94
if (bareURL[0 ] == 0x00 )
97
95
{
98
- size_t payLoadLen = advertisedDevice->getPayloadLength ();
99
96
Serial.println (" DATA-->" );
100
- for (int idx = 0 ; idx < payLoadLen ; idx++)
97
+ for (int idx = 0 ; idx < serviceData. length () ; idx++)
101
98
{
102
- Serial.printf (" 0x%08X " , payLoad [idx]);
99
+ Serial.printf (" 0x%08X " , serviceData [idx]);
103
100
}
104
101
Serial.println (" \n Invalid Data" );
105
102
return ;
@@ -110,23 +107,15 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
110
107
Serial.printf (" TX power %d\n " , foundEddyURL.getPower ());
111
108
Serial.println (" \n " );
112
109
}
113
- else if (payLoad[ 11 ] == 0x20 )
110
+ else if (serviceData[ 0 ] == 0x20 )
114
111
{
115
112
Serial.println (" Found an EddystoneTLM beacon!" );
116
113
BLEEddystoneTLM foundEddyURL = BLEEddystoneTLM ();
117
- std::string eddyContent ((char *)&payLoad[11 ]); // incomplete EddystoneURL struct!
118
-
119
- eddyContent = " 01234567890123" ;
120
-
121
- for (int idx = 0 ; idx < 14 ; idx++)
122
- {
123
- eddyContent[idx] = payLoad[idx + 11 ];
124
- }
114
+ foundEddyURL.setData (serviceData);
125
115
126
- foundEddyURL.setData (eddyContent);
127
116
Serial.printf (" Reported battery voltage: %dmV\n " , foundEddyURL.getVolt ());
128
117
Serial.printf (" Reported temperature from TLM class: %.2fC\n " , (double )foundEddyURL.getTemp ());
129
- int temp = (int )payLoad[ 16 ] + (int )(payLoad[ 15 ] << 8 );
118
+ int temp = (int )serviceData[ 5 ] + (int )(serviceData[ 4 ] << 8 );
130
119
float calcTemp = temp / 256 .0f ;
131
120
Serial.printf (" Reported temperature from data: %.2fC\n " , calcTemp);
132
121
Serial.printf (" Reported advertise count: %d\n " , foundEddyURL.getCount ());
0 commit comments