CГApL∀b SmartPlug's simple backend server
The SmartPlug supports two options to communicate its states to the world:
- ThingSpeak's Twitter API
- 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.
The backend provides three main features:
- WWW server to receive status messages from the SmartPlug
- Twitter API to tell the world the fate of your SmartPlug
- 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.
The main configuration is to set the two server ports for the HTTP REST API and
the WebSocket respectively. Set the
Tweeting is optionally. If the
TWITTER_ENABLED variable is set to
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.