Support for Websockets in Edge

Have tried to add support in a Edge driver for Websocket (client) using GitHub - lipp/lua-websockets: Websockets for Lua., that is written in pure Lua, without success.

Has anyone been able to add Websockets support in Edge?

1 Like

FYI, I have now managed to add support for lua-websockets in Edge. The main problem was actually a known bug regarding the implementation of PING/PONG in the module.
To make it work with the Edge event loop, I also had to adapt the code to cosock socket and cosock ssl (wss).

Adapted code here: GitHub - Goran58/lua-websockets: Websockets for Lua.

4 Likes

Hi Gol

I’m trying to add in your customised websocket library but I’m having difficulty (im a lua novice, so it’s probably something basic that I am missing)

I have downloaded the websockets library and installed it using luarocks

This is my path…

echo $LUA_PATH
/home/louis/st/stapi/lua_libs-api_v0/?.lua;/home/louis/st/stapi/lua_libs-api_v0/?/init.lua;./?.lua;./?/init.lua;/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;/usr/share/lua/5.3/?.lua;/usr/share/lua/5.3/?/init.lua;;/home/louis/.luarocks/share/lua/5.3/?.lua;/home/louis/.luarocks/share/lua/5.3/?/init.lua

and websockets appears to be in /home/louis/.luarocks/share/lua/5.3/

But when i install my driver to ST i get the following in logs

2021-12-03T15:48:22.529491679+00:00 FATAL Hello World  Lua: runtime error: [string "init.lua"]:5: Module 'websocket.client' not found
stack traceback:

Is there something special i have to do to make smartthings bundle the library when i package it?

Thank you

Hi,
Instead of changing the LUA_PATH it is probably easier to copy all files from the lua-websockets src-directory to the src-directory of your Edge-driver.

Thanks, not really sure why I didn’t think of trying that.

Incase you are interested, I’m going to attempt to see if I can speak to my Logitech harmony hub over websockets. I’ve found a nodejs library that does exactly that, so I’m going to see if I can rewrite some of the functionality in lua, and then figure out how to present the devices connected to the harmony hub as devices in st.

I just don’t get the most amount of time to work on it so it’s probably going to take me a while.

What was you communicating with over websockets? Thanks

Louis

2 Likes

I intended to develop a driver for integration with a burglary alarm system (Vanderbilt SPC). The communication is based on HTTPS and Websockets.
But actually, after spending two weeks struggling with the issues in the beta-version of the Edge SDK, I have decided to pause the development until ST provide a stable version of the SDK.

2 Likes

Hi Gol & Louis,

Glad to hear someone were trying to do something similar. Just want to know if you can share with what issues did you encounter and make you decide to pause at present?

@taustin has a couple of working websocket projects for Edge. They are still in beta because Edge itself is still in Beta, but you can take a look. you can find them (and any future offerings) from the quick browse lists in the community-created wiki:

https://thingsthataresmart.wiki/index.php?title=How_to_Quick_Browse_the_Community-Created_SmartApps_Forum_Section#Quick_Browse_Links_for_Edge_Drivers

1 Like

FYI, my drivers usually don’t use any third party libraries. My webhook, RESTful interfaces are implemented with vanilla sockets.

2 Likes

I guess the driver isn’t open sourced? Since I can’t seem to find link to source.

Which driver are you looking for? I have several Edge drivers in my public github repositories.

1 Like

I have posted about the driver I am working on here, I was able to get websockets working but had to change the library @gol shared and even hardcode some of the handshake behaviour as i was unable to get that bit to work in ST edge driver