Hi Paul, thanks for answering.
The ws.close () is only executed with the finish button. I'm sure of that because if I send a single command it still works.
I show you the part of the code:
ws.onmessage = function (msg) {
var response = JSON.parse(msg.data);
if (response.success) {
if(response.name == 'myOffsets')
{
showOffsetValues(response);
}
else if(response.name == 'myPayload')
{
showPayloadValues(response);
}
}
};
And this is where I declare the offset I need and send to the websocket:
this.iniciar = function () {
var data = {
command: 'offsets.declare',
name: 'myOffsets',
offsets: [{...CODE...}
]
}
ws.send(JSON.stringify(data));
var request = {
command: 'offsets.read',
name: 'myOffsets',
interval: 1000
}
ws.send(JSON.stringify(request));
var PayloadSend = {
command: 'payload.read',
name: 'myPayload',
weightUnit: 'Kg',
volumeUnit: 'l'
}
ws.send(JSON.stringify(PayloadSend));
}
Thanks for your time.