Začíname už za

Connecting Things

Created by Miroslav Biňas / mirek

![IoT Architecture Overview](images/iot.architecture-overview.png) notes: * https://www.avsystem.com/blog/what-is-iot-architecture/
## M2M (Machine-to-Machinie)
> M2M is a broad label that can be used to describe any technology that enables networked devices to exchange information and perform actions without the manual assistance of humans. > -- ([IoT Agenda](https://internetofthingsagenda.techtarget.com/definition/machine-to-machine-M2M))
## M2M ≠ IoT
![Difference between M2M and IoT](https://www.avsystem.com/media/iot_vs_m2m_graphics-02.png) notes: * https://www.avsystem.com/blog/iot-and-m2m-what-is-the-difference/
![The Impact of Connectivity Technologies on the Power Consumption](images/the.impact.of.connectivity.technologies.on.the.power.consumption.png) Notes: * https://www.saftbatteries.com/energizing-iot/impact-communication-technology-protocol-your-iot-application%E2%80%99s-power-consumption
![Distance of Communication Technologies](images/distance.of.communication.technologies.jpg)
![Communication Range Simplified](images/communication.range.png)
![Communicaton Protocols in ISO/OSI Model](images/iot.protocols.in.osi.iso.model.png) Notes: * http://selvarajkesavan.blogspot.com/2019/01/iot-device-communication-protocols-it.html
![ESP32](images/esp32.png)
![ESP32 Block Diagram](images/esp32.block.diagram.svg) * notes: * https://en.wikipedia.org/wiki/ESP32
## WiFi Support * _802.11 b/g/n_ * IEEE 802.11 standard security features all supported, including WFA, WPA/WPA2 and WAPI * can operate as an _Access Point_ notes: * https://en.wikipedia.org/wiki/ESP32
## The `network` Module
[![IFTTT](images/ifttt.png)](https://ifttt.com)
![IFTTT Recipe](images/ifttt-recipe.png)] notes: * https://medium.com/@imatrof/11-top-ifttt-recipes-to-increase-your-productivity-eed473789abd
## What is MQTT? * [MQTT](https://en.wikipedia.org/wiki/MQTT) (Message Queue Telemetry Transport) * lightweight publish-subscribe protocol that is used on top of TCP/IP * designed to _M2M_ communications * uses _publisher/subscriber pattern_ and _MQ model_ * becoming one of the main protocols for _IoT_ Notes: * https://pagefault.blog/2017/03/02/using-local-mqtt-broker-for-cloud-and-interprocess-communication/ * https://www.youtube.com/watch?v=eS4nx6tLSLs * http://www.steves-internet-guide.com/mqtt/
![Publish-subscribe Architecture](images/publish-subscribe.architecture.png) Notes: * https://blog.securitycompass.com/publish-subscribe-threat-modeling-11add54f1d07
## The Basics * broker * topics * publisher * subscriber * message

IoT Example

MQTT Overview
[![Mosquitto](images/logo-mosquitto.png)](https://mosquitto.org/)
## [Eclipse Mosquitto™](https://mosquitto.org/) * an open source lightweight MQTT broker * implements the MQTT protocol versions 3.1 and 3.1.1 * install with `sudo apt install mosquitto` `sudo apt install mosquitto-clients`
## `mosquitto_pub` * client for publishing simple messages * syntax: `mosquitto_pub -h host -t topic -m message` Notes: * man mosquitto_pub
## `mosquitto_sub` * client for subscribing to topics * syntax: `mosquitto_sub -h host -t topic [-F format]` * example: `mosquitto_sub -h localhost -t '#' -F "%t: %p"` Notes: * man mosquitto_sub
## Topics * string used by broker to filter messages * consist of one/more topic levels * topic level separator is '`/`' * topics don't need to be initialized first * cAsE sEnsItIvE * allows to use wildcards when subscribing: * '`#`' - multi level * '`+'` - single level Notes: * https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices
Slovensko/Košice/Letná 9/IoT Lab
home/ground/livingroom/temperature
## MQTT and ESP32 * package `umqtt`
## [IBM Watson IoT](https://quickstart.internetofthings.ibmcloud.com/#/)
## Get Ready for Watson * no direct support for _Watson_ * install appropriate package with `upip` * _MicroPython_ version of `pip` * packages for _MicroPython_ have prefix `micropython-` * install `micropython-watson-iot` package: ```python import upip upip.install('micropython-watson-iot') ```
## ESP32 with Watson ```python from watson_iot import Device device = Device(device_id='esp32-dht22', device_type='my-device-type', token='my-device-token') device.connect() device.publishEvent('temperature', {'degrees': 30.7, 'unit': 'C'} ) ```
## The Final Code ```python # imports ... sensor = DHT11(Pin(23)) device = Device(device_id='esp32-with-dht22', device_type='type', token='token') device.connect() while True: sensor.measure() temp = sensor.temperature() device.publishEvent('temperature', {'degrees': temp, 'unit': 'C'}) sleep(10) ```
## Questions?