deepcoder / bluetooth-temperature-sensors

Read Bluetooth Advertising Packets from BLE temperature sensors and publish data to MQTT
GNU General Public License v3.0
61 stars 11 forks source link

Connects to MQTT But Does Not Publish Topics #4

Open Hassiopeia opened 3 years ago

Hassiopeia commented 3 years ago

I have this installed on a Pi Zero W and connecting to a H5074 sensor. The software is getting the 04 type advertisement packets, but not sending topics via MQTT. I can see on my MQTT broker that a connection is established, yet noting is being send from the pi to my MQTT broker. I have no idea what I missed, so this may be an issue with newer versions of paho-mqtt perhaps?

deepcoder commented 3 years ago

when the app starts up, it should print a startup set of messages similar to what is shown below, pretty sure it will bomb if it fails to connect to the MQTT server correctly. Check the mqtt topic in the config file. As I said in docs, I am a pretty poor C coder so if the MQTT path in the config file is something oddly specified then the topic in MQTT maybe way off somewhere you are not thinking. Also try a program like MQTT Explorer, it should nicely display all the MQTT topics visible on the MQTT server.

Any warnings during the complie?

Try and see if you see a MQTT topic appear, try a really simple one if nothing else, just to see if that works. MQTT accepts some pretty wild strings for topics.

Let me know if you are still having issues and I will try to recomplie with latest paho-mqtt git.

pi@pi-ble-01:/ $ sudo /home/pi/ble-sensors/hack_ble.sh
Running ble_sensor_mqtt_pub
20210302121018
Press [CTRL+C] to stop..
ble_sensor_mqtt_pub v 2.12
1 Bluetooth adapter(s) in system.
Reading configuration file : ble_sensor_mqtt_pub.csv
MQTT server : tcp://192.168.2.242:1883
MQTT topic  : homeassistant/sensor/ble-temp/
Hassiopeia commented 3 years ago

No warnings during compile. Also tried a fresh setup on another Pi with the same results.

I have been using MQTT Explorer connected to the broker and see that no topics are arriving for this. I can see topics for RoomAssistant on another Pi I have running. I can see in Home Assistant Supervisor MQTT that the ble sensor is connected 1614781262: New client connected from 192.168.200.21 as ble_sensor_mqtt_pub-56:C8:5D:EB:27:B8 (p2, c1, k20). but no topics arrive.

I think I may be onto the issue though. I believe its permissions with the MQTT Broker in HA. I have a user account set as well as Anonymous. My RoomAssistant instance is connecting with the user account and has no issues. I could not find a way to specify a user account with this ble sensor. Reading more of the HA MQTT addon documentation I see that if a user account is specified then Anonymous is Read Only. I suspect that is the issue I'm seeing. I attempted to remove the user account from the MQTT Broker and only use Anonymous but since the HA addon uses HA users by default, Anonymous was still Read Only. Is there a way to include an MQTT user account and password with the ble sensor setup?

EDIT: I figured out how to make the MQTT Addon for Home Assistant be truly "Anonymous" for read/write. It took a few hoops to jump through with ACLs, but I have it working anonymously. The BLE sensor is now publishing topics to the MQTT broker!!!

It still wouldn't be a bad idea to implement user accounts tough.