Skip to content

Latest commit

 

History

History

backend

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

CГApL∀b SmartPlug's simple backend server

The SmartPlug supports two options to communicate its states to the world:

  1. ThingSpeak's Twitter API
  2. This simple backend server

The latter one obviously needs to be self hosted, while the first one is an IoT service. The main reason ThingSpeak is supported in the first place was initial laziness, but eventually the companion app idea was born, for which a backend was needed anyway.

Features

The backend provides three main features:

  1. WWW server to receive status messages from the SmartPlug
  2. Twitter API to tell the world the fate of your SmartPlug
  3. WebSocket server to notify yourself via the companion app

The WWW server is a very basic Bottle application without much RESTability, just one simple POST is all it listens to.

The Twitter API is implemented using Mike Taylor's Python Twitter API wrapper. To use this, you have to set up an application in your Twitter account to get all the tokens the API needs. This is all nicely documented in the previous link.

Lastly, the WebSocket server is implemented using Autobahn

Note, there is no persistent storage. Nothing gets stored in a database but is kept in memory only. Meaning, if the backend process is killed, all information is lost. Once restarted, the plug state is unknonwn until an actual event update is received from the SmartPlug.

Configuration

The main configuration is to set the two server ports for the HTTP REST API and the WebSocket respectively. Set the WWW_SERVER_PORT and WS_SERVER_PORT variables accordingly.

Twitter

Tweeting is optionally. If the TWITTER_ENABLED variable is set to False, everything Twitter related will be skipped. If set to True however, make sure to properly set up all token variables below it. Once again, check the Twitter API's Github documentation for guidance on this.