Bluetooth controller keeps going down. Reboot fixes?

Hi
I am using 5x bluetooth (BT) temp sensor hardware LYWSD03MMC devices .

It is working with latest HA core (as of 31.01.2021) with Pi3+ and correctly communicates with all BT sensors.

However, what I am experiencing is that after around two days I find that the controller goes down and HA reports an unexpected end of the bluetooth loop, and hciconfig -a reports the local controller to be DOWN and often timeouts communicating with the onboard controller, when issuing hciconfig commands. I then need to do the following

sudo systemctl restart hciuart, bluetooth
hciconfig hci0 reset

Eventually (sometimes I need to do this several times) the hci0 interface is back up and doing its PSCAN stuff, and the related sensors entities are again updated Sometimes even that doesn’t work so then a reboot of the Pi always resolves the issue but this is an overkill every two days!

I have scoured various forums with suggestions such as downgrading bluez and upgrading the EEPROM firmware, but this issue continues to persist. I am posting here because I only use the controller with HA and with these sensors - no other BT devices used in my network no other apps using BT. Thus wondering if HA users have managed to do something to get the Pi3+ BT controller working under HA.

I have also run raspi-update that still doesn’t fix this after a reboot.

Actually I have no idea what is going on with the Pi in terms of BT. There seems to be several BT packages installed which are not potentially needed and/or conflict with one another:

  • bluez-firmware
  • pi-bluetooth
  • bluez
  • hcitools
  • and various firmware “dist” files that can be downloaded and manually installed as a .deb

I also tried to downgrade bluez from 5**.5.0-1.2~deb10u1+rpt2** to 5.5.0-1.2~deb10u1 as per recommended on the RaspberryPI UK forum - but on reboot nothing could find the controller and all attempts to create/use/update the device from user-space failed with “No controller” or similar issues.

Has anyone had similar timeout issues with the BT controller going down with timeouts, and if you have, how specifically did you fix it please either in the OS or in HA. I do have access to “root” outside of HA if that helps?

sudo /opt/vc/bin/vcgencmd version

reports

updated Jan 21 2021 (clean) (release) (start)

I am using kernel 5.10.9-v7+

EDIT:
I found this repo of non-free fw files , has anyone used one of these and fixed BT issues?

1 Like

I struggled a long time trying to get various python to bluetooth LE solutions work on raspberry pi and intel based Ubuntu versions, with poor success. Even the newer paths via d-bus stuff. I think there are race conditions somewhere, perhaps in bluetooth systems, that cause these ‘outages’. When you ‘connect’ to a bluetooth device, things seem far more stable. But what I am doing, and perhaps you are as well, is just scanning for the bluetooth advertising packets, this is when the race conditions can occur and you end up have to restart the bluetooth stack or the whole machine.

I have tried both the internal BLE devices and external USB BLE devices, no difference. There are firmware upgrades for some USB BLE devices, I have applied those and they made no difference.

It seems to me, that if two processes try to access a single bluetooth device at same time while this advertising search is going on, troubles can occur.

I have a simple c program now doing this advertising scanning on raspberry pi and it runs solid. I have it processing the BLE advertising data for over 20 BLE temperature sensors. It sends about 10,000 readings per hour to MQTT. It’s uptime is now measured in months. It has been very stable. I’m not much of a c coder, so the code is very basic and rough, but perhaps it will give you some ideas.

You can still cause my program to crash, if while it is running you start to try to access the same bluetooth adapter, to say query it’s abilities or start another advertising scan request on same adapter. But, after quite a bit of head scratching, my code is pretty stable. You can even run multiple instances against different bluetooth adapters.

Good hunting.

YES that is the mode of operation, a scan for advertising packets.

Ditto.

I have been using HA community custom_component

But noticed this which I have not tried yet

If I cannot get that working I will try your C code - THANK YOU.

BTW, I run HA in a container , how would I setup+run your executable in such an environment?

Will come back …

EDIT1: The 2nd link (ble_monitor) is I think the same as the 1st (mitemp_bt) - it’s one and the same.
RRR

EDIT2:
Apologies - I just noticed your HowTo for the RPi in your github article.
I will wait for a bit because I have just changed my /etc/Bluetooth/main.conf file and set Mode from dual to ble and restarted bluetooth service … so good so far.

For $5 you can use an ESP32 running ESPHome as a stable Bluetooth gateway.

Or just buy a BT USB stick?

You’d still be using the pi’s (buggy by the sounds of it) Bluetooth stack.

Ah - I see. So it is not necessarily the BT (onboard) device, but moreover the entire driver and kernel stack - that would still be used to some degree if a BT dongle were inserted?

Not really sure.

Sounds logical. Think I need to investigate further. Can’t believe the Pi3+ - been around a few years now - doesn’t have a workable BT stack. Quite old and plenty of chance to resolve it all - ah well , I’ll keep searching.

Any ideas what all this SAP errors are about in my /var/log/syslog ?

daz@Pi:~/HASS/CONFIG $ sudo grep bluetooth /var/log/syslog
Feb  1 08:02:43 Pi bluetoothd[577]: Sap driver initialization failed.
Feb  1 08:02:43 Pi bluetoothd[577]: sap-server: Operation not permitted (1)
Feb  1 08:02:43 Pi systemd[1]: Started Raspberry Pi bluetooth helper.
Feb  1 08:03:02 Pi bluetoothd[577]: Terminating
Feb  1 08:03:02 Pi bluetoothd[577]: Stopping SDP server
Feb  1 08:03:02 Pi bluetoothd[577]: Exit
Feb  1 08:03:02 Pi systemd[1]: bluetooth.service: Succeeded.
Feb  1 08:03:02 Pi bluetoothd[18639]: Bluetooth daemon 5.50
Feb  1 08:03:02 Pi bluetoothd[18639]: Starting SDP server
Feb  1 08:03:02 Pi dbus-daemon[415]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.176' (uid=0 pid=18639 comm="/usr/lib/bluetooth/bluetoothd ")
Feb  1 08:03:02 Pi bluetoothd[18639]: Bluetooth management interface 1.18 initialized
Feb  1 08:03:02 Pi bluetoothd[18639]: Sap driver initialization failed.
Feb  1 08:03:02 Pi bluetoothd[18639]: sap-server: Operation not permitted (1)
Feb  1 08:19:18 Pi bluetoothd[18639]: Terminating
Feb  1 08:19:18 Pi bluetoothd[18639]: Stopping SDP server
Feb  1 08:19:18 Pi bluetoothd[18639]: Exit
Feb  1 08:19:18 Pi systemd[1]: bluetooth.service: Succeeded.
Feb  1 08:24:01 Pi bluetoothd[18987]: Bluetooth daemon 5.50
Feb  1 08:24:01 Pi bluetoothd[18987]: Unknown controller mode "le   "
Feb  1 08:24:01 Pi bluetoothd[18987]: Starting SDP server
Feb  1 08:24:01 Pi dbus-daemon[415]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.178' (uid=0 pid=18987 comm="/usr/lib/bluetooth/bluetoothd ")
Feb  1 08:24:01 Pi bluetoothd[18987]: Bluetooth management interface 1.18 initialized
Feb  1 08:24:01 Pi bluetoothd[18987]: Sap driver initialization failed.
Feb  1 08:24:01 Pi bluetoothd[18987]: sap-server: Operation not permitted (1)
Feb  1 09:03:49 Pi bluetoothd[18987]: Sap driver initialization failed.
Feb  1 09:03:49 Pi bluetoothd[18987]: sap-server: Operation not permitted (1)
Feb  1 09:03:49 Pi systemd[1]: Started Raspberry Pi bluetooth helper.

and what is this BCM43430A1.hcd ?

daz@Pi:~/HASS/CONFIG $ sudo grep brcm /var/log/syslog
Feb  1 08:02:43 Pi btuart[18593]: Flash firmware /lib/firmware/brcm/BCM43430A1.hcd
Feb  1 09:03:49 Pi btuart[19762]: Flash firmware /lib/firmware/brcm/BCM43430A1.hcd

EDIT
I have added “–noplugin=sap” to the bluetooth service file
and
I now get some more positive results from hciconfig

daz@Pi:~/HASS/CONFIG $ sudo hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: XX:XX:XX:XX:XX:XX  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN
        RX bytes:14408 acl:0 sco:0 events:420 errors:0
        TX bytes:3064 acl:0 sco:0 commands:97 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'Pi'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 4.1 (0x7)  Revision: 0x1fc
        LMP Version: 4.1 (0x7)  Subversion: 0x2209
        Manufacturer: Broadcom Corporation (15)

Much of the latter lines were “unknown” , before disabling sap plugin. I believe sap=SIM Access Plugin , which I don’t use anyway but seems to be improving my BT - for now?

The bluetooth firmware messages in syslog refer to available but not found on your machine firmware patches for the bluetooth adapters. I went down this rabbit hole and it made no difference for the BLE advertising problem. It’s a good lesson in how to add firmware patch files on linux, but that was all I gained. Note, that the names of the firmware files have to be jiggled depending on linux versions, for example same BLE adapter firmware file had to be named slightly differently on Ubuntu than on RaspberryOS. See link below for more info.

I run my c bluetooth collector program under tmux on rasberry pi, any method you want to run a disconnected process under linux works. I would not recommend running my program within a docker container, I never tried that, you have a whole second level of abstraction then. This one reason I think a number of folks have problems with the python based HA bluetooth scanner routines. Again one of the reasons I moved my solution to run on raw linux. I also like using MQTT as my data pipe for a many sensors as possible. Allows more fexability and robustness I believe. For example I feed my temperature sensor via MQTT into both HA and HomeKit (via Homebridge).

https://kb.plugable.com/bluetooth/outdated-solving-hfp-hsp-and-a2dp-profile-issues-on-linux
https://linuxize.com/post/getting-started-with-tmux/
1 Like

Thankyou @dproffer
Most insightful.
May I ask… your C code, does it run an mqtt broker or just the client ,i already use mqtt in HA which had its own broker - I believe.

It is just a client, it expects a MQTT servers somewhere on the network. You put it’s address into the config file. Hopefully, you should be able to download the three components on to your raspberry pi, compile as I documented, edit the config with your MQTT server and the MAC address of one of your sensors and test it out in about 10 minutes. You should see temperature and humidity values appearing in your MQTT server. Dont add anything to your HA config at first, just look at what is being published in MQTT with a tool like MQTT Explorer. Then if stays useful you can add MQTT sensors in HA as needed.

http://mqtt-explorer.com/

The LYWSD03MMC temperature and humidity sensors are really nifty devices, I have been very happy with them. As some others have commented, esphome with the esp32 boards work with this device as well. Another option, both mine and the ESP solutions seem much more robust than the ones using python bluetooth on linux.

1 Like

I give up @dproffer because my bluetooth failed again whilst was out and so HA was getting no data/stale data from the sensors so kept the heating on - most of the day - so thanks to crappy buggy python bluetooth on the RPi my house was 25C when I got in. Stifling. Downloading your client and code now.
I currently have these BT services/packages installed - which ones can I remove to use your client?


bluez
bluez-firmware
libbluetooth3:armhf
libluajit-5.1-2:armhf
libluajit-5.1-common
pi-bluetooth

Probably all of them, but to start, just leave them. I had a lot similar cruff on my rpi when I started coding and running my program and I did not have any issues. Later I did to a clean rpi install, as documented on github.

Just make sure you do not have anything running that is trying to access the bluetooth adapter at same time. So any sysctl jobs, or anything HA addin. I would disable those.

Shout if I can help.

Thanks muchly. but …

daz@Pi:~/BLUETOOTH/bluetooth-temperature-sensors $ cd paho.mqtt.c/
daz@Pi:~/BLUETOOTH/bluetooth-temperature-sensors/paho.mqtt.c $ make
mkdir -p build/output/samples
mkdir -p build/output/test
echo OSTYPE is Linux
OSTYPE is Linux
mkdir -p build
sed -e "s/@CLIENT_VERSION@/1.3.8/g" -e "s/@BUILD_TIMESTAMP@/Tue  2 Feb 17:25:36 GMT 2021/g" src/VersionInfo.h.in > build/VersionInfo.h
cc -g -fPIC  -D_GNU_SOURCE -Os -Wall -fvisibility=hidden -Ibuild -DPAHO_MQTT_EXPORTS=1 -o build/output/libpaho-mqtt3c.so.1.3 src/Heap.c src/LinkedList.c src/MQTTProtocolClient.c src/MQTTProtocolOut.c src/MQTTPersistence.c src/MQTTProperties.c src/MQTTPersistenceDefault.c src/Messages.c src/MQTTTime.c src/MQTTPacketOut.c src/Socket.c src/WebSocket.c src/Clients.c src/OsWrapper.c src/Thread.c src/MQTTPacket.c src/Base64.c src/SHA1.c src/MQTTClient.c src/Log.c src/StackTrace.c src/MQTTReasonCodes.c src/utf-8.c src/SocketBuffer.c src/Tree.c  -shared -Wl,-init,MQTTClient_init -Wl,--start-group -lpthread -lanl -Wl,--end-group -Wl,-soname,libpaho-mqtt3c.so.1
ln -s libpaho-mqtt3c.so.1.3  build/output/libpaho-mqtt3c.so.1
ln -s libpaho-mqtt3c.so.1 build/output/libpaho-mqtt3c.so
cc -g -fPIC  -D_GNU_SOURCE -Os -Wall -fvisibility=hidden -Ibuild -DPAHO_MQTT_EXPORTS=1 -o build/output/libpaho-mqtt3cs.so.1.3 src/Heap.c src/LinkedList.c src/SSLSocket.c src/MQTTProtocolClient.c src/MQTTProtocolOut.c src/MQTTPersistence.c src/MQTTProperties.c src/MQTTPersistenceDefault.c src/Messages.c src/MQTTTime.c src/MQTTPacketOut.c src/Socket.c src/WebSocket.c src/Clients.c src/OsWrapper.c src/Thread.c src/MQTTPacket.c src/Base64.c src/SHA1.c src/MQTTClient.c src/Log.c src/StackTrace.c src/MQTTReasonCodes.c src/utf-8.c src/SocketBuffer.c src/Tree.c -DOPENSSL  -shared -Wl,--start-group -lpthread -lanl -ldl -lssl -lcrypto -Wl,--end-group -Wl,-init,MQTTClient_init -Wl,-soname,libpaho-mqtt3cs.so.1 -Wl,-no-whole-archive
In file included from src/SSLSocket.c:31:
src/SocketBuffer.h:28:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/MQTTProtocolClient.h:25,
                 from src/MQTTProtocolClient.c:35:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/MQTTProtocolOut.h:25,
                 from src/MQTTProtocolOut.c:37:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPersistence.h:27,
                 from src/MQTTPersistence.c:29:
src/Clients.h:31:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/MQTTProperties.c:19:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/MQTTPacketOut.h:23,
                 from src/MQTTPacketOut.c:30:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/Socket.c:33:
src/SocketBuffer.h:28:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/WebSocket.h:20,
                 from src/WebSocket.c:30:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/Clients.c:24:
src/Clients.h:31:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/MQTTPacket.c:28:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
src/Base64.c:43:10: fatal error: openssl/bio.h: No such file or directory
 #include <openssl/bio.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/SHA1.c:17:
src/SHA1.h:21:10: fatal error: openssl/sha.h: No such file or directory
 #include <openssl/sha.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPersistence.h:27,
                 from src/MQTTClient.c:58:
src/Clients.h:31:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/Log.c:27:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/StackTrace.c:21:
src/Clients.h:31:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/MQTTPacket.h:26,
                 from src/MQTTReasonCodes.c:19:
src/SSLSocket.h:29:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/SocketBuffer.c:25:
src/SocketBuffer.h:28:10: fatal error: openssl/ssl.h: No such file or directory
 #include <openssl/ssl.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:259: build/output/libpaho-mqtt3cs.so.1.3] Error 1

Need to install openssl dev? and if so which package because lots of packages provide a “ssl.h” file according to apt-file find "ssl.h"

EDIT: Found libssl-dev which fixed the problem. You’re instructions need updating to include sudo apt install libssl-dev ?

Will do, thanks!

You’re welcome.

Also, for the RPi the BT device is not on the usb:

daz@Pi:~/BLUETOOTH/bluetooth-temperature-sensors $ lsusb
Bus 001 Device 006: ID 0658:0200 Sigma Designs, Inc. Aeotec Z-Stick Gen5 (ZW090) - UZB
Bus 001 Device 007: ID 1058:1042 Western Digital Technologies, Inc. Elements SE Portable (WDBPCK)
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

whereas your guide alludes to USB BT device

Bus 001 Device 005: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0

On the RPi 3+ it is a serial UART device:

daz@Pi:~/BLUETOOTH/bluetooth-temperature-sensors $ hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: XX:XX:XX:XX:XX:XX  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN
        RX bytes:64502794 acl:1 sco:2 events:1614765 errors:0
        TX bytes:19867 acl:0 sco:0 commands:2725 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'Pi'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 4.1 (0x7)  Revision: 0x1fc
        LMP Version: 4.1 (0x7)  Subversion: 0x2209
        Manufacturer: Broadcom Corporation (15)

All somewhat incidental and just for your info (updating the guide)

Good news! here is the code running , I just need to tweak configs … will come back… :-

ble_sensor_mqtt_pub v 2.12
1 Bluetooth adapter(s) in system.
Reading configuration file : ble_sensor_mqtt_pub.csv
MQTT server : tcp://172.148.5.11:1883
MQTT topic  : homeassistant/sensor/ble-temp/
Header      |MAC Address      |Type|Location                      |
Unit  :   0 |DD:C1:38:70:0C:24|   1|LYWSD03MMC Living Room        |
Unit  :   1 |DD:C1:38:AC:28:A2|   1|LYWSD03MMC Shared Bathroom    |
Unit  :   2 |DD:C1:38:4B:80:4A|   1|LYWSD03MMC Backyard           |
Unit  :   3 |DD:C1:38:C7:74:F1|   1|LYWSD03MMC Kitchen            |
Unit  :   4 |DD:C1:38:DD:CF:CD|   1|LYWSD03MMC Front Door         |
Unit  :   5 |DD:C1:38:EC:BE:94|   1|LYWSD03MMC Master Bedroom     |
Unit  :   6 |DD:C1:38:E2:32:B3|   1|LYWSD03MMC Medium Bedroom     |
Unit  :   7 |DD:C1:38:54:A4:70|   1|LYWSD03MMC Dining Room        |
Unit  :   8 |DD:C1:38:38:5C:72|   1|LYWSD03MMC Attic              |
Unit  :   9 |DD:44:0D:81:75:08|   2|H5052 Refrigerator            |
Unit  :  10 |DD:44:0D:70:F0:E4|   2|H5052 Backyard                |
Unit  :  11 |DD:44:0D:70:C1:CC|   2|H5052 Freezer                 |
Unit  :  12 |DD:44:0D:70:28:64|   2|H5052 Small Bedroom           |
Unit  :  13 |DD:44:0D:80:D8:25|   2|H5052 Garage                  |
Unit  :  14 |DD:C1:38:DD:4C:B2|   3|H5072 Living Room             |
Unit  :  15 |DD:C1:38:AC:77:44|   3|H5072 Shared Bathroom         |
Unit  :  16 |DD:C1:38:FF:AD:EB|   3|H5072 Kitchen                 |
Unit  :  17 |DD:C1:38:DB:44:04|   4|H5102 test unit               |
Unit  :  18 |DD:C1:38:38:5F:C2|   5|H5075 test unit               |
Unit  :  19 |DD:12:1D:22:80:77|   6|H5074 test unit               |
Total devices in configuration file : 20
MQTT client name : ble_sensor_mqtt_pub-XX:XX:XX:XX:XX:XX

May I ask what tcp://172.148.5.11:1883 is going? it’s not on my LAN?

EDIT: Never mind. My bad not reading properly. Its the host IP and port for the broker. Sorry!

EDIT: Nope, what is the MQTT server IP ? localhost:1883 doesn’t work?

I will test

tcp://localhost:1883

the c program and my mqtt server are on different physical machines, can you code the ip address of the MQTT server into the config file?

Hang on. My bad - again. I stopped all services so the UART interface was not up.

hciuart.service must be running. All other BT services can be stopped including the buggy pi-bluetooth thank god.

So…

daz@Pi:~/BLUETOOTH/bluetooth-temperature-sensors $ sudo ./ble_sensor_mqtt_pub 0 0 100 1000

yields (note the 0 for passive listening)

ble_sensor_mqtt_pub v 2.12
1 Bluetooth adapter(s) in system.
Reading configuration file : ble_sensor_mqtt_pub.csv
MQTT server : tcp://localhost:1883
MQTT topic  : homeassistant/sensor/ble-temp/
Header      |MAC Address      |Type|Location                      |
Unit  :   0 |XX:XX:XX:XX:XX:XX|   1|LYWSD03MMC Living Room        |
Total devices in configuration file : 1
MQTT client name : ble_sensor_mqtt_pub-XX:XX:XX:XX:XX:XX
Bluetooth Adapter : 0 has MAC address : XX:XX:XX:XX:XX:XX
Advertising scan type (0=passive, 1=active): 0
Advertising scan window   :  100, 62.5 ms
Advertising scan interval : 1000, 625.0 ms
Scanning....
current hour (GMT) = 18
last    hour (GMT) = 17

and a quick test in the MQTT HA integration listening for the topic:

Message 1 received on homeassistant/sensor/ble-temp/XX:XX:XX:XX:XX:XX at 18:01:
{
    "timestamp": "20210202180122",
    "mac-address": "XX:XX:XX:XX:XX:XX",
    "rssi": -61,
    "temperature": 68.7,
    "units": "F",
    "temperature-celsius": 20.4,
    "humidity": 41,
    "battery-pct": 87,
    "battery-mv": 2987,
    "frame": 1,
    "sensor-name": "",
    "location": "LYWSD03MMC Living Room",
    "sensor-type": "1"
}

WHAT A STAR YOU ARE.

PM me with paypal addy and I’ll send you a coffee !! UptoU

Consider updating your guide based on the above , as in

  • openssl-dev
  • the localhost:1883 (or whatever)
  • the 0 for passive listening
  • service hciuart must be installed and running
  • UART not USB controller
  • possibly bluez and bluez-firmware can be removed? don’t know but I will test and report back.

Tested on

  • RPi 3+
  • Integrated BT controller SoC UART device @7e201000
  • HCI Version: 4.1 (0x7) Revision: 0x1fc
  • LMP Version: 4.1 (0x7) Subversion: 0x2209
  • Raspbian Buster
  • Kernel Linux Pi 5.10.9-v7+ #1396 SMP
  • Thu Jan 21 15:54:00 GMT 2021 armv7l GNU/Linux

:ok_hand:

(or should I wait for it to prove its resilience :rofl:)