Skip to content

Commit 2c83a6a

Browse files
committed
service advertising data now reported as a simple array of bytes, not {type:'Buffer',data:...}
1 parent a59d87c commit 2c83a6a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Useful MQTT advertising parts are:
160160
* `/ble/advertise/DEVICE` - JSON for device's broadcast name, rssi and manufacturer-specific data
161161
* `/ble/advertise/DEVICE/manufacturer/COMPANY` - Manufacturer-specific data (without leading company code)
162162
* `/ble/advertise/DEVICE/rssi` - Device signal strength
163-
* `/ble/advertise/DEVICE/SERVICE` - Raw service data (as JSON)
163+
* `/ble/advertise/DEVICE/SERVICE` - Raw service data (as a JSON Array of bytes)
164164
* `/ble/advertise/DEVICE/PRETTY` or `/ble/PRETTY/DEVICE` - Decoded service data. `temp` is the obvious one
165165

166166
To decode the hex-encoded manufacturer-specific data, try:

lib/discovery.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ function onDiscovery(peripheral) {
102102
inRange[addr].data[d.uuid].time > Date.now()-60000)
103103
return;
104104

105-
mqtt.send("/ble/advertise/"+id+"/"+d.uuid, JSON.stringify(d.data));
105+
// Send advertising data as a simple JSON array, eg. "[1,2,3]"
106+
var byteData = [];
107+
for (var i=0;i<d.data.length;i++)
108+
byteData.push(d.data.readUInt8(i));
109+
mqtt.send("/ble/advertise/"+id+"/"+d.uuid, JSON.stringify(byteData));
110+
106111
inRange[addr].data[d.uuid] = { payload : d.data, time : Date.now() };
107112

108113
var decoded = attributes.decodeAttribute(d.uuid,d.data);

0 commit comments

Comments
 (0)