bledev.environmental
Environmental Sensing Service (0x181A): temperature, humidity, pressure and UV index.
Serve the readings your board has and update them as they change:
from bledev.environmental import EnvironmentalSensing
weather = EnvironmentalSensing(temperature=True, humidity=True, pressure=True)
ble.register_services(weather.service)
connection = await ble.advertise(name="Weather", services=[weather.SERVICE])
weather.update(temperature=21.5, humidity=40.2, pressure=101325.0)
Each reading is its own characteristic, which a central can read or subscribe
to. Units are degrees Celsius, percent relative humidity, pascals and the UV
index. The service converts them to the specification’s fixed-point formats:
temperature in 0.01 degrees, humidity in 0.01 percent and pressure in 0.1 pascal.
A reading you haven’t set yet reads “not known”, as the specification defines it.
update(temperature=None) leaves that reading alone.
ble.register_services() replaces whatever was registered before, so pass
this service together with the others. Any peripheral backend serves it:
MicroPython (bledev.mpble), CircuitPython (bledev.cpble) and the fake one
for tests.
- bledev.environmental.encode_temperature(celsius)[source]
Temperature as sint16 in 0.01 degrees Celsius.
- class bledev.environmental.EnvironmentalSensing(temperature=False, humidity=False, pressure=False, uv_index=False)[source]
Bases:
objectAn Environmental Sensing Service.
- Parameters:
temperature – True to serve Temperature.
humidity – True to serve Humidity.
pressure – True to serve Pressure.
uv_index – True to serve UV Index.
- characteristics
The served readings’
bledev.Characteristic, by name.