Open markdoerr opened 4 months ago
We don’t have a specific SHT31 driver but look at this code. The formatting is probably similar. switchdoclabs/SDL_Pi_SHT30: High Reliability Pure Python Drivers for the SwitchDoc Labs Grove SHT30 base Temperature and Humidity Sensorsgithub.comOn May 26, 2024, at 05:32, mark doerr @.***> wrote: Hallo iBeacon BLE reader developers, for a student demonstration project, I tried to write an updated version of the Bluetooth readout of Sensirion SHT31 beacon (blescan.py) with the modern python bleak package, since the original bluetooth python package is outdated: import asyncio from bleak import BleakClient
BLE_DEVICE_MAC_ADDRESS = "E4:A0:36:CA:7B:7E" # BLE_DEVICE_MAC_ADDRESS of the device (beacon) TEMPERATURE_UUID = "00001234-b38d-4985-720e-0f993a68ee41" TEMPERATURE_HANDLE = 49
def calculate_temperature(data): print("temp:", data, type(data)) print("== temp - calc : ", (data / 65536.) * 175. - 45)
async def main(BLE_DEVICE_MAC_ADDRESS): async with BleakClient(BLE_DEVICE_MAC_ADDRESS) as client:
services = client.services
for service in services:
for char in service.characteristics:
print("--->", char.handle)
if char.handle == TEMPERATURE_HANDLE : # TEMPERATURE_UUID :
char_data = await client.read_gatt_char(char.uuid)
print("temperature raw:", char_data, type(char_data), len(char_data))
temp_data = int.from_bytes(char_data, byteorder='little') # which bytes contain the temperature value?
calculate_temperature(temp_data)
asyncio.run(main(BLE_DEVICE_MAC_ADDRESS))
But I am stuck with the line extracting temp_data, because it is not clear to me, what part of the 4 byte array returning as char_data does really contain the temperature information which could be then converted as described in the documentation to deg. celsius (with the above formula). Could you please help ? Thanks a lot in advance.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
Thanks a lot, @switchdoclabs , for the ultrafast reply :) The code, that you were pointing at (switchdoclabs/SDL_Pi_SHT30) is using the I2C interface, unfortunately not bluetooth. There are indeed some similarities (also the endianess conversion), but I2C seems to send Temperature and Humidity information as one single 4 byte bytestream for all (2 first bytes temperature, 2 next bytes humidity) , whereas bluetooth seems to send information separately, but strangely 4 bytes per temperature and 4 per humidity. The question is, what part of the 4 bytes is the information ? I tried the first and the second 2 bytes, but none give the right values.
btw. the outdated SHT31 beacon scanner file, I was referring to is :
https://github.com/switchdoclabs/iBeacon-Scanner-/blob/master/blescan.py
All the info is in here that you needDatasheet_SHT3x_DISPDF Document · 810 KBOn May 26, 2024, at 11:00, mark doerr @.***> wrote: btw. the outdated SHT31 beacon scanner file, I was referring to is : https://github.com/switchdoclabs/iBeacon-Scanner-/blob/master/blescan.py
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>
Hallo iBeacon BLE reader developers,
for a student demonstration project, I tried to write an updated version of the Bluetooth readout of Sensirion SHT31 beacon (blescan.py) with the modern python bleak package, since the original bluetooth python package is outdated:
But I am stuck with the line extracting temp_data, because it is not clear to me, what part of the 4 byte array returning as char_data does really contain the temperature information which could be then converted as described in the documentation to deg. celsius (with the above formula). Could you please help ? Thanks a lot in advance.