Communicating with Internet of Things

by Peter Martin / @pe7er

WordCamp NL 2016, Sunday 16th October 2016

About me

Peter Martin (@pe7er)
Nijmegen, NL

Organizes:
* Linux Usergroup Nijmegen
* Open Coffee Nijmegen

www.db8.nl
Joomla support, application development


Joomla volunteer:
* Global Forum Moderator
* Joomla Bug Squad
* Pizza Bugs & Fun (in NL)

* Former Joomla Community
   Leadership Team (6 yr)
* Mentor GSoC 2016

Overview Presentation

  • Internet of Things (IoT)
  • My 2 IoT “projects”
  • MQTT
  • Demo




Questions preferably after the demo

Presentation: http://slides.db8.nl
IoT code: https://github.com/pe7er/db8iot

1. Internet of Things (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!

We all know what happened in the movie “The Terminator”

Application to boost IoT?

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
- low-cost: $ 1.42 at eBay.com
- full TCP/IP stack
- connects to a Wi-Fi router

Communication:
Hayes-style "AT" (modem)

Chinese documentation

Pins of ESP8266-01

GPIO: General-purpose
input/output

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

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

ESP8266

No need for Arduino microcontroller
programme & flash chip on ESP!

- Software Development Kit (SDK)
- esp-open-sdk (GCC toolchain)
- NodeMCU + LUA scripts

- Arduino IDE + ESP8266WiFi library !

2. My IOT “project” 1 (of 2)

ESP8266 pins too close for gutter

Bridging the gutter

USB to TTL Serial interface

Flashing the ESP8266

Temperature sensor

Connect to ThingSpeak.com (RESTFull)

2. My IOT “project” 2 (of 2)

My co-working place
Hubbels.net, Nijmegen

Last year, me with longer hair, working

Remko, my co-working colleague...

...had Lunch

No lunch for me!

Who is there?

Website with application?
    arrive? -> log in
    leave? -> log out

-> additional actions
therefore unreliable

What is the first thing
you do at work?


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

connect your
laptop and/or
mobile
to Wi-Fi (LAN)

A Raspberry Pi for everything

Raspberry Pi


connected to LAN

bash script
    collects MAC addresses
    of all devices in LAN

    sends them to my
    external webservice

Webservice


October 28th 2015
REST API in WordPress 4.4

August 2015
me playing with RPi


and Joomla 3.4.3
No REST API for me (yet)...

Webservice


SLIM Framework
external PHP script; RESTFull
    connects to my
    Joomla's database;

    gets & stores
    MAC addresses

External Joomla Website


Custom application
manages
    colleagues +
    MAC addresses

shows
    who is there...

Easier access


Mobile App (Android)
    connects to
    webservice

    displays colleagues
    and their presence

MY IOT “projects”


all 1-to-1 communication

all RESTFull
(need Webserver; can be heavy)

And Now For Something Completely Different...

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

- messaging protocol
- publish/subscribe

- simple + lightweight
- layer on TCP/IP


(IBM) “MQ Telemetry Transport”
Official standard: ISO/IEC PRF 20922

“WhatsApp for machines”


WhatsApp Server = MQTT Broker

WhatsApp Group = Topic

Member of Group = Subscriber

Post in Group = Publish to Topic

Topics

Topic name: hierarchically structured with forward slashes

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

MQTT Communication

MQTT Client & Broker

basic messages

Client Broker

CONNECT

SUBSCRIBE / UNSUBSCRIBE
(Topic Name)

PUBLISH
(Topic Name + Payload + QoS)

CONNACK
(= CONNect ACKnowledge)
SUBACK / UNSUBACK
(SUBscribe ACKnowledge)

PUBACK
(PUBlish ACKnowledge) (if QoS = 1 or 2)

Quality of Service (QoS)


QoS 0
No-feedback needed

QoS 1
Acknowledge receipt

QoS 2
Just Once

MQTT Security

Authentication

Access to MQTT Broker

- Username + Password

- X509 Client Certificate
(Public/Private Keys)

- OAuth 2.0

Authorization

Control MQTT resources

- Allowed topics

- Allowed operation
(publish and/or subscribe)

- Allowed QoS

Secure communication

Secure communication
between client & broker

- Secure connection
   Transport Layer Security (TLS)
    MQTT over SSL / TLS (using Let’s Encrypt)


- Secure message
   MQTT Payload Encryption

Installing MQTT

MQTT Broker SaaS

ThingSpeak.com

io.adafruit.com

CloudMQTT.com

List of
publically-accessible
MQTT brokers

(for testing and prototyping)


MQTT Broker Linux


Mosquitto



Install Mosquitto broker on Debian / Ubuntu

$ sudo apt-get install mosquitto


MQTT Client PC

MQTT.fx (written in Java)
Platforms: Windows, Apple OSX, Linux Debian/Red Hat, Unix


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

MQTT Client Mobile Apps


MyMQTT
MQTT Client
MQTT Dashboard


MQTT Tester
ICPDAS MQTT
MQTTInspector


M2Mqtt

MQTT Client Arduino / ESP8266

Arduino IDE editor v1.6.9
     -> to flash ESP board install:
          Tools > Boards > Board Manager:
          esp8266 v2.2.0

     -> to use MQTT + esp8266 in C++ code:
          add PubSubClient + ESP8266WiFi libraries in IDE

          add in C++ code:

// include MQTT library
#include <PubSubClient.h>
// include ESP8266
#include <ESP8266WiFi.h>

MQTT Client scripts

Python: Mosquitto module

Arduino: PubSubClient

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

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



4. Demo time

Sorry,

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


There might be published a
WordCamp Netherlands 2016 video soon.

Or check out the video from the
European Joomla conference JandBeyond 2016.

Thank you!


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