HM10 Bluetooth Module data decoding with Python and bleak

Customer:

I’m working on a measurement device that sends data via Bluetooth to a laptop. The laptop runs a Python script that creates a UI and processes the data by plotting collected measurements. Data is collected using a load-cell sensor and transmitted via Bluetooth to the laptop. Everything works correctly when I connect to the HM10 module using an iOS phone with the BLExAR application - I can send a command to start data transmission and display it properly on a graph.

I’ve had major difficulties connecting the HM10 module to the laptop, especially with Python, because it’s a BLE device and doesn’t support Bluetooth over serial port connection. Using the bleak Python module I’ve successfully made a connection to the HM10 module, but I can’t properly decode the data. When I print the data without decoding, it’s in the form bytearray(b’\x005\xff\x13\xecv’). I’ve tried decoding it using utf-8 and ascii, then converting to float values, but nothing worked.

I also acquired an ESP32 device and successfully connected it via COM port over Bluetooth and transmitted data successfully. But when I connected an HX711 amplifier and load cell sensor to it, everything broke again.

I want to send a command from the Python UI start button to the Arduino to begin data transmission, then receive and process the data in Python on the laptop. I should mention that when sending data to the phone everything works perfectly, and when sending data to the laptop via USB cable connected to the Arduino everything also works perfectly.

Original message (Croatian)

Naime, pokušavam napraviti mjerni uređaj koji će pomoću Bluetootha slati podatke na laptop. Laptop će vrtiti Python skriptu koja služi za stvaranje upravljačkog UI sučelja te za obradu podataka tj pravljenje grafa od prikupljenih podataka. Podaci se prikupljaju load-cell senzorom te bluetoothom šalju na laptop. Valja napomenuti da sve ispravno funkcionira kada se na HM10 modul povežem pomoću iOS telefona koristeći BLExAR aplikaciju. Tada mogu poslati komandu za početak slanja podataka te ih pravilno pokazati na grafu.

Imao sam velikih problema kako spojiti HM10 modul sa laptopom te pogotov sa pythonom pošto je on BLE uređaj te nema mogućnost spajanja preko Bluetooth over serial port connection. Pomoću bleak python modula sam uspješno napravio konekciju između HM10 modula no nikako ne uspijevam pravilno dekodirati podatke. Kada printam podatke bez da ih pokušavam dekodirati oni su oblika bytearray(b’\x005\xff\x13\xecv’). Pokušavao sam ih dekodirati i pomoću utf-8, ascii, te ih onda pretvoriti u float vrijednost no ništa nije bilo uspješno.
Također sam nabavio i ESP32 uređaj te ga uspješno povezao Bluetoothom preko COM porta i uspješno slao podatke no kada sam na njega priključio HX711 pojačalo i load cell senzor sve je ponovno otišlo kvragu.
Dakle, želim pritiskom na gumb start koji je na python UI-u poslati komandu arduino za početak slanja podataka te podatke primati i obrađivati pomoću pythona na laptopu. Još jedno ću naglasiti da prilikom slanja podataka na telefon sve funkcionira odlično te da pri slanju podataka na laptop pomoću usb kabla povezanog sa Arduinom također sve odlično funkcionira.

Originally submitted via email support on 23 April 2024. Migrated to the forum for community visibility.

Soldered Support:

When decoding, try using unpack with ‘<f’ for little-endian float. Investigate that - it might be the correct way to decode. That could be it. Have you properly set the UUID of the module in your Python code?

Also, it’s odd that ESP32 Bluetooth stopped working after you connected the HX711. What exactly is the error? Does it stop working? Does the ESP reset? Check the Arduino Serial port.

Original message (Croatian)

evo nekih stvari koje možeš probati
Pri dekodiranju, probaj koristiti unpack:

ili ‘<f’ za little-endian float. Istraži to, možda je to točan način za dekodiranje. To bi moglo biti to. Jesi li pravilno postavio UUID modula u python kodu?

Takođe, čudno je što je esp32 bluetooth prestao raditi nakon što si spojio hx711. Koja točno greška se dogodi? Prestane raditi? ESP se resetira? Provjeri Arduino Serial port.