6 posts / 0 new
Last post
Script to send a specific MQTT message


Just getting started with OVMS - very impressed. I'm wondering whether it's possible to set up a script (which would be triggered by certain events) to send an MQTT message to an MQTT broker? I get that I could play around with the v3 server to get MQTT functionality "out of the box", but I'm thinking about something much simpler: an event happens and I send a relevant message over MQTT at the time of the event. But I can't find anything in the docs about how I could write a script that could send an MQTT message.

Can anyone help me with that?



markwj's picture
I don't see anything in the

I don't see anything in the current firmware that would allow that at the moment. I think you would need an extension to the server v3 component to allow it to send arbitrary mqtt data.

You could use the notification system to send notifications, and those are forwarded out through MQTT - but those are on specific MQTT topics.


OK - thanks Mark. I'll have a play around with the notification system. It looks like there might be enough flexibility to pack commands into an existing notification message, which I can unpack at the other end in my home automation system by subscribing to the appropriate MQTT topic. I'll see what I can do.

dexter's picture


not sure if that's documented: if you need to transport arbitrary strings, you may need to use the "data" type. "info" & "alert" payloads are (historically) encoded in a non-reversible way:

 *  - replace '\r\n' by '\r'
 *  - replace '\n' by '\r'
 *  - replace ',' by ';'

@Mark: we currently do so, but I'm not sure if we need to do that for MQTT as well.


markwj's picture
I don't think it is required

I don't think it is required for MQTT as the payload is an arbitrary string and not newline terminated like protocol v2.

Arbitrary strings

Thanks for the feedback Dexter. The part of the docs that triggered this idea was this example:

OVMS# notify raise text info usr.anton.welcome "Hello, wonderful person!"

I haven't had a chance to try anything, but given the example included an arbitrary text string, I thought maybe I could use that to formulate some kind of simple messaging structure towards my MQTT broker. I get that I should stop being lazy and just start trying stuff... ;-)


Log in or register to post comments