Gateway architecture

From OpenMotics
Jump to: navigation, search

The following diagram shows an overview of the communication from and to the Gateway.

Gwoverview.png

Components running on the Gateway Controller (BeagleBone)

This sections describes the daemons running on the BeagleBone.

openmotics

This is the main daemon. It communicates with the master (using rs232) and the power modules (using rs485) and provides the Webservice over HTTPS. This webservice provides the local gateway interface (on https://OpenMotics.local/) and is used by the cloud to perform action like setting outputs and thermostats.

The daemon is implemented in openmotics_service.py and run in supervisord. See [1] for more information on how to use supervisord.

vpn_keepalive

The vnp_keepalive daemon periodically asks the cloud whether the vpn connection should be opened (over an encrypted HTTPS connection). The daemon includes status information (about inputs, outputs, thermostats and power modules) in the requests, this makes sure that the status information in the cloud is alway updated in near real-time. The status information is fetch from the openmotics daemon using a local HTTP connection (the HTTP socket is configured to only respond to requests from localhost and cannot be used from external hosts: the encrypted HTTPS connection has to be used from external hosts).

The cloud has to ability to perform some basic configuration and actions using the keepalive messages:

  • The cloud can control the interval between two consecutive keepalive messages from the gateway by setting the sleep_time.
  • The cloud can ask the gateway to perform an action, this can be used to perform actions when the vpn connection is closed.

The status information send to the cloud is defined by the mode in the vpn_keepalive daemon. For instance: when configuring his system, the cloud shows the user the last pressed inputs, this makes it easy to identify the inputs. However when the configuration is over, the cloud does not need the last pressed inputs. The last pressed inputs are only sent when in init mode, this mode is set by the cloud.

The daemon in implemented in vpn_service.py and run in supervisord.

led_service

The leds on the toppanel are driven by the led_service. The led_services communicates with the top panel using i2c and exposes the functionality to set the leds to the other daemons using dbus.

The led_services also keeps track of the button on the top panel: if the button is pressed for more then 5 seconds, the gateway is put in authorized mode. When an action that requires authorized mode (for instance creating a new user) is received in the openmotics daemon, the openmotics daemon uses dbus to communicate with the led_service daemon to check if the gateway is in authorized mode.

The daemon in implemented in physical_frontend_service.py and runs in supervisord.

openvpn

All communication from the cloud to the gateway is done over a OpenVPN tunnel. The tunnel makes sure that the cloud can reach the gateway through a firewall, it also provides authentication and encryption for the connection.

This is the standard OpenVPN 2.2.2 and runs in systemd (checking the state of the daemon in supervisor was too slow, so we moved this daemon to systemd).

configure_ports

Run once at startup: sets the correct input/output mode on the gpio pins of the BeagleBone. This script is located at /opt/openmotics/bin/configure_ports.sh and runs in supervisord.


ntpsync

The OpenVPN certificates are valid for a limited time only. When ntpdate fails, its sets the clock to the 1st of Januari 2000, the OpenVPN certificates are not valid for that timestamp. The ntpsync script is a wrapper for ntpdate that sets the date to the 1st of July 2013 if the sync fails and retries the sync after one minute. The script keeps running and sync the time every hour.

This script is located at /usr/bin/ntpsync and runs in supervisord.


watchdog

The BeagleBone watchdog is configured to reset the system after one minute without watchdog reset. The watchdog daemon resets the watchdog every 10 seconds. The daemon is implemented in "watchdog.py" and runs in supervisord.

The activation of the watchdog is implemented as a u-boot and linux patch.