Created
August 31, 2018 06:15
-
-
Save dendentang/57d089581c7aa2a9e26df69555e12f7a to your computer and use it in GitHub Desktop.
Keep updating sensors' data via websocket.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Keep updating sensors' data via websocket. | |
| */ | |
| function update_sensor(data_json){ | |
| var actions = "Do something" | |
| } | |
| function websocket_init(){ | |
| if ("WebSocket" in window){ | |
| var _socket_path = "ws://" + window.location.host + ":8801"; | |
| var web_socket = new WebSocket(_socket_path); | |
| web_socket.onmessage = function (_event){ | |
| var data_json = JSON.parse(_event.data); | |
| update_sensor(data_json); | |
| }; | |
| web_socket.onclose = function(){ | |
| bootbox.alert("Data connection failed and closed.") | |
| } | |
| }else{ | |
| bootbox.alert("Failed to initialize data connection.") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment