I built a bridge between socket and websocket with webtcp. Then i was able to display the data on browser, however it is not updating in real time unless i refresh the whole page. It needs to be updated constantly showing all the data. This is how i get the data, parse it and update it.
socket.on('data', function (data) {
var arr = data.split("|").slice(1);
var dataSet = {};
arr.map((o, i) => {
if ((i + 1) % 2 != 0) dataSet[o] = arr[i + 1];
});
console.log(dataSet);
$(document).ready(function () {
$("#example").DataTable({
retrieve: true,
deferRender: true,
searching: false,
paging: false,
"data": [dataSet],
"columns": [
{"data": "power"},
{"data": "mode"},
{"data": "execution"},
{"data": "Xact"},
{"data": "Yact"},
{"data": "Zact"},
{"data": "Xcom"},
{"data": "Ycom"},
{"data": "Zcom"},
{"data": "path_feedrate"},
{"data": "line"},
{"data": "Block"},
{"data": "program"}
],
});
});
});
This is my html:
<table id="example" class="display" width="100%">
<thead>
<tr>
<th>Power</th>
<th>Mode</th>
<th>Execution</th>
<th>Xact</th>
<th>Yact</th>
<th>Zact</th>
<th>Xcom</th>
<th>Ycom</th>
<th>Zcom</th>
<th>path_feedrate</th>
<th>line</th>
<th>Block</th>
<th>program</th>
</tr>
</thead>
</table>
This is how my data looks on console and on browser, it gets updated on console as waterjet machine is working but not on browser:
This is how looks raw data from socket:
2018-08-14T22:17:00.0631|Xcom|0.00|Ycom|0.00|path_feedrate|0.00
2018-08-14T22:17:00.0683|line|389286|Block|389286
2018-08-14T22:17:00.0709|Xact|402.79|Yact|33.84|Xcom|38.71|Ycom|24.19|path_feedrate|45.65
2018-08-14T22:17:00.0735|Xcom|0.00|Ycom|0.00|path_feedrate|0.00
2018-08-14T22:17:00.0787|line|389288|Block|389288
2018-08-14T22:17:00.0840|Xact|402.78|Xcom|19.36|path_feedrate|19.36
2018-08-14T22:17:00.0866|Xcom|0.00|path_feedrate|0.00|line|389290|Block|389290
2018-08-14T22:17:00.0944|Xact|402.75|Yact|33.83|Xcom|58.07|Ycom|24.19|path_feedrate|62.91
2018-08-14T22:17:00.0970|Xcom|0.00|Ycom|0.00|path_feedrate|0.00|line|389292|Block|389292
and so on....