MQTT & Raspberry Pi Managing Networked Sensors

Slides:



Advertisements
Similar presentations
MESSAGE QUEUE TELEMETRY TRANSPORT PROTOCOL(MQTT) AND IT’S REAL WORLD APPLICATIONs MRIDUL SEN COMPUTER SCIENCE DEPARTMENT OLD DOMINION UNIVERSITY.
Advertisements

Raspberry Pi Training Truman College Goals of our Training Today Unbox and boot up the Raspberry Pi (RPi) Learn how to access the desktop graphical.
DPNM Lab., POSTECH 1/25 CS490K - Internet of Things (IoT) Jonghwan Hyun DPNM Lab. Department of Computer Science and Engineering, POSTECH
Basic Router Configuration Honolulu Community College Cisco Academy Training Center Semester 2 Version 2.1.
Intro to the Arduino Topics: The Arduino Digital IO
/ IoT and RESTful Hardware What We’ve Learned from Three Years Treating Motion as REST Alden Hart - Synthetos O’Reilly Solid Conference May 21, 2014.
RC CAR CONTROLLER BASED ON INTEL GALILEO SOC PLATFORM Nadav Shiloach Sagi Sabag Supervisor: Idan Shmuel Spring 2014 One Semester Project PROJECT’S ENDING.
Ultra-low cost IoT system for smart house applications Characterization Presentation Students: Sagiv Katony Asaf Luster Advisors: Evgeny Kuksin 
Architectures and Applications for Wireless Sensor Networks ( ) Sensor Node Programming II (UART and Radio) Chaiporn Jaikaeo
05/10/20151 MQTT Contribution. 05/10/20152 What is being contributed ■ MQTT was co-invented by IBM and Arcom Systems over 13 years ago. ■ The current.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
4BP1 Electronic & Computer Engineering Paul Gildea th Year Interim Project Presentation.
Introduction :  In the beginning, the calculator is the basic idea of computers out, then that arrived at the large computers.  in1980 or late seventies.
Connected Hardware for Software Engineers 101 Pance Cavkovski, Netcetera.
IoT: Windows 10 & Raspberry Pi By: Mitchel Sellers.
Raspberry Pi Project Control Your Home Lights with a Raspberry Pi.
I I R R T T Internet Real Time Lab SECE SYSTEM SECE SERVER INTERNET ELECTRICAL APPLIANCES CONNECTED TO MICROCONTROLLER … … : register & download.
Jeremy Sandoval University of Washington May 14, 2013
2007/11/16 Dinh Trong Thuy RTLab
Engineering Innovation Center
Grado en Ingeniería de Tecnologías y Servicios de Telecomunicación
Workshop on Raspberry Pi 3
Computer System Laboratory
Internet of Things.
James Robertson 17th April 2014 #Scotrug
More on WANs Fiber Optic Cables Used in Internet backbone
Student: Taariq Ghansar Supervisor: Prof Bagula
IoT 101 with Raspberry Pi and Azure
AT Commands Supports AT commands
Computer System Laboratory
IoT with Arduino and Raspberry Pi
DHT 11 Sensor Connect the sensor with Arduino board like picture below. Download DHT11 Sensor library from
Chapter A - The Raspberry Pi Computer
Building a conference attendee tracking system using DNN and MQTT
CIT 384: Network Administration
MQTT – Accessing MQ from anywhere
UTA010 : Engineering Design – II
IzoT™ Device Stacks March 2014.
Haiwell PLC Modules Introduce
A microcontroller Raspberry Pi 2 Model B V1.1 RPi
Computer System Laboratory
DT80 range Modbus capability
RASPBERRY PI WORKSHOP.
Arduino Part 1 Topics: Microcontrollers Programming Basics
Programming with Arduinos and Rapsberry Pi
connectivity | autonomous | electrification | architecture
connectivity | autonomous | electrification | architecture
Arduino and Grove LET’S START.
The Internet of Things (IoT)
Internet-of-Things (IoT)
Sensor platforms for smart university project
Intro to the Arduino Topics: The Arduino Digital IO
AT91RM9200 Boot strategies This training module describes the boot strategies on the AT91RM9200 including the internal Boot ROM and the U-Boot program.
Embedded Software Development with Python and the Raspberry Pi
Building an Internet of Things Device
Bc. Adam Földvári, Bc. Robert Čížek
Internet-of-Things (IoT)
Enter the World of Industry 4.0 with UniStream MQTT
Purdue University Fort Wayne
DOMOTICA MAY MONTH Sander Claassen John Heesterbeek Ad van Berlo
Purdue University Fort Wayne
Message Queuing Telemetry Transport (Internet of Things)
Implementation of Embedded OS
Workshop GPIO I2C SPI Panic1 woensdag 10 april 2019.
Beginning Raspberry Pi
Arduino and Grove LET’S START.
Introduction to arduino
Chapter 7 IoT Physical Devices and Endpoints
Setting up a Webcam on a Raspberry Pi
Robot and Crickit HAT © Copyright 2019 by Dr. Elizabeth I. Horvath and Dr. Eva A. Horvath 1.
Presentation transcript:

MQTT & Raspberry Pi Managing Networked Sensors while Dealing with Jargon and (if all goes well) a net-connected cowbell Stewart Russell — @scruss 2017-12-14

“Back in the old days …” Coal Clough Wind Farm - Photo by James Bird, 2009 - CC-BY-ND

MQTT Stands for MQ Telemetry Transport Only faintly related to IBM’s MQ message queue product Allows sensors to talk over TCP/IP As standard as we’re likely to see: ISO/IEC 20922:2016 OASIS standard, 2015 Widely (but quietly) used Extraordinarily jargon-heavy

MQTT Basic Jargon https://micropython-iot-hackathon.readthedocs.io/

MQTT Topic Hierarchy Topics have levels: home/basement/temperature home/basement/humidity home/kitchen/temperature … Wildcard + matches one level: home/+/temperature → home/basement/temperature → home/kitchen/temperature Wildcard # matches all levels: home/#

MQTT: “they thought of that” Quality of Service: each message can be sent At most once: typical for most IoT sensors At least once: may be sent multiple times — important alarms Exactly once: receipt is verified — valuable transactions Last Will A client can register a “will” with the broker should it exit unexpectedly The broker publishes the will as a message for other clients to act upon

Installing a broker Eclipse Mosquitto™ — https://mosquitto.org/ doesn’t seem to require any configuration small and quite well-behaved default port 1883 Raspbian installation: sudo apt install mosquitto mosquitto-clients

MQTT “Hello, World!” On the broker host: mosquitto_sub --topic 'hello/#' On another (or same host): mosquitto_pub [ --host broker_host ] --topic 'hello/world' --message "Hello, World!" Displayed on the broker host: Hello, World!

ESP8266 Wireless sensor board 80 – 160 MHz 32-bit core Multiple digital I/O ports One (slightly weedy) 0 – 1 V ADC Can be very cheap: < $5 / unit Sold under many names: NodeMCU, Huzzah, ESP8266 Thing, WiPy (v1.0) Can be programmed in Lua, Arduino, MicroPython, … By Sparkfun Electronics - https://c1.staticflickr.com/1/494/19681470919_9a9bcd5692_z.jpg, CC BY 2.0, https://commons.wikimedia.org/w/index.php?curid=57331438

MicroPython Real Python 3 — only smaller! Runs on many µc boards from ARM Cortex-M0 up Small memory footprint: can run in under 64 KB RAM Actively targets ESP8266 Many libraries for supporting different sensors/protocols Downside: can’t exactly be called fast … https://micropython.org/

Installing MicroPython Download binary image from https://micropython.org/ Install over USB serial using esptool.py: sudo pip install esptool Provides MicroPython REPL over USB serial at 115200 bps (Optionally) provides MicroPython REPL over WebSockets terminal to browser (configuration required)

ampy, a serial helper Install via pip install adafruit-ampy Uploads and downloads program and data files Manages file folders on your ESP8266 Runs MicroPython scripts with output to the terminal Examples: ampy -p /dev/ttyUSB2 get boot.py > boot.py ampy -p /dev/ttyUSB2 put main-esp8266-MQTT-DHT22-pin4.py /main.py

MicroPython User Interface Typically through two scripts: boot.py — board and network setup main.py — user program

boot.py def do_connect(): import network sta_if = network.WLAN(network.STA_IF) ap_if = network.WLAN(network.AP_IF) if ap_if.active(): ap_if.active(False) print("AP turned off ...") if not sta_if.isconnected(): print('connecting to network...') sta_if.active(True) sta_if.connect('SSID', 'PASSWORD') while not sta_if.isconnected(): pass print('network config:', sta_if.ifconfig()) print("Starting network ...") do_connect()

Sensor Setup DHT22: Cheap temperature (°C) and relative humidity sensor (%) Simple one-wire digital protocol Results to 1 decimal place Max 1 reading / 2 s Can be cranky and decides not to give you a reading sometimes (in MicroPython, at least)

main.py: 1 of 2 import machine import dht import time from umqtt.simple import MQTTClient broker_ip = '192.168.2.109' # broker address client_id = 'wemos024155' print('broker: ', broker_ip) print('client_id: ', client_id) client = MQTTClient(client_id, broker_ip) d = dht.DHT22(machine.Pin(4))

main.py: 2 of 2 while True: time.sleep(5) retry = 0 # retry reading if DHT22 stubborn while retry < 3: try: d.measure() break except: retry = retry + 1 if retry < 3: print(("%6.1f deg C / %6.1f %% RH") % (d.temperature(), d.humidity())) client.connect() client.publish(client_id + '/temperature', str(d.temperature())) client.publish(client_id + '/humidity', str(d.humidity())) client.disconnect()

Local Results! Starting network ... connecting to network... network config: ('192.168.2.72', '255.255.255.0', '192.168.2.1', '192.168.2.1') broker: 192.168.2.109 client_id: wemos024155 20.1 deg C / 30.7 % RH 20.2 deg C / 31.2 % RH 20.1 deg C / 31.3 % RH …

Network Results! $ mosquitto_sub -h 192.168.2.109 -v --topic 'wemos024155/+' wemos024155/temperature 20.6 wemos024155/humidity 30.4 wemos024155/humidity 30.3 wemos024155/humidity 30.3 …

Overnight Results From mqtt-spy https://kamilfb.github.io/mqtt-spy/

Consuming and Creating In Python, Eclipse Paho MQTT Python client library: sudo pip install paho-mqtt This next demo was created using paho-mqtt for Python 3 GPIO Zero https://gpiozero.readthedocs.io MicroPython

🐮🔔

But seriously … BlueLine PowerCost Monitor Clips to Smart Meter and gives power readings every 30 s Given away free by the power authority Talks over 433 MHz RF Doesn’t connect to your network ☹ → just as well we reverse-engineered the protocol! ☺ → stable Arduino implementation over serial Almost the perfect application for a small MQTT device