No ACL setup yet! Denying access to everyone.
en:edu:zmitac:macro:iot:project
Differences
This shows you the differences between two versions of the page.
| en:edu:zmitac:macro:iot:project [2019/03/07 11:08] – created pczekalski | en:edu:zmitac:macro:iot:project [2019/03/07 11:08] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | iot project | + | ===== IoT Tools ===== |
| + | Internet of Things laboratory project infrastructure | ||
| + | |||
| + | |||
| + | ===== MQTT Broker ===== | ||
| + | |||
| + | There are various possibilities on how to create an MQTT broker. It may be implemented as PC software (Linux, Windows-based, | ||
| + | Note, we're going to install [[https:// | ||
| + | |||
| + | We assume, your RPi installation is installed, updated and the network interface is up, connected to the local or Internet, and there is no firewall. | ||
| + | <note warning> | ||
| + | Security note: once you run mosquitto for the first time, note it is not password protected by default. It is not the serious risk, however, other than massive/ | ||
| + | </ | ||
| + | |||
| + | ==== MQTT broker on Raspberry Pi ==== | ||
| + | Installing an MQTT broker on Raspberry Pi contains some tricks regarding current Armbian OS distribution. | ||
| + | <note warning> | ||
| + | The instruction below applies to Raspian version Stretch, on Raspberry Pi 3 B. | ||
| + | The original Armbian distribution comes with outdated Mosquitto libraries. Depending on the current state of updating the distro, it may be necessary to remove any *mosquitto* repositories before continuing this instruction. | ||
| + | Please refer to the // / | ||
| + | < | ||
| + | cd / | ||
| + | ls *mosquitto* | ||
| + | </ | ||
| + | In case above code returns any source, remove it: | ||
| + | < | ||
| + | rm <here comes the name> | ||
| + | </ | ||
| + | Next follow the steps below to install Mosquitto for Stretch: | ||
| + | < | ||
| + | cd ~/ | ||
| + | wget http:// | ||
| + | sudo apt-key add mosquitto-repo.gpg.key | ||
| + | cd / | ||
| + | sudo wget http:// | ||
| + | sudo apt-get update | ||
| + | |||
| + | cd ~/ | ||
| + | wget http:// | ||
| + | sudo dpkg -i libssl1.0.0_1.0.1t-1+deb8u6_armhf.deb | ||
| + | wget http:// | ||
| + | sudo dpkg -i libwebsockets3_1.2.2-1_armhf.deb | ||
| + | sudo apt-get install mosquitto mosquitto-clients | ||
| + | </ | ||
| + | |||
| + | Once the installation is finished test, if mosquitto works: | ||
| + | < | ||
| + | mosquitto | ||
| + | </ | ||
| + | The server should start, present network configuration and also print messages on client connection (if any): | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | The Mosquitto server runs in the foreground now and its log is redirected to the console. It runs without any configuration loaded. You can connect to it anyway, for testing purposes. | ||
| + | Any MQTT client (including installed command-line ones should work). Refer to the section below on **MQTT client**. | ||
| + | |||
| + | To kill server use Ctrl+C. | ||
| + | |||
| + | === Securing MQTT communication using credentials === | ||
| + | Once Mosquitto server is in the public network, virtually anyone can connect to it as a client. This is not desired state thus it is essential to provide some security. | ||
| + | <note warning> | ||
| + | To enable credentials there is a need to configure /// | ||
| + | < | ||
| + | listener 1883 | ||
| + | persistence true | ||
| + | persistence_location / | ||
| + | persistence_file mosquitto.db | ||
| + | log_dest syslog | ||
| + | log_dest stdout | ||
| + | log_dest topic | ||
| + | log_type error | ||
| + | log_type warning | ||
| + | log_type notice | ||
| + | log_type information | ||
| + | connection_messages true | ||
| + | log_timestamp true | ||
| + | allow_anonymous false | ||
| + | password_file / | ||
| + | </ | ||
| + | |||
| + | To create a hashed password file use // | ||
| + | < | ||
| + | sudo mosquitto_passwd -c / | ||
| + | </ | ||
| + | Enter password for user **iot** twice. | ||
| + | <note warning> | ||
| + | |||
| + | === Mosquitto server autostart === | ||
| + | Now it is time to make mosquitto server start automatically on Raspbian boot. | ||
| + | Unfortunately, | ||
| + | Time to create a new service, through configuration file for Mosquitto. File is: / | ||
| + | < | ||
| + | sudo reboot | ||
| + | </ | ||
| + | and once your RPi restarts, re-connect terminal and issue: | ||
| + | < | ||
| + | netstat -l -p |grep 1883 | ||
| + | </ | ||
| + | Your RPi should answer something like this: | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | If you see the server ready and listening, do not follow this manual - it is in case your server does not start automatically on boot-up. | ||
| + | <note warning> | ||
| + | First remove old configuration (if any): | ||
| + | < | ||
| + | sudo update-rc.d mosquitto remove | ||
| + | </ | ||
| + | next, create new / | ||
| + | < | ||
| + | sudo nano / | ||
| + | </ | ||
| + | and fill it with following content: | ||
| + | < | ||
| + | [Unit] | ||
| + | Description=Mosquitto MQTT Broker daemon | ||
| + | ConditionPathExists=/ | ||
| + | Requires=network.target | ||
| + | |||
| + | [Service] | ||
| + | Type=simple | ||
| + | ExecStart=/ | ||
| + | ExecReload=/ | ||
| + | PIDFile=/ | ||
| + | Restart=on-failure | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </ | ||
| + | Note - the configuration file for Mosquitto server is located in /// | ||
| + | |||
| + | Now enable the service and reboot to test it working: | ||
| + | < | ||
| + | sudo systemctl enable mosquitto.service | ||
| + | sudo reboot | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | |||
| + | ==== MQTT client ==== | ||
| + | There are various MQTT clients. One of the most convenient yet offering full features and great GUI and also the one that does not require any installation is Java-based [[https:// | ||
| + | === Connecting to the MQTT broker === | ||
| + | Once the main screen appears, please add new connection: | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | Next provide connection details (currently your MQTT server does not need any credentials, | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | Give it some name, client ID and IP address of your RPi (if you're running on the same machine, use 127.0.0.1 - IP loopback). | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | Now click [Open connection]. MQTT-Spy may ask you to save the connection. This may fail if you run MQTT-Spy client for the first time - you need to create default configuration file first. Nevertheless you should see the following window with green coloured tab (if succesfully connected): | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | In case connection fails, first check if both (client and server) can connect on port 1883 and validate IP addresses. | ||
| + | === Subscribing and Publishing === | ||
| + | Now it is time to test MQTT messages forwarding. \\ | ||
| + | We will simulate it using one client both for publishing and subscribe.\\ | ||
| + | First, it is time to subscribe. Click New tab in the " | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | Once done, click yellow # tab to observe incoming communicates.\\ | ||
| + | Next step is to publish any topic to ... yourself (actually that sounds odd, anyway remember it is for testing purposes - in a real environment it is rare Published and Subscriber of the particular topic are the same system). To publish an MQTT message, write in the " | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | Right afterward, you should see the forwarded message through the MQTT broker to appear in the " | ||
| + | <figure label> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | ===== ESP8266 01 ===== | ||
| + | Programming (flashing) ESP8266 01 dongle. | ||
| + | |||
| + | There are 2 versions of the ESP01 (ESP-01 / ESP9266 01) dongle: 512kB and 1MB (8Mbit) | ||
| + | If you have 512kB version, do not even think about programming it - most of the firmware available is already for at least 1MB flash size.If your memory is bigger, then you need to adjust addresses where appropriate section of the flash memory starts (see Flash Memory Map, note it is not the same as Memory Map). | ||
| + | |||
| + | |||
| + | The code below shows some flashing scenarios (Ubuntu 17.10 x64, python 2.7).\\ | ||
| + | Erase contents: | ||
| + | <code sh> | ||
| + | pczekalski@s317-pc01: | ||
| + | </ | ||
| + | |||
| + | Flash original firmware (Esprif): | ||
| + | <code sh> | ||
| + | pczekalski@s317-pc01: | ||
| + | </ | ||
| + | Write firmware for router: | ||
| + | <code sh> | ||
| + | sudo ~/ | ||
| + | </ | ||
| + | |||
| + | ===== Easycam EC-230D camera ===== | ||
| + | Live stream is available at: < | ||
| + | Only Internet Explorer works. Camera requires external converter from the stream above, to the http-based one, i.e. Motion server. | ||
| + | |||
| + | Stream parameters are:\\ | ||
| + | |||
| + | <figure easycam> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Laboratory ideas ===== | ||
| + | |||
| + | ==== Network enabled power monitor ==== | ||
| + | # | ||
| + | Create a network-enabled system that monitors high voltage and current for the home system.\\ | ||
| + | Hardware is ESP32 with WiFi connection. | ||
| + | It should display it locally on the OLED display (an integrated ESP32 board) and should report it to the MQTT server.\\ | ||
| + | Configuration should enable following features: | ||
| + | * Individual identification of the devices via some identifier in the flash memory. | ||
| + | * Remote configuration via AP and via connected wireless interface: | ||
| + | * At the beginning system should expose access point. | ||
| + | * Once configured and successfully connected to the infrastructure, | ||
| + | * If device cannot connect to the infrastructure, | ||
| + | * There should be a button to reset configuration and provide clean startup | ||
| + | * Configuration should provide MQTT client config (MQTT server address, credentials if any and message string and period). | ||
| + | * Summary power consumption should be present and stored in persistent memory periodically (to be adjusted) | ||
| + | |||
| + | ==== A sensor network for the III level hall of the Faculty, mesh-based ==== | ||
| + | # | ||
| + | A sensor network (temperature / humidity DHT22) of the ESP8266-01 devices, battery operated, identifiable, | ||
| + | Note - those devices are to be battery powered thus power usage optimisation is a must! | ||
| + | |||
| + | ==== Web-enabled coffee machine ==== | ||
| + | # | ||
| + | An interface for our office coffee machine to switch it on and off remotely via relays. Level monitoring of the Coffee (possibly optical) is also very welcome. An interface should send notifications to the users, i.e. via social media. | ||
| + | |||
| + | ==== A WiFi interface to the ToLC equipment ==== | ||
| + | #teaching # | ||
| + | A module with a network interface (possibly ESP32 or WeMOS D1 R2 or WeMOS Mini D1) providing digital outputs that you can individually set or reset via a WEB interface. Web Access via infrastructure or directly via AP (configuration of the infrastructure via AP). | ||
| + | |||
| + | ==== A LoRA based logical gateway ==== | ||
| + | # | ||
| + | A solution for a gateway collecting sensor data through WiFi and forwarding it for a long distance connection over LoRA networks. | ||
| + | |||
| + | ==== A mobile station for measuring PM10 and PM2.5 levels ==== | ||
| + | # | ||
| + | Battery operated mobile device presenting dust level PM2.5 and PM10 (possibly others, sensor dependent), with networking capability. The PMS sensors are to be used in this project | ||
| + | ==== A stationery solution for measuring and reporting PM10 and PM 2.5 levels ==== | ||
| + | # | ||
| + | A sensor device for PM2.5 and PM10 (based on existing PMS sensor) with the capability to forward the measurements, | ||
en/edu/zmitac/macro/iot/project.1551953317.txt.gz · Last modified: by pczekalski
