mqtt javascript examples

1,447 views
Skip to first unread message

zatalian

unread,
Dec 9, 2017, 3:53:56 AM12/9/17
to Routix
Hi,

I'm trying to use MQTT-Dash in combination with the esp8266_milight_hub project from sidoh and a mosquitto server running on my pc.

I'm simply trying to turn on/off a lamp and get the status of the lamp from the mosquitto server.

to get the status, i subscribe to "milight/states/" and get the following json as result:

{"state":"OFF","brightness":255,"mode":2,"bulb_mode":"scene","color":{"r":255,"g":255,"b":255}}

to turn the lamp on or off, i publish to "milight" the following json:

{"state":"OFF"}


As I understand, those json messages must be the same to get the MQTT-Dash button to work correctly? I can use $.state the get the value "ON", or "OFF" from the state, but then only that is send when i try to publish a new state.
Is there a way (with javascript?) to either filter the response from the subscription or to format the payload i want to publish, so that they are the same?

Do you have some javascript examples that modify the payload in any way?

Thanks!

zatalian

unread,
Dec 10, 2017, 2:30:15 PM12/10/17
to Routix
Solved the problem with the following code in OnMessage:

var i = event.payload.indexOf(",");
var result = event.payload.substring(0, i) + "}";
event.payload = result;


Where can i find some more information about this event object? What other properties does it have? Can i for example access the result of the jsonpath filter?

Vadim Mostovoy

unread,
Dec 10, 2017, 2:32:56 PM12/10/17
to zata...@gmail.com, Routix
Hi, there is Help button in the script editor. Depending on metric/event type it displays relevant help page.


--
Thanks,
Vadim Mostovoy

--
You received this message because you are subscribed to the Google Groups "Routix" group.
To unsubscribe from this group and stop receiving emails from it, send an email to routix+unsubscribe@googlegroups.com.
To post to this group, send email to rou...@googlegroups.com.
Visit this group at https://groups.google.com/group/routix.
For more options, visit https://groups.google.com/d/optout.

Matt Elias

unread,
Dec 31, 2017, 2:48:27 AM12/31/17
to Routix
Is there more detailed help somewhere? Or more examples?

Vadim Mostovoy

unread,
Dec 31, 2017, 3:18:27 AM12/31/17
to elias...@gmail.com, Routix
Hi,
​All available JS API explained in​ integrated help (help button in script editor - fjr each metric type and handler type there is separate help page opened).
Also all standard JS functions available.


--
Thanks,
Vadim Mostovoy

On Sun, Dec 31, 2017 at 2:03 AM, Matt Elias <elias...@gmail.com> wrote:
Is there more detailed help somewhere? Or more examples?
Reply all
Reply to author
Forward
0 new messages