cyberjunky / RTL-SDR-P2000Receiver-HA

Receive P2000 messages using RTL-SDR stick and post them to Home Assistant
MIT License
23 stars 11 forks source link

No messages to MQTT #34

Open danesolutions opened 2 years ago

danesolutions commented 2 years ago

Hi,

First of all, great software just what I was looking for! I only have an issue with registering to my MQTT (Mosquitto) I don't have credentials set on Mosquitto. I can't get it to work that the topic "p2000" is getting published and filled with P2000 messages. Attached is my config.ini file. I tried to leave the fields username/password empty or just filled in random text but I can't see the p2000 topic published.

Hope you can help me. Kind regards image

cris1 commented 2 years ago

I have the same issue, also with mosquitto. I do use a username and password but p2000 messages are not published although the debug log says it did -->

python3[15860]: 2022-06-07 22:33:00 - (PostThread) - p2000.py - DEBUG - MQTT status: Posting to 192.168.100.188:1883 topic:huis/p2000
Dinges28 commented 2 years ago

Try to outcomment (#) line 720 [https://github.com/cyberjunky/RTL-SDR-P2000Receiver-HA/blob/94e251ee60ca4f97d4a470e85af88201b7aabd8b/p2000.py#L720]

It might solve your login credentials issue (not using mqtt myself)

cyberjunky commented 2 years ago

If this works i will do check for password/username to see if we need to call the set_pw

cris1 commented 2 years ago

For me that did not solve the issues. My MQTT requires authentication btw.

Dinges28 commented 2 years ago

Fill in a dummy user and password, and add and change line 717 and 722 with the data from my pull request.

37

cyberjunky commented 2 years ago

@cris1 did the fix from @Dinges28 fixed your MQTT issue? (code is now updated)

cyberjunky commented 2 years ago

@cris1 can you try the latest code and let us know? There was a bug which is fixed now.

dfsx1 commented 2 years ago

@cyberjunky @chris1

I think this is the problem. Debug says it posts to mqtt_topic https://github.com/cyberjunky/RTL-SDR-P2000Receiver-HA/blob/cff3779b1f783e08031375f2c8ad1d2fda958a98/p2000.py#L749

But this is wrong because it actually posts to mqtt_topic_sensor

https://github.com/cyberjunky/RTL-SDR-P2000Receiver-HA/blob/cff3779b1f783e08031375f2c8ad1d2fda958a98/p2000.py#L745

self.mqtt_topic_sensor = (
  self.mqtt_topic + "/sensor/" + self.sensorname
)

I still have a manual MQTT sensor configured in HA that expects state_topic: "p2000" So for now I just modify the code to post to mqtt_topic again.

client.publish(self.mqtt_topic_sensor, data) client.publish(self.mqtt_topic, data)

Maybe later it would be nice to change the format to HA MQTT Discovery... https://www.home-assistant.io/docs/mqtt/discovery/#discovery-messages

Dinges28 commented 2 years ago

This is done because the current script allows multiple sensors. therefore the topic_sensor is made. But if you don't use that, be free to change it what you want it to be, no harm done... ;-)

Doing the discovery.. I tried, but no succes for me.. but if somebody else wants to try?

cris1 commented 2 years ago

@cris1 can you try the latest code and let us know? There was a bug which is fixed now.

Hi, sorry for the delay, took me a bit to find time to test the update. I can tell you it works for me!!

I have Mosquitto MQTT running on port 1883 and use authentication.

image

The mistake I made was how I subscribed to the topic. The trailing slash did the trick for me and now I see the P2000 messages in MQTT. I am not sure if this always was the issue or not..but I am glad it works.

Sep 10 22:56:57 /huis/p2000/sensor/p2000_catchall {"state": "P 2 BDH-02 BR gerucht Bazuinlaan Rijswijk ZH 155630", "attributes": {"time received": "Sat Sep 10 22:56:55 2022", "group id": "14.039", "receivers": "001500161", "capcodes": ["002029568", "001503902", "001500196", "001500161"], "priority": 2, "disciplines": "", "raw message": "FLEX|2022-09-10 20:56:55|1600/2/K/A|14.039|002029568 001503902 001500196 001500161|ALN|P 2 BDH-02 BR gerucht Bazuinlaan Rijswijk ZH 155630", "region": "", "location": "", "postal code": "", "city": "Rijswijk ZH", "address": "Bazuinlaan Rijswijk ZH", "street": "", "remarks": "", "longitude": "4.3216871", "latitude": "52.0316638", "opencage": "enabled: True ratelimit: False gps-checked: False", "mapurl": "https://www.openstreetmap.org/?mlat=52.03166&mlon=4.32169#map=17/52.03166/4.32169", "distance": 38.39, "friendly_name": "P2000 Catchall"}}

Good job!

spiralshapeturtle commented 2 years ago

Thanks, this thread helps me to solve my MQTT problems.