gorootde / nodered-openhab

Node-Red Nodes for OpenHab2 connectivity
GNU General Public License v3.0
1 stars 1 forks source link

payload format #1

Closed jtmoderate876 closed 7 years ago

jtmoderate876 commented 7 years ago

Michael,

Why does the payload format have odd (escape?) characters and how do I handle those in Node-RED? For example: { "topic": "smarthome/items/OutHoliday322AOF/state", "payload": "{\"type\":\"OnOffType\",\"value\":\"ON\"}", "type": "ItemStateEvent", "_msgid": "a3bdd06.f5c423" }

I'm not a seasoned javascript nor Node-RED guy so please share even if the answer is obvious to you.

gorootde commented 7 years ago

This should be a plain JSON object, not a string containing JSON. I'll fix this as soon as possible.

jtmoderate876 commented 7 years ago

I think github modifies the my payload when I paste so here is an image: image

And here it is with via "insert code": { "topic": "smarthome/items/OutHoliday322AOF/statechanged", "payload": "{\"type\":\"OnOffType\",\"value\":\"OFF\",\"oldType\":\"OnOffType\",\"oldValue\":\"ON\"}", "type": "ItemStateChangedEvent", "_msgid": "647d15ec.9b82ec" }

Thanks for looking into it and again - I could just be doing something wrong

gorootde commented 7 years ago

It was an issue in the code. The payload is delivered as String by openhab, and not as JSON object. I've fixed this in version 0.0.4 of the nodes. Please update your nodes.

jtmoderate876 commented 7 years ago

I upgraded the node-red-contrib-openhab to 0.0.4 but still get strange payload of { "topic": "OutHoliday322AOF", "payload": "{\"type\":\"OnOffType\",\"value\":\"ON\"}", "type": "ItemStateEvent", "_msgid": "cb70f70f.348f08" }

What am I doing wrong?

gorootde commented 7 years ago

Where do you copy this code from? Try adding an openhab input node, only connected to a debug node. Take a look in your debug console. Is the payload field expandable, or is it just a string?

jtmoderate876 commented 7 years ago

I copied the msg from the debug menu as you suggest - but my Node_RED with PI doesn't have the debug Expand feature.

image

I wonder if it has something to do with that I am using the node_RED version that comes with Raspberry Pi - which is not the latest.

In this version it doesn't have the expandable payload functionality in the debug menu that the latest node-RED has.

I'll try an upgrade from Pi Node-RED to latest node-RED and report back.

Thx for your continued attention.

jtmoderate876 commented 7 years ago

Michael, it was my version of either node-RED, node.js or something else - I suspect node.js. I am sorry I wasted your cycles on this but hopefully someone else will find this.

I upgraded my RPI node_RED using: upgrade-nodejs-and-nodered from command prompt and 20 minutes later everything was working including payload format and upgraded node-RED debut window: image

Thank you.

gorootde commented 7 years ago

Hi Jeff,

glad you found the issue :-)