Page 2 of 2

Re: MQTT discussion topic

Posted: Mon Apr 28, 2014 10:33 am
by dad
Digit wrote:I also create a separate topic for every device value, for example an Oregon Scientific sensor can have 4 of them: */temp, */hum, */batt and */comfort. Cause if you want all the info of that sensor, you simply do a */#.
Using an object notation for the payload does keep it more flexible, e.g. adding a timestamp later on, so you know when that value in the payload was 'sensed'.

So that you can store information like when the AV receiver was powered on (*/powerstate = {value:on, changed: "13:44:00"}), but also when the last time was that the volume level has changed (*/volume = {value:35, changed: "14:00:23"}) In a way, you keep all options open for the future, without having to change a single line of code other than for adding that new 'feature'. I don't use JSON in the payload.
@Digit: I am new to MQTT - at the moment I just have the raw value as the payload, but if you do a wild card you just get a series of numbers. Am I correct that you send the following as payload:

value:35, changed: "14:00:23"

BTW: where do you inject the time value?

Thanks

Dad

Re: MQTT discussion topic

Posted: Mon Apr 28, 2014 11:59 pm
by Bwired
you need to add that yourself

example:

Code: Select all

var s = (new Date()).toMyString() + ' '+ value;
MqttClient.publish(MQTT_LOGGING_ROOT+global.systemId, s.toString(), false);