Skip to content

Commit fb9ab72

Browse files
README.md - redo example for new BTHome class
1 parent 3fd2797 commit fb9ab72

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ Once you've got the modules installed, have a look at the code sample in [main.p
2626

2727
Building your own sensor beacon boils down to this...
2828
1. Import the bthome module
29-
2. Set the device name you want
30-
3. Write the sensor readings to the bthome variables you're using
31-
4. Call bthome.pack_advertisement() with parameters to indicate which data to broadcast
29+
2. Create a new instance of the BTHome class, passing in the device name you want
30+
3. Write the sensor readings to the BTHome properties you're using
31+
4. Call the `pack_advertisement()` method with parameters to indicate what data to broadcast
3232
5. Send that advertising data to `aioble.advertise()`
3333

34-
As MicroPython statements, those steps are:
34+
As MicroPython statements, those steps would be something like this:
3535

3636
```
37-
import bthome
38-
bthome.device_name = "myBeacon"
39-
bthome.temperature = dht.temperature()
40-
bthome.humidity = dht.humidity()
41-
adv_data = bthome.pack_advertisement(bthome.TEMPERATURE_SINT16, bthome.HUMIDITY_UINT16)
37+
from bthome import BTHome
38+
beacon = BTHome("myBeacon")
39+
beacon.temperature = dht.temperature()
40+
beacon.humidity = dht.humidity()
41+
advert = beacon.pack_advertisement(bthome.TEMPERATURE_SINT16, bthome.HUMIDITY_UINT16)
42+
await aioble.advertise(BLE_ADV_INTERVAL_uS, adv_data=advert, connectable=False)
4243
```
4344

4445
See [main.py](main.py) for a more robust example.

0 commit comments

Comments
 (0)