Is this possible to connect from losant (workflow) to web socket and maintain persistent connection for unlimited time?
Best regards.
Mirek.
Is this possible to connect from losant (workflow) to web socket and maintain persistent connection for unlimited time?
Best regards.
Mirek.
Opening a persistent websocket connection using a workflow is not possible. Cloud workflows have a 60 second timeout on any single execution. We have considered a websocket integration that would allow you to form a persistent connection and then trigger workflows on incoming messages. Would that work for your use case?
That would work for some of our use cases.
First of all thank you very much for fast answer,
I think it would work and at least it is worth to try. What I want to do is make a http request (undefined time) and wait for message, as you Brandon wrote above. Then, when message come I would trigger a workflow. Yes it sounds reasonably.
Sorry for my english.
Have a nice day.
Mirek.
One of the challenges with a Websocket integration is that the data is raw bytes, so we canāt automatically know where a message ends to trigger a workflow with it.
Do either of you use a standard protocol on top of Websockets? Something like socket.io?
In an application context, we use J1939 (from the engine world) in Losant as a top level protocol and parse it within the platform, which is carried over a proprietary UDP-based protocol from the cellular gateway vendor.
We have not used either of these protocols with Websocket however. sockets.io seems like a great starting point though.
Hello Brandon, Evan.
Iām not sure that my knowledge is enough deep to pass valuable
information to you. In few sentences Iāll describe what I need to do.
Controller that I use is Seeed Studio Wio Node/Link with button connected to
it. Controller has predefined firmware that sends data to server with REST API
service. The benefit is that there is no need to program the controller. Seeed
Studioās server doesnāt keep any historical data, so I have to pick it up
before it gone. Some information (data) for example temperature, humidiy is
easy to collect. Its enough to make http request every one minute or so. But
there is also event type data, generated by, for example: button or PIR sensor.
That event is passed by websocket. Below is example of connection in javascript:
The response message is json formatted and looks like below:
[5] RECV: {āmsgā: {ābutton_pressedā: ā3ā}}
[4] RECV: {āmsgā: {ābutton_pressedā: ā3ā}}
[3] RECV: {āmsgā: {ābutton_pressedā: ā3ā}}
[2] RECV: {āmsgā: {ābutton_pressedā: ā3ā}}
[1] SENT: ā¦ā¦your tokenā¦ā¦.
[0] CONNECTED
Best regards.
Mirek.
Please do elaborate on socket.io
How can it be used within the Losant Environment?
The way I need to use it is as follows:
1.1 Where can I plug the following socket connection code:
const Client = require(āsocket.io-clientā);
socket = Client(SOCKET_SERVER_URL, { jsonp: false });
socket.on(āconnect_errorā, (err) => {
console.log(err);
throw āSocket connection damaged, please checkā;
});
2.2 Where will I be able to read the successful/failed authentication (JSON structure) for the auth
event
ā,
āreadingsā: [{
āDevice_IDā: āā,
āreading_timeā:āepoch_valueā,
āName_of_Attribute_1ā: ānumerical_valueā,
āName_of_Attribute_2ā: ānumerical_valueā,
āName_of_Attribute_3ā: ānumerical_valueā,
āName_of_Attribute_4ā: ānumerical_valueā,
āName_of_Attribute_5ā: ānumerical_valueā
}]
},
});
socket.on(āerrorsā, (data) => {
console.log(data);
});
socket.on(āackā, (data) => {
console.log(data);
});
3.2 Where will I be able to validate the following (JSON structure) ack event?
{
ācodeā, āā,
āackā: true,
āidā: ā<MESSAGE_ID>ā
}
socket.io is not supported directly with Losant. Since this post was original created, however, we have released Streaming Endpoints, which utilizes Server-Sent Events under the hood.
Server-sent events provide real-time streaming of data in one direction: from the server to the client (usually a web browser).
To send data from the client to the server, a basic POST request to a standard Experience Endpoint works very well.
Thank you for this answer, the only way for me to communicate with this API is through socket.io
What will be your recommendation for a work around?
Should I send the payload to AWS and create a socket.io with their services: socket.io server under AWS ELB (Application Load Balancer) or Amazon API Gateway