I am making a plugin to add to the E-450 controller where it will make a web socket connection to our server to receive the events that happen inside the controller. Has anyone worked on any of this in .lua? I have seen something similar done in python.
yes, you could create a socket connection with this lua code
require "network"
local _logger = require("logging")
socketConnection = network.connect( { ip = "192.168.1.100", port = "3000", connection_type = "TCP" } )
if not socketConnection then
_logger.error("Fail to connect to socket server")
else
_logger.info("Client connect to socket server")
end
remember to add the “network” module to the permissions in the config.json file
You can use any existing Lua API functions to access the collections that the controller provides.
But, there is no such Lua call that provides a rooms list for now.
We can add it in case something is needed and that something isn’t violating security rules.
The way of obtaining something in a Lua plugin that is a part of WebSocket API is not the right way, I think.
It needs your code to support both secure and insecure ways of communication, for a secure one you need to update user credentials, etc.
To your question: there is no way to establish a WebSocket connection from a hub to an outer WebSocket server.
There is no such functionality, and it cannot be implemented without firmware support.
What we provide is a HTTP lua module to which make it possible to make queries outside of a hub in an asynchronous way.
There is no way to write and execute synchronous lua code on a hub.
So, to solve your task, I’d suggest you to make an HTTP connection from your “server” to the E450’s HTTP server .
It will give you an SSE (Server-Side Events) stream of changes.
And, another one: /v1/request, will give you the ability to ask WebSocket API requests directly from the hub.
1 Like
Best Home Automation shopping experience. Shop at Ezlo!