AdvertisementDatable.toitnamemanufacturer-dataimport ble
import encoding.hex
BEACON-SERVICE ::= ble.BleUuid "FEAA"
SCAN-DURATION ::= Duration --s=3
main:
adapter := ble.Adapter
central := adapter.central
while true:
addresses := Set
data := []
central.scan --duration=SCAN-DURATION: | device/ble.RemoteScannedDevice |
if device.data.service-classes.contains BEACON-SERVICE:
address := hex.encode device.address
addresses.add (address.to-ascii-upper.trim --left "00")
data.add device.data.manufacturer-data
print addresses
print data
sleep Duration/5{BC5729059011}
[#[]][tej@a1278 temperature_beacon]$ jag firmware
Device 'eloquent-fortune' is running Toit SDK v2.0.0-alpha.164
Running on ESP32-Wroom-32 (Olimex ESP32 Gateway)ble.toitremote.toitresources/ble_esp32.cc/**
* Perform a passive scan. I.e., don't send follow-up scan requests to
* each advertiser.
*/
disc_params.passive = 1;disc_params.passive = 0passivepassivegit submodule initTOIT_GIT_VERSIONnamedisc_params.passive = 0;src/resources/ble_esp32.ccESP_LOGEBleCentralManagerResource::_on_discoverydisc_params.passive = 0;manufacturer-dataE (7363) BLE: Discovery Event:
E (7363) BLE: Address: 11:90:05:29:57:bc
E (7363) BLE: RSSI: -61
E (7363) BLE: Event Type: 0
E (7363) BLE: Data Length: 29
E (7363) BLE: Advertisement Data:
02 01 06 03 03 aa fe 15 16 aa fe 21 04 0f 0b d4
18 f8 43 0c 00 d6 ff f0 03 c4 01 1a 2e
E (7373) BLE: Discovery Event:
E (7383) BLE: Address: 11:90:05:29:57:bc
E (7383) BLE: RSSI: -62
E (7383) BLE: Event Type: 4
E (7393) BLE: Data Length: 24
E (7393) BLE: Advertisement Data:
09 16 80 20 66 09 00 00 00 00 0d 09 42 4c 45 30
30 30 30 30 30 30 31 31TOIT_GIT_VERSION=v2.0.0-alpha.164 make esp32
# beacon.toit is the example code from the first post
toit compile --snapshot -o beacon.snapshot beacon.toit
toit tool firmware -e build/esp32/firmware.envelope container install beacon beacon.snapshot
toit tool firmware -e build/esp32/firmware.envelope flash --port /dev/ttyUSB0 --baud 921600
jag monitorDiscoveredPeripheralscan_nextble_hs_adv_parse_fieldsble_hs_adv_parse_fieldsDiscoveredPerihperal09 16 80 20 66 09 00 00 00 0066 09 00 00 00 000d 09 42 4c 45 30 30 30 30 30 30 30 31 31BLE000000011import ble
import encoding.hex
BEACON-SERVICE ::= ble.BleUuid "FEAA"
SCAN-DURATION ::= Duration --s=-1
main:
adapter := ble.Adapter
central := adapter.central
while true:
addresses := Set
data := []
central.scan --duration=SCAN-DURATION
--active=true
--limited-only=false
--interval=160
--window=158:
| device/ble.RemoteScannedDevice |
if device.data.services.contains BEACON-SERVICE:
address := hex.encode device.address-bytes.stringify
print device.identifier
print device.address-bytes
print device.address-type
print device.data
sleep Duration/5an instance with class-id 55
#[0x00, 0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
#[0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
0--limited-only=trueintervalwindow// From C
E (6538) BLE: Discovery Event:
E (6538) BLE: Address: 11:90:05:29:57:bc
E (6538) BLE: RSSI: -89
E (6538) BLE: Event Type: 0
E (6538) BLE: Data Length: 29
E (6538) BLE: Advertisement Data:
02 01 06 03 03 aa fe 15 16 aa fe 21 04 0f 0b d4
17 29 45 b6 ff e1 ff d2 03 f2 01 29 db
E (6548) BLE: Discovery Event:
E (6558) BLE: Address: 11:90:05:29:57:bc
E (6558) BLE: RSSI: -86
E (6558) BLE: Event Type: 4
E (6568) BLE: Data Length: 24
E (6568) BLE: Advertisement Data:
09 16 80 20 66 09 00 00 00 00 0d 09 42 4c 45 30
30 30 30 30 30 30 31 31
// From Toit
ID: #[0x00, 0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address bytes: #[0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address type: 0
Name: null
Data: #[0x02, 0x01, 0x06, 0x03, 0x03, 0xaa, 0xfe, 0x15, 0x16, 0xaa, 0xfe, 0x21, 0x04, 0x0f, 0x0b, 0xd4, 0x17, 0x29, 0x45, 0xb6, 0xff, 0xe1, 0xff, 0xd2, 0x03, 0xf2, 0x01, 0x29, 0xdb]ble_esp32.ccprint "ID: " + device.identifier.stringify
print "Address bytes: " + device.address-bytes.stringify
print "Address type: " + device.address-type.stringify
print "Name: " + device.data.name.stringify
print "Data: " + device.data.to-raw.stringifyRemoteScannedDeviceis-scan-responseprint "ID: $device.identifier"+RemoteScannedDeviceRemoteScannedDeviceListblockDiscoveryScan Responsescanned-device1 := ...
scanned-device2 := ...
merged-blocks := scanned-device1.data.data-blocks + scanned-device2.data.data-blocks
merged-advertisement := Advertisement merged-blocks --no-check-size
print merged-advertisement.name
...durationDiscoveryID: #[0x00, 0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address bytes: #[0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address type: 0
Name: null
Data: #[0x02, 0x01, 0x06, 0x03, 0x03, 0xaa, 0xfe, 0x11, 0x16, 0xaa, 0xfe, 0x20, 0x00, 0x0b, 0xd2, 0x17, 0x33, 0x00, 0x4b, 0xe8, 0x01, 0x
01, 0xf8, 0x3e, 0x16]
Is Scan Response: false
ID: #[0x00, 0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address bytes: #[0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address type: 0
Name: null
Data: #[0x02, 0x01, 0x06, 0x03, 0x03, 0xaa, 0xfe, 0x15, 0x16, 0xaa, 0xfe, 0x21, 0x04, 0x0f, 0x0b, 0xd2, 0x17, 0x33, 0x47, 0xf3, 0xff, 0x
e1, 0xff, 0xd2, 0x03, 0xf2, 0x01, 0x2b, 0x06]
Is Scan Response: false
// Repeats...import ble
import encoding.hex
BEACON-SERVICE ::= ble.BleUuid "FEAA"
SCAN-DURATION ::= Duration --s=1
main:
adapter := ble.Adapter
central := adapter.central
central.scan --duration=SCAN-DURATION
--active=true
--limited-only=true
--interval=160
--window=158:
| device/ble.RemoteScannedDevice |
if device.data.services.contains BEACON-SERVICE:
address := hex.encode device.address-bytes.stringify
print "ID: $device.identifier"
print "Address bytes: $device.address-bytes"
print "Address type: $device.address-type"
print "Name: $device.data.name"
print "Data: $device.data.to-raw"
print "Is Scan Response: $device.is-scan-response"ble_esp32.ccscan_nextBEACON-SERVICEaa fediscovered-device.identifierBEACON-SERVICEfound-devices := {}
central.scan ...
if device.data.contains-service BEACON-SERVICE or found-devices.contains device.identifier:
found-devices.add device.identifier
...BEACON-SERVICEID: #[0x00, 0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address bytes: #[0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address type: 0
Name: null
Data: #[0x02, 0x01, 0x06, 0x03, 0x03, 0xaa, 0xfe, 0x11, 0x16, 0xaa, 0xfe, 0x20, 0x00, 0x0b, 0xd2, 0x18, 0x02, 0x00, 0x4f, 0xa9, 0x65, 0x02, 0x0b, 0x0f, 0xd7]
Is Scan Response: false
ID: #[0x00, 0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address bytes: #[0xbc, 0x57, 0x29, 0x05, 0x90, 0x11]
Address type: 0
Name: BLE000000011
Data: #[0x09, 0x16, 0x80, 0x20, 0x66, 0x09, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x09, 0x42, 0x4c, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x31]
Is Scan Response: true