Webserver within plugin? - For receiving external events

Python and python framework

Moderator: leecollings

Post Reply
swevm
Posts: 23
Joined: Friday 16 September 2016 20:04
Target OS: Raspberry Pi / ODroid
Domoticz version: 8718
Location: Sweden
Contact:

Webserver within plugin? - For receiving external events

Post by swevm »

Hi,

Have just started to explore what can be done with the Python plugin capabilities. An awesome thing if you ask me as it open up much more ways to integrate stuff and in a way that is simpler due to Python vs C++.

I have a device from Teracom that is basically a ethernet connected IO device with relays, 1-wire and digital inputs together with rudimentary automation. For example a relay can be triggered if a temperature is reached on a 1-wire sensor or if a digital input state is changed etc.

The plugin I am planning to write will leverage these capabilities to configure an autonomous control system for a pool heater integrated with heatpump (water-water variant, a type very common the Nordics). Doing the actual configuration should not be the hard part as the device have defined APIs to control pretty much anything in it. The harder part which causes headache for me is to handle events coming from the Teracom unit in the form of SNMP traps or state data sent to an arbitrary URL.

My question is what is the best way to capture state change information coming in from external devices with Domoticz. The optimal way (at least how I think about it) would be to have a tiny webserver running within the plugin that the unit can post changes to and then data is immediately captured by plugin and processed. Not sure what issues this may cause with threading and lockups and before I start looking at I´m interested in hearing about ideas from the community here.

/Magnus
Domoticz on RPi3 with Razberry: 10xZME WALLC-S, 14x Fib Switch, 6x Fib Wallplug, 1x Fib Motion Sensor, 2x Fib Smoke Sensor, 1x Fib Universal sensor (with 1-wire), 3x SwiidInter cordsw, ESPEasy [1-wire and relay], Kodi, Node-Red [Onkyo NR-828, UI etc]
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Webserver within plugin? - For receiving external events

Post by Dnpwwo »

@swevm,

Adding the ability to 'Listen' for incoming connections is on the enhancement list but not there yet, as is UDP.

The current framework would probably not work with you embedding a web server, async and threading operations will have unknown effects (like, no idea what that would do, probably bad things).

A full blown web server might be a little tricky to add, SNMP support via UDP would be easier.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
User avatar
jorgh
Posts: 124
Joined: Friday 27 June 2014 23:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8224
Location: Netherlands
Contact:

Re: Webserver within plugin? - For receiving external events

Post by jorgh »

@Dnpwwo,

If UDP is on the enhancement list, could you also take into account to send and receive network broadcasts? As a lot of IP based devices have a discovery protocol based on UDP broadcasts, this will allow auto configuration of plugins (I now wrote this myself on the Onkyo plugin). Also nice on networks where DHCP might issue changing IP's.

Regards,

Jorg
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest