Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed json sent to the mqtt broker ? #30

Closed
yvesle opened this issue Dec 24, 2019 · 2 comments
Closed

Malformed json sent to the mqtt broker ? #30

yvesle opened this issue Dec 24, 2019 · 2 comments

Comments

@yvesle
Copy link

yvesle commented Dec 24, 2019

Hi and thank you for the great work !

Using hass.io 0.103.3 installed on Beaglebone black
I installed your add-on and used the official mosquitto broket add-on v5.1

When I run the add-on, nothing special shows in the log but the broker received one set of data only, no updates. The broker gives a message about "socket error on client xxxx disconnecting" and nothing else.

I am using a current cost transmitter and when using rtl_433 alone and the json format looks like this :
{"time" : "2019-12-24 10:46:53", "model" : "CurrentCost-TX", "id" : 2972, "power0" : 0, "power1" : 0, "power2" : 0}
However when I increased the log level in your script I got this ouput :
echo '{"time"' : '"2019-12-24' '11:27:49",' '"model"' : '"CurrentCost-TX",' '"id"' : 2972, '"power0"' : 0, '"power1"' : 0, '"power2"' : '0}'
Notice there are single quotes missing around double quotes at the beginning and the end. I guess this messed up with the broker.
I used the workaround mentionned in another issue and it works now althought I lost the autodiscovery part.

Hope that helps !

@yvesle
Copy link
Author

yvesle commented Dec 27, 2019

I continued to dig and I think I found a good solution.
It turns out the rtl_433 program can now have its output sent directly to a MQTT broker.
So from line 183 down of the rtl2mqtt.sh script here is my replacement solution :

/usr/local/bin/rtl_433 -M newmodel -R $PROTOCOL -f $FREQUENCY -g $GAIN -p $OFFSET -F "mqtt://$MQTT_HOST:1883,user=$MQTT_USER,pass=$MQTT_PASS,retain=0,events=rtl_433[/model][/id]"

and....that's it ! :)

The topic for my current cost meter becomes "rtl_433/CurrentCost-TX/2972" and is available in hass.io. No stalls yet and works like a charm.
I used "-M newmodel" because the models names are more consistent and make use of dashes "-" instead of space in their name.

I did not try to make autodiscovery work as it seemed too complicated to setup for my need. My only last "hack" was that I wanted to monitor two protocols and I had to hardcode the second one (add -R XX as needed).

Hope that helps others !

@james-fry
Copy link
Owner

Thanks for the inputs @yvesle
It would be nice if I had time to maintain this properly! Great that you got it working, and I think that using rtl433 built in mqtt client is the right approach. If you are able to submit a pr I’d be happy to merge it.
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants