Communicating with Internet of Things

by Peter Martin / @pe7er

About me

Peter Martin, Nijmegen, NL
db8.nl - Joomla support, application development

db8 Site Dev - free checklist component for devs

Joomla volunteer:
* Global Forum Moderator
* Joomla Bug Squad
* co-organizing PBFs in NL
* former Joomla CLT
* Mentor GSoC 2016

Likes:
* Music (vinyl records)
* Movies
* Electronics
* Raspberry Pi
* Internet of Things

Organizes:
* Linux Usergroup Nijmegen
* Open Coffee Nijmegen

www.db8.nl
twitter: @pe7er

Overview Presentation

  • Internet of Things (IoT)
  • My 2 IoT "projects"
  • MQTT
  • Communication
  • Security
  • Installation
  • Demo

1. Internet of Things (IoT)

“Internet of Things is a global infrastructure for the information society, enabling advanced services by interconnecting (physical and virtual) things based on existing and evolving interoperable information and communication technologies.”
International Telecommunication Union (ITU), June 2012
“The Internet of Things (IoT) is the network of physical objects—devices, vehicles, buildings and other items—embedded with electronics, software, sensors, and network connectivity that enables these objects to collect and exchange data”
Wikipedia.org on IoT
“The Internet of Things (IoT) is
a network of devices that are connected to each other using TCP/IP
and communicate autonomously.
#IoT #JaB16
@pe7er (in exactly 140 characters)

Be Careful!

Communication IoT devices

Input
Text Messages

Sensors
   - temperature
   - movement
   - sound
   - light
   - touch / push button
   - pressure
   - etc

Output
Text Messages

Signals
    - light (LED)
    - switch (Relay)
    - sound
    - screen

Samsung Family Hub Refrigerator
5,999.99 USD

Smarter FridgeCam
99.99 GBP

Self-ordering Fridge:
not for me!

Arduino

Microcontroller

ESP8266

Wifi chip

Add Wifi to Arduino

ESP8266

Out-of-the-box
low-cost WiFi chip: $5
full TCP/IP stack
connect to a Wi-Fi network
Hayes-style "AT" commands

No need for microcontroller
it has its own, programmable:
- Software Development Kit (SDK)
- esp-open-sdk (GCC toolchain)
- NodeMCU + LUA scripts
- Arduino IDE + ESP8266WiFi library

ESP8266 Versions

Pins of ESP8266-01

Ready to flash the ESP8266

2. My IOT v1

PCB Prototype Board

Breadboard Prototype Board

Building a circuit with Breadboard

ESP8266 pins too close for gutter

Bridging the gutter

Tinkering with PCB, wire,
IC socket, DS18B20 Transistor

ESP8266 on PCB Prototype Board

Flashing the ESP8266

Temperature sensor

Connect to ThingSpeak.com (RESTFull)

2. My IOT v2

The Sandwich

My co-working place

Last year, me with longer hair, working

Remko, my co-working colleague

No lunch for me

A Raspberry Pi for everything

What is the first thing
you do at work?


besides taking off your jacket
besides switching on the lights
besides making a cup of coffee

connect laptop / mobile:
to Wi-Fi (LAN)

Raspberry Pi


connected to LAN

collects MAC addresses
of all devices in the LAN

sends them to my
external webservice

Webservice


SLIM Framework
external PHP script; RESTFull

connected to Joomla + its database (See github:
Pierre-André Vullioud)

Joomla


External Joomla Website
custom "com_members"
component to manage members + MAC addresses

database shared with MAC data of webservice

Easier access


Mobile (Android) App
connects to webservice

displays co-working colleagues
and their presence

MY IOT = Nice, but

all 1-to-1 communication
all RESTFull
(need Webserver; can be heavy)


And Now For Something Completely Different...

person-to-device

device-to-device

devices-to-devices

Some Message Protocols

6LoWPAN (IPv6 over Low power Wireless Personal Area Networks). DASH7 active RFID. MyriaNed wireless sensor network (WSN) platform. Z-Wave wireless communications protocol for home automation. ZigBee for personal area networks with small, low-power digital radios. Low-Power Wide-Area Network (LPWAN). Thread protocol for household devices to communicate on a network. Matrix open protocol for real-time communication. Constrained Application Protocol (CoAP) used for very simple electronics devices. AMQP (Advanced Message Queuing Protocol). STOMP (Simple (or Streaming) Text Oriented Message Protocol). MQTT (MQ Telemetry Transport).

3. MQTT

MQTT

http://mqtt.org/

  • “MQ Telemetry Transport”
    (IBM's MQ - message queuing)
  • simple and lightweight messaging protocol
  • layer on TCP/IP
  • ISO Standard
    ISO/IEC PRF 20922
  • publish/subscribe pattern

Server: (MQTT Broker)
Clients: Publisher + Subscribers

Topics

Topic name: hierarchically structured with forward slashes

minimal 1 character
Case Sensitive

Examples of topics





myhouse/groundfloor/kitchen/temperature
myhouse/groundfloor/livingroom/brightness
myhouse/groundfloor/livingroom/temperature
myhouse/firstfloor/bathroom/temperature


Wildcards in topics


Single level: +
myhouse/groundfloor/+/temperature

myhouse/groundfloor/kitchen/temperature
myhouse/groundfloor/livingroom/brightness
myhouse/groundfloor/livingroom/temperature
myhouse/firstfloor/bathroom/temperature

Wildcards in topics


Multi level: #
myhouse/groundfloor/#

myhouse/groundfloor/kitchen/temperature
myhouse/groundfloor/livingroom/brightness
myhouse/groundfloor/livingroom/temperature
myhouse/firstfloor/bathroom/temperature

4. MQTT Communication

MQTT Client & Broker

basic messages

Client Broker

CONNECT

SUBSCRIBE
(Topic Name)
PUBLISH
(Topic Name + Payload + QoS)
UNSUBSCRIBE
(Topic Name)

CONNACK
(= CONNect ACKnowledge)
SUBACK
(SUBscribe ACKnowledge)
PUBACK
(PUBlish ACKnowledge) (if QoS = 1 or 2)
UNSUBACK
(UNSUBscribe ACKnowledge)

Quality of Service (QoS)

3 levels: 0, 1, 2

QoS 0 - No-feedback needed

Client sends PUBLISH message to the broker:
Topic Name, Payload,
Packet Identifier, QoS 0



Broker sends that message to subscribers
but does not acknowledge receipt

QoS 1 - Acknowledge receipt

Client sends PUBLISH message to the broker:
Topic Name, Payload,
Packet Identifier, QoS 1

and stores message until ACK (PUBACK) broker.

Broker sends that message to subscribers
and responds PUBACK message:
Packet Identifier

QoS 2 - Just Once (1/2)

Client sends PUBLISH message to the broker:
Topic Name, Payload,
Packet Identifier, QoS 2

and stores message until ACK (PUBACK) broker.

Broker sends that message to subscribers
and responds PUBREC (Publish Received):
Packet Identifier

QoS 2 - Just Once (2/2)

Client stores PUBREC message and answers to broker with PUBREL (Publish Release):
Packet Identifier

Broker receives PUBREL, ignores future same ID messages, answers PUBCOMP (Publish Complete):
Packet Identifier

5. MQTT Security

Authentication

Access to MQTT Broker

- Username + Password

- X509 Client Certificate
(Public/Private Keys)

- OAuth 2.0

Authorization

Access to certain resources

- Allowed topics

- Allowed operation
(publish and/or subscribe)

- Allowed QoS

Secure communication

Secure communication between client & broker

- Transport Layer Security (TLS)
   - MQTT over SSL / TLS
   - Using Let’s Encrypt

- MQTT Payload Encryption

6. Installation

MQTT Broker
SaaS

ThingSpeak.com

io.adafruit.com

CloudMQTT.com

List of
publically-accessible
MQTT brokers

(for testing and prototyping)

MQTT Broker + Client
Linux

Mosquitto

Install Mosquitto broker + client on Linux

$ sudo apt-get install mosquitto mosquitto-clients

Publish message to channel “test/msg”

$ mosquitto_pub -d -t test/msg -m "Hello Joomladay!"

Subscribe & receive all messages from channel “test/msg”

$ mosquitto_sub -t test/msg

MQTT Client
Arduino / ESP8266

  • Arduino IDE v1.6.9

  • Install ESP board in Arduino
    Tools > Boards > Board Manager: esp8266 v2.2.0

  • Include libraries in your C++ code
// include MQTT library
#include <PubSubClient.h>
// include ESP8266
#include <ESP8266WiFi.h>

MQTT Broker

Onion Omega


Installation on OpenWRT

$ opkg update
$ opkg install mosquitto| mosquitto-client

Publish message to channel “test/msg”

$ mosquitto_pub -m 'Hello JandBeyond!' -t test

Subscribe & receive all messages from channel “test”

$ mosquitto_sub -v -t test

MQTT Client

MQTT.fx (written in Java)


Download

$ wget http://www.jensd.de/apps/mqttfx/1.1.0/mqttfx-1.1.0-64bit.deb

Installation

$ sudo dpkg -i mqttfx-1.1.0-64bit.deb

Android - MQTT Clients


MyMQTT


MQTT Client


MQTT Dashboard

Various

python: Mosquitto Python module

arduino: PubSubClient - Arduino Client for MQTT


php:
bluerhinos/phpMQTT Simple PHP class to connect/publish/subscribe to an MQTT broker

McFizh/libMQTT Simple MQTT library for PHP with support for MQTT version 3.1.1, TLS.

7. Demo

Sorry...

I do not have sheets for the demo...
You had to be there!


ok, there might become a video available soon.
Or check out the video of the European Joomla conference JandBeyond cd www2016 at Youtube

Questions?


Presentation:
http://slides.db8.nl

IoT code:
https://github.com/pe7er/db8iot


Peter Martin
e-mail: info at db8.nl
twitter: @pe7er
presentation: https://db8.nl

Photo Credits 1/3

Photo Credits 2/3

Photo Credits 3/3