Minot tweaks to MG_sensor_demo

Fix WS connect address
Only update graphs when connected

PUBLISHED_FROM=3a3c4e2d21595f48c811b45fb391f7709dc0bcf7
This commit is contained in:
Deomid Ryabkov 2016-04-19 13:08:54 +01:00 committed by rojer
parent 56c687b39b
commit 7519a3765b
2 changed files with 26 additions and 5 deletions

View File

@ -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">
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=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="cc3200"/>
</option>
@ -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">
<listOptionValue builtIn="false" value="MG_ENABLE_HTTP_STREAMING_MULTIPART=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="cc3200"/>
</option>

View File

@ -447,6 +447,8 @@ API.txt for details.
})(jQuery);
var ws = null;
var connected = false;
$(document).ready(function() {
var startTime = Date.now();
@ -478,6 +480,7 @@ $(document).ready(function() {
};
var updateGraph = function(g) {
if (!connected) return;
var now = Date.now();
//if (now - g.lastUpdateTime < 50) return;
g.lastUpdateTime = now;
@ -518,7 +521,7 @@ $(document).ready(function() {
]
},
temp: {
title: 'Temperature sensor',
title: 'Sensor die temperature',
plot: null,
lastUpdateTime: null,
data: [
@ -533,10 +536,24 @@ $(document).ready(function() {
setInterval(function() { updateGraph(v); }, 100);
});
// Create Websocket connection. For simplicity, no reconnect logic is here.
//var ws = new WebSocket('ws://' + location.host);
var ws = new WebSocket('ws://192.168.1.54');
ws.onmessage = function(ev) {
function wsConnect() {
if (ws != null) return;
var wsAddr = 'ws://' + location.host;
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 {
var obj = JSON.parse(ev.data);
//var timestamp = startTime + parseInt(obj.ts * 1000);
@ -565,4 +582,6 @@ $(document).ready(function() {
ws.send(JSON.stringify({ t: 1, v: state }));
});
wsConnect();
setInterval(wsConnect, 1000);
});