• Day 1 - Setup and POC

    Tobias Schmitt08/05/2016 at 14:47 0 comments

    Yesterday I did a full setup of the environment and started with a little Proof-Of-Concept code. At first I'd like to present the architecture:

    We start at the top left. There will be some GPIO detection and logging Module. This module detects sensor data and pastes it to my MQTT Broker. Since MQTT as a protocol has no data persistence, you have to implement it yourself: the MQTT-Data-Service receives this data and saves it to a database. At last a webscript polls the data from there and displays it for the users.

    GPIO Detection v0.01 - NodeMCU

    Since my originally planned RaspberryPi 3 has not arrived, I did a little first-shot with a NodeMCU module. I simply put it on a breadboard and connected a photosensitive resistor on Port A0. The resistor is connected to the "washing"-LED of the laundry machine with formable glue.

    The NodeMCU is programmed with platform IO and the arduino framework. It connects to WLAN and MQTT and posts the status of A0 port every 10 seconds. No rocket science now. You can find the code here.

    MQTT-Broker

    As broker I use mosquitto on Ubuntu 16.04.

    MQTT-Data-Service

    As i mentioned, MQTT will not preserve your data. When a client posts, and you are not connected to receive it, the value will disappear in nirvana. So I had to implement a persistence module myself. This is a little python tool which reads a config.ini file, where the MySQL/MQTT connections are defined and also every subscription topic, that should be followed. It then connects to the MQTT broker and subscribes to every defined topic. When it receives a message, it simply pastes it into the database. For further information about the structure of the database please consider the Github Repository.

    Webserver/Script

    I use nginx as a webserver. The super simple script is written in php7. It connects to the database, receives the current MQTT Data and displays it on a bootstrap webpage.

    HAHA I cannot remove that last list point. What a bug! :D