Page 1 of 1

transfer variable or device status between Indigo servers

PostPosted: Mon Mar 02, 2020 2:41 pm
by boekweg
Hi,

I have a multil level office setup with 4 separate Indigo servers managing the entire building. I want to transfer some variable status from one server to another.
All servers are in the same vlan. I was hoping to use the restfullAPI with the device extensions plugin and use the URL extension but I receive errors if I use that route.

Anybody a good idea?

The functionality I want to achieve is that every server will pass on a value if there is any presence on one of the building levels.

Re: transfer variable or device status between Indigo serv

PostPosted: Tue Mar 03, 2020 6:44 am
by DaveL17
I think I would probably use Indigo's RESTful API and Python to accomplish this. There are likely ways to add more robustness, but you could start with a broadcast method--any time a server's occupied status changes, it could broadcast its status to the other servers. Here's one way.

Each server has four variables: 'server1_occupied', 'server2_occupied', 'server3_occupied, server4_occupied.
Server 1 runs a trigger when 'server1_occupied' changes.
Trigger runs a short Python script to broadcast its status to the other servers (recommend using a linked script and not an embedded script)

Code: Select all
import requests
from requests.auth import HTTPDigestAuth

server_list = ['10.0.1.2', '10.0.1.3', '10.0.1.4']
username = 'USERNAME'
password = 'PASSWORD'
status = indigo.variables['server1_occupied'].value

for server in server_list:
    url = 'http://{0}:8176/variables/server1_occupied?_method=put&value={1}'.format(server, status)
    result = requests.get(url, auth=HTTPDigestAuth(username, password))

indigo.server.log(str(result.status_code))

If each server has different log in credentials, you'll need to amend the script to account for that. Also, this method stores the username and password in clear text within the script, so take that into account for your security situation (and presumes you're requiring a username and password on each server in the first place). The code above may need a bit of tweaking to account for response times, although I believe that the requests module is blocking until a response is received (so it might be fine).

The code is untested, but should be pretty close. If there are problems, post back; I'm happy to help debug.

Re: transfer variable or device status between Indigo serv

PostPosted: Tue Mar 03, 2020 7:33 am
by autolog
This is probably a classic use case for the use of MQTT.

Setup a MQTT broker on one Indigo server and then each Indigo server can publish topic updates to the MQTT broker and each Indigo server can subscribe to the topics from the other three servers. :)

Re: transfer variable or device status between Indigo serv

PostPosted: Tue Mar 03, 2020 3:55 pm
by boekweg
Thanks guys, I will look into both options