Battery level report in MQTT?



  • Hi

    I have added battery level reporting for a temperature sensor. It sends that to a MQTT gateway connected to Openhab. I see the battery level report go from the sensor, to the gateway but then it looks sort of funny when I look at the MQTT message.
    I want to pick the message up in Openhab to get a status of the battery level there but I don't get Openhab to receive it.

    In the Serial monitor for the gateway it look like this:

    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=0,pt=1,l=1,sg=0:95
    MyMQTT/20/255/V_

    I tried to read that value in Openhab, without success (It looks weird so I guess it's wrong) , with this item:

    Number Batteri_Kvar_Inne "Batteri kvar [%.1f %]" <battery> {mqtt="<[nuc:MyMQTT/20/255/V_:state:default]"}

    Anyone have experience from visualising the battery level on Openhab with MQTT and have any idea what's going on and how to pick it up in Openhab?

    /Johan



  • Update...

    I have figured out why the MQTT message looks strange. In the MyMQTT.h file there are an array that translates the variable type to the string that should be sent in the MQTT message. The value for the battery level I get from my sensor is 50 and that translation translates to "", and thus the message obviously becomes just V_.
    It is an easy fix to fix my message but maybe the whole translation table should be updated by someone who know more about all the various other variable types. As I am sort of new to MySensors, what is the proper way to get this fixed? Create an issue in Git?

    /Johan



  • Another update...

    Yesterday I switched to using the MQTTClientGateway from tomkxy's branch. It is acting as a MQTT client instead of as a broker, as I think it should. I mean, if you have installed Openhab and thinking of using MQTT instead of serial as communication I think installing a Mosquitto broker (for example) probably is not a big deal. :)
    There are obvious benefits to using a "real" broker in that you can have several clients subscribing to the messages at once. This also lets you monitor the messages sent through the broker.

    It works great and I now get all the values to Openhab without problems. It even runs on my UNO with the Ethernet shield, even though several persons have said the memory would not be sufficient. Thanks tomkxy!

    /Johan



  • Hi Johan, I have been trying to get the MQTTClient gateway running a few months back but gave up..... Can you share the final sketch you used?


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.