-
Notifications
You must be signed in to change notification settings - Fork 2
/
blynk-websocket.json
1 lines (1 loc) · 6.8 KB
/
blynk-websocket.json
1
[{"id":"eae8969d.cdd158","type":"inject","z":"2983d627.2be4aa","name":"","topic":"","payload":"1","payloadType":"num","repeat":"1","crontab":"","once":true,"x":116,"y":601,"wires":[["e0b03cb3.1e4e8","f2029e6.9c6e46"]]},{"id":"e0b03cb3.1e4e8","type":"function","z":"2983d627.2be4aa","name":"","func":"\nmsg.payload = Math.random();\n\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":602,"wires":[["77477c.743b7884"]]},{"id":"77477c.743b7884","type":"blynk-websockets-out-write","z":"2983d627.2be4aa","name":"","pin":"3","client":"4a806e96.251ee","x":499,"y":603,"wires":[]},{"id":"ba8ac800.cb8328","type":"blynk-websockets-in-write","z":"2983d627.2be4aa","name":"","pin":"12","client":"4a806e96.251ee","x":176,"y":223,"wires":[["c64ffae8.e79548","eb76f04c.b4825"]]},{"id":"dba99cca.4a522","type":"blynk-websockets-out-write","z":"2983d627.2be4aa","name":"","pin":"10","client":"4a806e96.251ee","x":510,"y":740,"wires":[]},{"id":"f2029e6.9c6e46","type":"function","z":"2983d627.2be4aa","name":"","func":"context.count = context.count || 0;\ncontext.count += 1;\nmsg.payload = context.count % 2 > 0 ? 255 : 0;\nreturn msg;","outputs":1,"noerr":0,"x":304,"y":739,"wires":[["dba99cca.4a522"]]},{"id":"333df0d4.74234","type":"http in","z":"2983d627.2be4aa","name":"","url":"/blynk","method":"get","swaggerDoc":"","x":193,"y":365,"wires":[["d938ff74.39a8f"]]},{"id":"c64ffae8.e79548","type":"debug","z":"2983d627.2be4aa","name":"","active":true,"console":"false","complete":"payload","x":538,"y":175,"wires":[]},{"id":"d938ff74.39a8f","type":"template","z":"2983d627.2be4aa","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<html>\n <head>\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Simple Display</title>\n <link rel=\"stylesheet\" href=\"themes/jquery.mobile.icons.min.css\" />\n\t\t<link rel=\"stylesheet\" href=\"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css\" />\n <script src=\"https://code.jquery.com/jquery-1.11.1.min.js\"></script>\n <script src=\"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js\"></script>\n\t\t<link rel=\"stylesheet\" href=\"themes/pete.min.css\" />\n\t\t\n </head>\n <script type=\"text/javascript\">\n var topics = {};\n var wsUriC = \"ws:https://\" + window.location.host + \"/ws/blynk\";\n\t\tvar ws;\n\t\t\n\t\tvar light0='<img src=\"icons/light0.png\" alt=\"someimage\" />';\n\t\tvar light1='<img src=\"icons/light1.png\" alt=\"someimage\" />';\n\t\t\n\t\tfunction gIcon(imName)\n\t\t{\n\t\t\treturn '<img style=\"width:32px; height:32px; vertical-align:middle\" src=\"icons/'+imName+'.png\">'\n\t\t}\n\t\t\n function wsConnectC() {\n console.log(\"connect\",wsUriC);\n ws = new WebSocket(wsUriC);\n ws.onmessage = function(msg) {\n var line = \"\";\n console.log(msg.data);\n\t\t\t\tvar fromPage=JSON.parse(msg.data);\n if (fromPage.state!=null) { \n\t\t\t\t\tif (fromPage.state!=\"\") \n\t\t\t\t\t\t$(\"#info1\").html(fromPage.state); \n\t\t\t\t\telse \n\t\t\t\t\t\t$(\"#info1\").html(\"Nothing entered\"); \n\t\t\t\t} \t\t\t\n\t\t\t\tif (fromPage.my_slider!=null) $(\"#info2\").html(fromPage.my_slider+\"c\");\n if (fromPage.my_switch!=null) $(\"#info3\").html(fromPage.my_switch);\n\t\t\t\tif (fromPage.my_slider!=null) $(\"#my_slider\").val(fromPage.my_slider).slider(\"refresh\");\n if (fromPage.my_switch!=null) $(\"#my_switch\").val(fromPage.my_switch).flipswitch(\"refresh\");\t\t\t\t\n\t\t\t\tif (fromPage.my_switch!=null) { \n\t\t\t\t\tif (fromPage.my_switch==\"on\") \n\t\t\t\t\t\t$(\"#image_holder\").html(gIcon(\"light1\")); \n\t\t\t\t\telse \n\t\t\t\t\t\t$(\"#image_holder\").html(gIcon(\"light0\")); }\n }\n ws.onopen = function() {\n $(\"#status\").html(\"connected\");\n console.log(\"connected\");\n }\n ws.onclose = function() {\n $(\"#status\").html(\"not connected\");\n setTimeout(wsConnectC,1000);\n }\n }\n\t\t\n\tfunction sendMessage(){\n\t// send message back to page\n\tvar toPage='{\"my_input\":\"'+$(\"#my_input\").val()+'\",\"my_slider\":\"'+$(\"#my_slider\").val()+'\",\"my_switch\":\"'+$(\"#my_switch\").val()+'\"}';\n ws.send(toPage);\n } // end sendMessage\n \n \n </script>\n\t\n\t<body onload=\"wsConnectC();\" onunload=\"ws.disconnect;\">\n\t\t<div data-role=\"page\" id=\"one\" data-theme=\"a\">\n\t\t\t<div data-role=\"header\" data-position=\"inline\">\n\t\t\t\t<h2>Websockets Test Page</h2>\n\t\t\t</div>\n\t\t\t<div data-role=\"content\" data-theme=\"a\">\n\t\t\t\t<h2>Temperature Display</h2>\n\t\t\t\t<div id=\"status\">status unknown</div>\t\n\t\t\t\t<input id=\"my_input\" placeholder=\"Type something\"/>\t\t\t\n\t\t\t\t<div id=\"info1\">!Empty!</div>\n\t\t\t\t<hr/>\n\t\t\t\t<div data-role=\"collapsible\">\n\t\t\t\t<h4>Hello</h4>\n\t\t\t\twerlkj werlkjw erlkwje rwlekjr wer jkl\n\t\t\t\t</div>\n\t\t\t\t<div id=\"info2\">0</div>\n\t\t\t\t<hr/>\n\t\t\t\t<div id=\"info3\">0</div>\n\t\t\t\t<hr/>\n\t\t\t\t<label for=\"my_slider\">Input slider:</label>\n\t\t\t\t<input type=\"range\" id=\"my_slider\" value=\"60\" min=\"0\" max=\"100\" data-theme=\"a\" onMouseRelease=\"sendMessage()\"/>\t\n\t\t\t\t<select name=\"my_switch\" id=\"my_switch\" data-role=\"flipswitch\" onchange=\"sendMessage()\" data-theme=\"a\">\n\t\t\t\t\t<option value=\"off\">Off</option>\n\t\t\t\t\t<option value=\"on\">On</option>\n\t\t\t\t</select> <span id=\"image_holder\"></span><br/>\n\t\t\t\t<input type=\"button\" data-inline=\"true\" value=\"Update the lot\" onClick=\"sendMessage()\" />\n\n\t\t\t\t<input type=\"button\" data-inline=\"true\" value=\"Single Msg test\" onClick='ws.send(\"{\\\"my_input\\\":\\\"Just this\\\"}\")' />\n\t\t\t\t<a href=\"#two\">Get page 2</a>\n\t\t\t</div>\n\t\t</div>\t\t\n\t\t\n\t\t\t<div data-role=\"page\" id=\"two\" data-theme=\"a\">\n\t\t\tHello there\n\t\t\t</div>\n </body>\n</html>","x":352,"y":365,"wires":[["569a3c78.cf1694"]]},{"id":"569a3c78.cf1694","type":"http response","z":"2983d627.2be4aa","name":"","x":500,"y":365,"wires":[]},{"id":"eb76f04c.b4825","type":"function","z":"2983d627.2be4aa","name":"","func":"var state = msg.payload;\n\nmsg = {\n \tpayload: JSON.stringify(\n \t { \"state\" : state\n \t }\n )\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":414,"y":267,"wires":[["d87cd8a9.a06a18"]]},{"id":"d87cd8a9.a06a18","type":"websocket out","z":"2983d627.2be4aa","name":"","server":"147743d.7e555bc","client":"","x":576.8333282470703,"y":266.3333168029785,"wires":[]},{"id":"4a806e96.251ee","type":"blynk-websockets-client","z":"","name":"","path":"ws:https://blynk-cloud.com:8082/websocket","key":"c4bc90ad34b9403590d90ce5726fe984"},{"id":"147743d.7e555bc","type":"websocket-listener","z":"","path":"/ws/blynk","wholemsg":"false"}]