Commit 7519a376 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by rojer

Minot tweaks to MG_sensor_demo

Fix WS connect address
Only update graphs when connected

PUBLISHED_FROM=3a3c4e2d21595f48c811b45fb391f7709dc0bcf7
parent 56c687b3
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.2068422510" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols"> <option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.2068422510" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols">
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/> <listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/>
<listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/> <listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/>
<listOptionValue builtIn="false" value="FS_SLFS_MAX_FILE_SIZE=262144"/>
<listOptionValue builtIn="false" value="MG_FS_SLFS=1"/> <listOptionValue builtIn="false" value="MG_FS_SLFS=1"/>
<listOptionValue builtIn="false" value="cc3200"/> <listOptionValue builtIn="false" value="cc3200"/>
</option> </option>
...@@ -94,6 +95,7 @@ ...@@ -94,6 +95,7 @@
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.1633469996" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols"> <option id="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE.1633469996" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.2.compilerID.DEFINE" valueType="definedSymbols">
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/> <listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=1"/>
<listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/> <listOptionValue builtIn="false" value="SL_PLATFORM_MULTI_THREADED=1"/>
<listOptionValue builtIn="false" value="FS_SLFS_MAX_FILE_SIZE=262144"/>
<listOptionValue builtIn="false" value="MG_FS_SLFS=1"/> <listOptionValue builtIn="false" value="MG_FS_SLFS=1"/>
<listOptionValue builtIn="false" value="cc3200"/> <listOptionValue builtIn="false" value="cc3200"/>
</option> </option>
......
...@@ -447,6 +447,8 @@ API.txt for details. ...@@ -447,6 +447,8 @@ API.txt for details.
})(jQuery); })(jQuery);
var ws = null;
var connected = false;
$(document).ready(function() { $(document).ready(function() {
var startTime = Date.now(); var startTime = Date.now();
...@@ -478,6 +480,7 @@ $(document).ready(function() { ...@@ -478,6 +480,7 @@ $(document).ready(function() {
}; };
var updateGraph = function(g) { var updateGraph = function(g) {
if (!connected) return;
var now = Date.now(); var now = Date.now();
//if (now - g.lastUpdateTime < 50) return; //if (now - g.lastUpdateTime < 50) return;
g.lastUpdateTime = now; g.lastUpdateTime = now;
...@@ -518,7 +521,7 @@ $(document).ready(function() { ...@@ -518,7 +521,7 @@ $(document).ready(function() {
] ]
}, },
temp: { temp: {
title: 'Temperature sensor', title: 'Sensor die temperature',
plot: null, plot: null,
lastUpdateTime: null, lastUpdateTime: null,
data: [ data: [
...@@ -533,10 +536,24 @@ $(document).ready(function() { ...@@ -533,10 +536,24 @@ $(document).ready(function() {
setInterval(function() { updateGraph(v); }, 100); setInterval(function() { updateGraph(v); }, 100);
}); });
// Create Websocket connection. For simplicity, no reconnect logic is here. function wsConnect() {
//var ws = new WebSocket('ws://' + location.host); if (ws != null) return;
var ws = new WebSocket('ws://192.168.1.54'); var wsAddr = 'ws://' + location.host;
ws.onmessage = function(ev) { console.log('Connecting to', wsAddr);
ws = new WebSocket(wsAddr);
ws.onopen = function() {
console.log('Connected');
connected = true;
};
ws.onclose = function() {
console.log('Disconnected');
connected = false;
ws = null;
};
ws.onmessage = handleWsMessage;
}
function handleWsMessage(ev) {
try { try {
var obj = JSON.parse(ev.data); var obj = JSON.parse(ev.data);
//var timestamp = startTime + parseInt(obj.ts * 1000); //var timestamp = startTime + parseInt(obj.ts * 1000);
...@@ -565,4 +582,6 @@ $(document).ready(function() { ...@@ -565,4 +582,6 @@ $(document).ready(function() {
ws.send(JSON.stringify({ t: 1, v: state })); ws.send(JSON.stringify({ t: 1, v: state }));
}); });
wsConnect();
setInterval(wsConnect, 1000);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment