I tried to send the json message but failed
client.publish( "lights/hue/device123/set/led", {'a':5}, { retain: true },function(err){
if(err){
console.log('publishing message',failed);
}
});
I know it does't support json, but would be a better way to do it
client.publish('lights/hue/device123/set/led', JSON.stringify({ a: 5 }))
Got it, thanks @ralphtheninja
You need to do the opposite in .on('message', fn), e.g.
client.on('message', function (topic, payload) {
const obj = JSON.parse(payload.toString()) // payload is a buffer
})
Most helpful comment