Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outbound websocket example: publisher/subscriber to provide a working starting point? #71

Open
wimleers opened this issue Oct 6, 2023 · 1 comment

Comments

@wimleers
Copy link

wimleers commented Oct 6, 2023

https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Ws shows it's possible to create outbound websockets from scripts. Cool.

But all it provides in terms of showing how to communicate is this:

The Outbound Websocket component uses ws as RPC namespace and provides the methods:

There's only one very vague example in this repo:

function emitOverWs(measurement) {
  Shelly.emitEvent(CONFIG.event_name, measurement);
}

function emitOverWs(measurement) {

Can I just start listening for incoming data using Shelly.addEventHandler()?

Why not create a typical "publisher/subscriber" example, combined with a HTTPServer? The publisher sends an event over the websocket to the subscriber, and the subscriber sets the received value in KVS. That way, there's no dependency on external components and it'd provide a great starting point to connect other devices.

Thanks for considering! 😊

@wimleers wimleers changed the title Example script with outbound websocket relaying information Outbound websocket example: publisher/subscriber to provide a working starting point? Oct 6, 2023
@Mircho
Copy link
Contributor

Mircho commented Oct 10, 2023

Maybe the example is misleading a bit. In a Shelly the transport is not related to the notification mechanism. One may have MQTT and oubound WebSocket channels open and publish notifications over them. Or receive RPC requests. One can communicate directly with a script by calling the Script.Eval method if he knows which script id the script has.

To directly communicate with the device you can add an http endpoint handler in a script or subscribe for an MQTT topic:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants