Parsing payload

170 views
Skip to first unread message

Deepak Raja

unread,
Aug 25, 2015, 11:10:12 AM8/25/15
to Node-RED
Below is the code for parsing payload in function node to template node.The value is corrupted.


[{"id":"fa40bb9b.05bf48","type":"template","name":"Default","field":"payload","format":"handlebars","template":"<!DOCTYPE html>\n<html>\n   <head>\n      <title>IBAROUND CONTEXTUAL MARKETING</title>\n      <script type = \"text/javascript\">\n         function displayad()\n         {\n           document.getElementById(\"img\").src = \"{{payload}}\"; \n         }\n         function startTimer()\n          {\n              setInterval(displayad,3000);\n          }\n      </script>\n   </head>\n   \n   <body onload=\"startTimer()\">\n        <img id=\"img\" src=\"https://lh3.googleusercontent.com/MbS8rAifpson5yuYTa5MHbbVENGNF192n6P6UbMeqQ=w528-h562-no \" height=600 width=400 />\n   </body>\n</html>","x":230.89581298828125,"y":431.8888854980469,"z":"631a9bdb.9ce564","wires":[["fa887fd1.05778","2e5a6814.d1a598"]]}]

Nicholas O'Leary

unread,
Aug 25, 2015, 11:11:58 AM8/25/15
to Node-RED Mailing LIst
Hi,

could you describe a bit more what the problem is and what help you're looking for?

Nick

On 25 August 2015 at 16:10, Deepak Raja <deepa...@ibaround.com> wrote:
Below is the code for parsing payload in function node to template node.The value is corrupted.


[{"id":"fa40bb9b.05bf48","type":"template","name":"Default","field":"payload","format":"handlebars","template":"<!DOCTYPE html>\n<html>\n   <head>\n      <title>IBAROUND CONTEXTUAL MARKETING</title>\n      <script type = \"text/javascript\">\n         function displayad()\n         {\n           document.getElementById(\"img\").src = \"{{payload}}\"; \n         }\n         function startTimer()\n          {\n              setInterval(displayad,3000);\n          }\n      </script>\n   </head>\n   \n   <body onload=\"startTimer()\">\n        <img id=\"img\" src=\"https://lh3.googleusercontent.com/MbS8rAifpson5yuYTa5MHbbVENGNF192n6P6UbMeqQ=w528-h562-no \" height=600 width=400 />\n   </body>\n</html>","x":230.89581298828125,"y":431.8888854980469,"z":"631a9bdb.9ce564","wires":[["fa887fd1.05778","2e5a6814.d1a598"]]}]

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deepak Raja

unread,
Aug 25, 2015, 11:33:32 AM8/25/15
to Node-RED
Hi Nick,

Program:

              I am creating a proof of concept for our company,where we compare the temperature data(Object or IR Temperature) from sensor tag(cc2650) and display appropriate ad msgs to a web server based upon the threshold.For that,i have stored three different images in google photos and used those urls in the function-node(node-red) where i compare the object temperature value and store the msg.payload with appropriate urls of image.This payload is being passed to a template-node(node-red) of a webserver(myapp/addisplay13) which parses this url and display appropriate image,according the temperature value.

Problem:
            During storing the url into the msg.payload in function-node,it works fine,but once the msg.payload object is passed from function-node to template node and parsed there for displaying in the web server,the link is getting corrupted and could not able to display the appropriate image.So,i need to know ,is there is any function to convert object(msg.payload) to string value("url")  and store it in a string variable and use it or is there any way, i can send this msg.payload from function-node to template node without getting corrupted.


I have attached the code of my flow below.Please take a look and let me know ,if there is something i need to change to make it work.


[{"id":"fa40bb9b.05bf48","type":"template","name":"Default","field":"payload","format":"handlebars","template":"<!DOCTYPE html>\n<html>\n   <head>\n      <title>IBAROUND CONTEXTUAL MARKETING</title>\n      <script type = \"text/javascript\">\n         function displayad()\n         {\n           document.getElementById(\"img\").src = \"{{payload}}\"; \n         }\n         function startTimer()\n          {\n              setInterval(displayad,3000);\n          }\n      </script>\n   </head>\n   \n   <body onload=\"startTimer()\">\n        <img id=\"img\" src=\"https://lh3.googleusercontent.com/MbS8rAifpson5yuYTa5MHbbVENGNF192n6P6UbMeqQ=w528-h562-no \" height=600 width=400 />\n   </body>\n</html>","x":230.89581298828125,"y":431.8888854980469,"z":"631a9bdb.9ce564","wires":[["fa887fd1.05778","2e5a6814.d1a598"]]}]


Hoping for a positive response from your side.

Regards,
Deepak Raja
Message has been deleted

Deepak Raja

unread,
Aug 25, 2015, 11:45:18 AM8/25/15
to Node-RED
Hi Nick,
                  Below is the exact flow of the node.

[{"id":"e15c2a9b.1ea3d8","type":"websocket-listener","path":"/addisplay13","wholemsg":"false"},{"id":"3ba0505f.c45fb","type":"websocket in","name":"adlistener","server":"e15c2a9b.1ea3d8","client":"","x":102,"y":564,"z":"3f8ec49.fc0713c","wires":[["9db589c1.624a78"]]}]

Regards,
Deepak Raja 

Nicholas O'Leary

unread,
Aug 25, 2015, 12:04:45 PM8/25/15
to Node-RED Mailing LIst
HI Deepak,

you've not provided the complete flow, only a few individual nodes, so it's hard to see what's happening.

When you say the link is getting corrupted, what exactly do you see as the output of the template node? I see you have {{payload}} where you want msg.payload to be inserted. If the url contains any html entities, the mustache template will be escaping html entities in your url - in which case you need to use triple braces: {{{payload}}}.

Nick

--

Deepak Raja

unread,
Aug 25, 2015, 12:27:20 PM8/25/15
to Node-RED


Hi Nick,
                 I have provided the snapshot of my node-red window,which gives information about all the nodes as well as their flow.In the same picture on the debug console,you will find the "url" link came from the payload is corrupted  inbetween with some random values(#^&) something like that,which prevents the window to parse the html url and display the image.

I have followed your instruction and changed the braces from 2 to 3 and now the url is coming somehow,but still since it is a object format,the web server does not recognise the link and parse it to display the appropriate image.

Hope the picture provides you more insight ,how the node works and flow occurs.

Hoping for positive response from your side.

Regards,
Deepak Raja
node-red pic.jpg
Reply all
Reply to author
Forward
0 new messages