SlideShare a Scribd company logo
Martin Christen
FHNW – University of Applied Sciences and Arts Northwestern Switzerland
School of Architecture, Civil Engineering and Geomatics
Institute of Geomatics Engineering
martin.christen@fhnw.ch
@MartinChristen
Getting Started with IoT using a Raspberry Pi and Python
Quelle: http://cloudtimes.org/2013/09/09/introducing-web-3-0-internet-of-things/Quelle: https://www.hifiberry.com/2016/02/the-new-raspberry-pi-3-is-out/
10 April 2016Insitute of Geomatics Engineering 2
Quelle: https://www.ncta.com/platform/industry-news/infographic-the-growth-of-the-internet-of-things/
10 April 2016Insitute of Geomatics Engineering 3
MQTT (Message Queuing Telemetry Transport)
MQTT provides a lightweight method of carrying out messaging using a
publish/subscribe model. This makes it suitable for “machine to machine”
messaging such as with low power sensors or mobile devices such as phones or
the Raspberry Pi.
MQTT dates back to 1999.
MQTT is:
Open (ISO/IEC PRF 20922)
Lightweight (2 bytes header)
Reliable (QoS/patterns to avoid packet loss)
Simple (TCP based, async, publish/subscribe, payload agnostic)
10 April 2016Insitute of Geomatics Engineering 4
How MQTT works
Quelle: https://zoetrope.io/tech-blog/brief-practical-introduction-mqtt-protocol-and-its-application-iot
10 April 2016Insitute of Geomatics Engineering 5
XMPP Implementation: Eclipse Mosquitto
• Lightweight server implementation of MQTT written in C
• About 3 MB RAM with 1000 clients connected…
• http://eclipse.org/mosquitto
• Client support for Python 2.x and Python 3.x
10 April 2016Insitute of Geomatics Engineering 6
Dockerfile
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install wget build-essential libwrap0-dev libssl-dev -y
RUN apt-get install python-distutils-extra libc-ares-dev uuid-dev -y
RUN mkdir -p /usr/local/src
WORKDIR /usr/local/src
RUN wget http://mosquitto.org/files/source/mosquitto-1.4.8.tar.gz
RUN tar xvzf ./mosquitto-1.4.8.tar.gz
WORKDIR /usr/local/src/mosquitto-1.4.8
RUN make
RUN make install
RUN adduser --system --disabled-password --disabled-login mosquitto
USER mosquitto
EXPOSE 1883
CMD ["/usr/local/sbin/mosquitto"]
based on: https://hub.docker.com/r/ansi/mosquitto/~/dockerfile
docker build -t test-mosquitto .
docker run -p 1883:1883 test-mosquitto
10 April 2016Insitute of Geomatics Engineering 7
Python Client
pip3 install paho-mqtt
Documentation: https://pypi.python.org/pypi/paho-mqtt/
Source: https://github.com/eclipse/paho.mqtt.python
10 April 2016Insitute of Geomatics Engineering 8
MQTT: Subscribe
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("SensorXY/#")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
host = "192.168.99.100"
print("Connecting to " + host)
client.connect(host, port=1883, keepalive=60)
client.loop_forever()
10 April 2016Insitute of Geomatics Engineering 9
MQTT: Publish
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# The callback for when a PUBLISH message is received from the server.
# unused for this demo
def on_publish(client, userdata, mid):
pass
client = mqtt.Client()
client.on_connect = on_connect
client.on_publish = on_publish
host = "192.168.99.100"
client.connect(host, port=1883, keepalive=60)
client.loop_start()
topic = "SensorXY"
s = ""
while s != "exit":
s = input("payload >")
client.publish(topic, s)
client.loop_stop()
10 April 2016Insitute of Geomatics Engineering 10
Simple example: Remote-control a light from anywhere in the world
In the first example we turn on/off a LED using MQTT. The LED is connected on
GPIO Pin 11 (GPIO 17)
https://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm
10 April 2016Insitute of Geomatics Engineering 11
How it works:
Raspberri Pi
MQTT
Broker
Subscribe and wait for command
«light on» or «light off»
Controller
Interface
Send command «light on», «light off», or «get status»
DB
save state
(optional)
10 April 2016Insitute of Geomatics Engineering 12
Raspberry Pi Client
import RPi.GPIO as GPIO
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("Raspberry/#")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
s = str(msg.payload, encoding="ascii")
print("retrieved message: " + s)
if s == "lighton":
GPIO.output(LedPin, GPIO.LOW)
elif s == "lightoff":
GPIO.output(LedPin, GPIO.HIGH)
# Initialize GPIO
LedPin = 11 # pin GPIO 17, change if you connect to other pin!
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LedPin, GPIO.OUT)
GPIO.output(LedPin, GPIO.HIGH) # turn off led
# Initialize MQTT
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
host = "192.168.99.100"
print("Connecting to " + host)
client.connect(host, port=1883, keepalive=60)
client.loop_forever()
sudo pip3 install paho-mqtt
10 April 2016Insitute of Geomatics Engineering 13
Control Raspberry Pi
import paho.mqtt.client as mqtt
client = mqtt.Client()
host = "192.168.99.100"
client.connect(host, port=1883,
keepalive=60)
client.loop_start()
topic = "Raspberry"
print("COMMANDS:")
print("0: turn light off")
print("1: turn light on")
print("3: quit application")
s=0
while s!=3:
s = int(input("command >"))
if s == 0:
client.publish(topic, "lightoff")
elif s == 1:
client.publish(topic, "lighton")
elif s == 3:
print("bye")
else:
print("unknown command")
client.loop_stop()
10 April 2016Insitute of Geomatics Engineering 14
Questions ?

More Related Content

What's hot (11)

Windows 10 IoT Core, a real sample
Windows 10 IoT Core, a real sampleWindows 10 IoT Core, a real sample
Windows 10 IoT Core, a real sample
Mirco Vanini
 
Iotivity atmel-20150328rzr
Iotivity atmel-20150328rzrIotivity atmel-20150328rzr
Iotivity atmel-20150328rzr
Phil www.rzr.online.fr
 
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT CoreHands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Andri Yadi
 
IoTivity: From Devices to the Cloud
IoTivity: From Devices to the CloudIoTivity: From Devices to the Cloud
IoTivity: From Devices to the Cloud
Samsung Open Source Group
 
FOSDEM 2017: Making Your Own Open Source Raspberry Pi HAT
FOSDEM 2017: Making Your Own Open Source Raspberry Pi HATFOSDEM 2017: Making Your Own Open Source Raspberry Pi HAT
FOSDEM 2017: Making Your Own Open Source Raspberry Pi HAT
Leon Anavi
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
Vijay Vishwakarma
 
Create IoT with Open Source Hardware, Tizen and HTML5
Create IoT with Open Source Hardware, Tizen and HTML5Create IoT with Open Source Hardware, Tizen and HTML5
Create IoT with Open Source Hardware, Tizen and HTML5
Leon Anavi
 
Ipdtl
IpdtlIpdtl
Ipdtl
ssuser1eca7d
 
TinyOS 2.1 Tutorial: TOSSIM
TinyOS 2.1 Tutorial: TOSSIMTinyOS 2.1 Tutorial: TOSSIM
TinyOS 2.1 Tutorial: TOSSIM
Razvan Musaloiu-E.
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experience
Alexandre Abadie
 
IoTivity: Smart Home to Automotive and Beyond
IoTivity: Smart Home to Automotive and BeyondIoTivity: Smart Home to Automotive and Beyond
IoTivity: Smart Home to Automotive and Beyond
Samsung Open Source Group
 
Windows 10 IoT Core, a real sample
Windows 10 IoT Core, a real sampleWindows 10 IoT Core, a real sample
Windows 10 IoT Core, a real sample
Mirco Vanini
 
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT CoreHands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Andri Yadi
 
FOSDEM 2017: Making Your Own Open Source Raspberry Pi HAT
FOSDEM 2017: Making Your Own Open Source Raspberry Pi HATFOSDEM 2017: Making Your Own Open Source Raspberry Pi HAT
FOSDEM 2017: Making Your Own Open Source Raspberry Pi HAT
Leon Anavi
 
Create IoT with Open Source Hardware, Tizen and HTML5
Create IoT with Open Source Hardware, Tizen and HTML5Create IoT with Open Source Hardware, Tizen and HTML5
Create IoT with Open Source Hardware, Tizen and HTML5
Leon Anavi
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experience
Alexandre Abadie
 
IoTivity: Smart Home to Automotive and Beyond
IoTivity: Smart Home to Automotive and BeyondIoTivity: Smart Home to Automotive and Beyond
IoTivity: Smart Home to Automotive and Beyond
Samsung Open Source Group
 

Viewers also liked (20)

Python and the internet of things
Python and the internet of thingsPython and the internet of things
Python and the internet of things
Adam Englander
 
Ashley Madison - Lessons Learned
Ashley Madison - Lessons LearnedAshley Madison - Lessons Learned
Ashley Madison - Lessons Learned
Adam Englander
 
Docker for Python Development
Docker for Python DevelopmentDocker for Python Development
Docker for Python Development
Martin Christen
 
Presentation final 72
Presentation final 72Presentation final 72
Presentation final 72
Martin Christen
 
Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...
Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...
Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...
Martin Christen
 
Simply arduino
Simply arduinoSimply arduino
Simply arduino
Abdullah Sharaf
 
IoT... this time it is different?
IoT... this time it is different?IoT... this time it is different?
IoT... this time it is different?
Heinz Tonn
 
動かしながら学ぶMQTT
動かしながら学ぶMQTT動かしながら学ぶMQTT
動かしながら学ぶMQTT
Eiji Yokota
 
How to Connect MQTT Broker on ESP8266 WiFi
How to Connect MQTT Broker on ESP8266 WiFiHow to Connect MQTT Broker on ESP8266 WiFi
How to Connect MQTT Broker on ESP8266 WiFi
Naoto MATSUMOTO
 
Mqttの通信を見てみよう
Mqttの通信を見てみようMqttの通信を見てみよう
Mqttの通信を見てみよう
Suemasu Takashi
 
溫溼度數據統計
溫溼度數據統計溫溼度數據統計
溫溼度數據統計
裕凱 夏
 
Easy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonEasy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and Python
Núria Vilanova
 
MQTT meetup in Tokyo 機能概要
MQTT meetup in Tokyo 機能概要MQTT meetup in Tokyo 機能概要
MQTT meetup in Tokyo 機能概要
shirou wakayama
 
MQTTS mosquitto - cheat sheet -
MQTTS mosquitto - cheat sheet -MQTTS mosquitto - cheat sheet -
MQTTS mosquitto - cheat sheet -
Naoto MATSUMOTO
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
Seggy Segaran
 
IoT時代を支えるプロトコルMQTT技術詳解
IoT時代を支えるプロトコルMQTT技術詳解IoT時代を支えるプロトコルMQTT技術詳解
IoT時代を支えるプロトコルMQTT技術詳解
Naoto MATSUMOTO
 
IoT Aquarium 2
IoT Aquarium 2IoT Aquarium 2
IoT Aquarium 2
Benjamin Chodroff
 
IoT World Forum Press Conference - 10.14.2014
IoT World Forum Press Conference - 10.14.2014IoT World Forum Press Conference - 10.14.2014
IoT World Forum Press Conference - 10.14.2014
Bessie Wang
 
20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと
Daichi Morifuji
 
19. atmospheric processes 2
19. atmospheric processes 219. atmospheric processes 2
19. atmospheric processes 2
Makati Science High School
 
Python and the internet of things
Python and the internet of thingsPython and the internet of things
Python and the internet of things
Adam Englander
 
Ashley Madison - Lessons Learned
Ashley Madison - Lessons LearnedAshley Madison - Lessons Learned
Ashley Madison - Lessons Learned
Adam Englander
 
Docker for Python Development
Docker for Python DevelopmentDocker for Python Development
Docker for Python Development
Martin Christen
 
Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...
Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...
Visualisation of Complex 3D City Models on Mobile Webbrowsers Using Cloud-bas...
Martin Christen
 
IoT... this time it is different?
IoT... this time it is different?IoT... this time it is different?
IoT... this time it is different?
Heinz Tonn
 
動かしながら学ぶMQTT
動かしながら学ぶMQTT動かしながら学ぶMQTT
動かしながら学ぶMQTT
Eiji Yokota
 
How to Connect MQTT Broker on ESP8266 WiFi
How to Connect MQTT Broker on ESP8266 WiFiHow to Connect MQTT Broker on ESP8266 WiFi
How to Connect MQTT Broker on ESP8266 WiFi
Naoto MATSUMOTO
 
Mqttの通信を見てみよう
Mqttの通信を見てみようMqttの通信を見てみよう
Mqttの通信を見てみよう
Suemasu Takashi
 
溫溼度數據統計
溫溼度數據統計溫溼度數據統計
溫溼度數據統計
裕凱 夏
 
Easy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and PythonEasy GPS Tracker using Arduino and Python
Easy GPS Tracker using Arduino and Python
Núria Vilanova
 
MQTT meetup in Tokyo 機能概要
MQTT meetup in Tokyo 機能概要MQTT meetup in Tokyo 機能概要
MQTT meetup in Tokyo 機能概要
shirou wakayama
 
MQTTS mosquitto - cheat sheet -
MQTTS mosquitto - cheat sheet -MQTTS mosquitto - cheat sheet -
MQTTS mosquitto - cheat sheet -
Naoto MATSUMOTO
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
Seggy Segaran
 
IoT時代を支えるプロトコルMQTT技術詳解
IoT時代を支えるプロトコルMQTT技術詳解IoT時代を支えるプロトコルMQTT技術詳解
IoT時代を支えるプロトコルMQTT技術詳解
Naoto MATSUMOTO
 
IoT World Forum Press Conference - 10.14.2014
IoT World Forum Press Conference - 10.14.2014IoT World Forum Press Conference - 10.14.2014
IoT World Forum Press Conference - 10.14.2014
Bessie Wang
 
20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと
Daichi Morifuji
 
Ad

Similar to Gettiing Started with IoT using Raspberry Pi and Python (20)

OSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet Mens
OSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet MensOSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet Mens
OSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet Mens
NETWAYS
 
MQTT – protocol for yours IoT
MQTT – protocol for yours IoTMQTT – protocol for yours IoT
MQTT – protocol for yours IoT
Miroslav Resetar
 
MQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdf
MQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdfMQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdf
MQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdf
ManhHoangVan
 
Practical Security with MQTT and Mosquitto
Practical Security with MQTT and MosquittoPractical Security with MQTT and Mosquitto
Practical Security with MQTT and Mosquitto
nbarendt
 
Connecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTTConnecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTT
Leon Anavi
 
MQTT_v2 protocol for IOT based applications
MQTT_v2 protocol for IOT based applicationsMQTT_v2 protocol for IOT based applications
MQTT_v2 protocol for IOT based applications
hassam37
 
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communicationMQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
Christian Götz
 
How to build own IoT Platform
How to build own IoT PlatformHow to build own IoT Platform
How to build own IoT Platform
Patryk Omiotek
 
Building Smart IoT Solutions: Raspberry Pi with Hive MQTT
Building Smart IoT Solutions: Raspberry Pi with Hive MQTTBuilding Smart IoT Solutions: Raspberry Pi with Hive MQTT
Building Smart IoT Solutions: Raspberry Pi with Hive MQTT
Ashish Sadavarti
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
Andy Piper
 
Messaging for the Internet of Awesome Things
Messaging for the Internet of Awesome ThingsMessaging for the Internet of Awesome Things
Messaging for the Internet of Awesome Things
Andy Piper
 
Mqtt
MqttMqtt
Mqtt
abinaya m
 
MQTT - Austin IoT Meetup
MQTT - Austin IoT MeetupMQTT - Austin IoT Meetup
MQTT - Austin IoT Meetup
Bryan Boyd
 
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorialPowering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
Benjamin Cabé
 
mqttvsrest_v4.pdf
mqttvsrest_v4.pdfmqttvsrest_v4.pdf
mqttvsrest_v4.pdf
RaghuKiran29
 
MQTT and SensorThings API MQTT Extension
MQTT and SensorThings API MQTT ExtensionMQTT and SensorThings API MQTT Extension
MQTT and SensorThings API MQTT Extension
SensorUp
 
MQTT 101 - Getting started with the lightweight IoT Protocol
MQTT 101  - Getting started with the lightweight IoT ProtocolMQTT 101  - Getting started with the lightweight IoT Protocol
MQTT 101 - Getting started with the lightweight IoT Protocol
Christian Götz
 
Creating #IOT applications using #MQTT
Creating #IOT applications using #MQTTCreating #IOT applications using #MQTT
Creating #IOT applications using #MQTT
Jeffrey Cohen, P.E.
 
MQTT: A lightweight messaging platform for IoT
MQTT: A lightweight messaging platform for IoTMQTT: A lightweight messaging platform for IoT
MQTT: A lightweight messaging platform for IoT
Alejandro Martín Clemente
 
Why and how we proxy our IoT broker connections
 Why and how we proxy our IoT broker connections Why and how we proxy our IoT broker connections
Why and how we proxy our IoT broker connections
Scaleway
 
OSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet Mens
OSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet MensOSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet Mens
OSMC 2014: MQTT for monitoring (and for the lo t) | Jan-Piet Mens
NETWAYS
 
MQTT – protocol for yours IoT
MQTT – protocol for yours IoTMQTT – protocol for yours IoT
MQTT – protocol for yours IoT
Miroslav Resetar
 
MQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdf
MQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdfMQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdf
MQTfsdaffffffffffffffffffffffffffffffffffffffffT.pdf
ManhHoangVan
 
Practical Security with MQTT and Mosquitto
Practical Security with MQTT and MosquittoPractical Security with MQTT and Mosquitto
Practical Security with MQTT and Mosquitto
nbarendt
 
Connecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTTConnecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTT
Leon Anavi
 
MQTT_v2 protocol for IOT based applications
MQTT_v2 protocol for IOT based applicationsMQTT_v2 protocol for IOT based applications
MQTT_v2 protocol for IOT based applications
hassam37
 
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communicationMQTT with Eclipse Paho: A protocol for IoT and M2M communication
MQTT with Eclipse Paho: A protocol for IoT and M2M communication
Christian Götz
 
How to build own IoT Platform
How to build own IoT PlatformHow to build own IoT Platform
How to build own IoT Platform
Patryk Omiotek
 
Building Smart IoT Solutions: Raspberry Pi with Hive MQTT
Building Smart IoT Solutions: Raspberry Pi with Hive MQTTBuilding Smart IoT Solutions: Raspberry Pi with Hive MQTT
Building Smart IoT Solutions: Raspberry Pi with Hive MQTT
Ashish Sadavarti
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
Andy Piper
 
Messaging for the Internet of Awesome Things
Messaging for the Internet of Awesome ThingsMessaging for the Internet of Awesome Things
Messaging for the Internet of Awesome Things
Andy Piper
 
MQTT - Austin IoT Meetup
MQTT - Austin IoT MeetupMQTT - Austin IoT Meetup
MQTT - Austin IoT Meetup
Bryan Boyd
 
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorialPowering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
Benjamin Cabé
 
MQTT and SensorThings API MQTT Extension
MQTT and SensorThings API MQTT ExtensionMQTT and SensorThings API MQTT Extension
MQTT and SensorThings API MQTT Extension
SensorUp
 
MQTT 101 - Getting started with the lightweight IoT Protocol
MQTT 101  - Getting started with the lightweight IoT ProtocolMQTT 101  - Getting started with the lightweight IoT Protocol
MQTT 101 - Getting started with the lightweight IoT Protocol
Christian Götz
 
Creating #IOT applications using #MQTT
Creating #IOT applications using #MQTTCreating #IOT applications using #MQTT
Creating #IOT applications using #MQTT
Jeffrey Cohen, P.E.
 
MQTT: A lightweight messaging platform for IoT
MQTT: A lightweight messaging platform for IoTMQTT: A lightweight messaging platform for IoT
MQTT: A lightweight messaging platform for IoT
Alejandro Martín Clemente
 
Why and how we proxy our IoT broker connections
 Why and how we proxy our IoT broker connections Why and how we proxy our IoT broker connections
Why and how we proxy our IoT broker connections
Scaleway
 
Ad

More from Martin Christen (12)

Opening Session GeoPython & Python Machine Learning Conference
Opening Session GeoPython & Python Machine Learning Conference Opening Session GeoPython & Python Machine Learning Conference
Opening Session GeoPython & Python Machine Learning Conference
Martin Christen
 
EuroPython 2019: GeoSpatial Analysis using Python and JupyterHub
EuroPython 2019: GeoSpatial Analysis using Python and JupyterHubEuroPython 2019: GeoSpatial Analysis using Python and JupyterHub
EuroPython 2019: GeoSpatial Analysis using Python and JupyterHub
Martin Christen
 
Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25
Martin Christen
 
High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...
High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...
High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...
Martin Christen
 
Teaching with JupyterHub - lessons learned
Teaching with JupyterHub - lessons learnedTeaching with JupyterHub - lessons learned
Teaching with JupyterHub - lessons learned
Martin Christen
 
Mixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-StadtmodellenMixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-Stadtmodellen
Martin Christen
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
Martin Christen
 
OpenStreetMap in 3D using Python
OpenStreetMap in 3D using PythonOpenStreetMap in 3D using Python
OpenStreetMap in 3D using Python
Martin Christen
 
3d mit Python (PythonCamp)
3d mit Python (PythonCamp)3d mit Python (PythonCamp)
3d mit Python (PythonCamp)
Martin Christen
 
Webilea: The OpenWebGlobe Project
Webilea: The OpenWebGlobe ProjectWebilea: The OpenWebGlobe Project
Webilea: The OpenWebGlobe Project
Martin Christen
 
OpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing BernOpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing Bern
Martin Christen
 
GeoBeer July 3rd, 2013
GeoBeer July 3rd, 2013GeoBeer July 3rd, 2013
GeoBeer July 3rd, 2013
Martin Christen
 
Opening Session GeoPython & Python Machine Learning Conference
Opening Session GeoPython & Python Machine Learning Conference Opening Session GeoPython & Python Machine Learning Conference
Opening Session GeoPython & Python Machine Learning Conference
Martin Christen
 
EuroPython 2019: GeoSpatial Analysis using Python and JupyterHub
EuroPython 2019: GeoSpatial Analysis using Python and JupyterHubEuroPython 2019: GeoSpatial Analysis using Python and JupyterHub
EuroPython 2019: GeoSpatial Analysis using Python and JupyterHub
Martin Christen
 
Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25
Martin Christen
 
High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...
High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...
High-Quality Server Side Rendering using the OGC’s 3D Portrayal Service – App...
Martin Christen
 
Teaching with JupyterHub - lessons learned
Teaching with JupyterHub - lessons learnedTeaching with JupyterHub - lessons learned
Teaching with JupyterHub - lessons learned
Martin Christen
 
Mixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-StadtmodellenMixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-Stadtmodellen
Martin Christen
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
Martin Christen
 
OpenStreetMap in 3D using Python
OpenStreetMap in 3D using PythonOpenStreetMap in 3D using Python
OpenStreetMap in 3D using Python
Martin Christen
 
3d mit Python (PythonCamp)
3d mit Python (PythonCamp)3d mit Python (PythonCamp)
3d mit Python (PythonCamp)
Martin Christen
 
Webilea: The OpenWebGlobe Project
Webilea: The OpenWebGlobe ProjectWebilea: The OpenWebGlobe Project
Webilea: The OpenWebGlobe Project
Martin Christen
 
OpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing BernOpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing Bern
Martin Christen
 

Recently uploaded (20)

FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptxFIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FMESupporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdfWar_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdfENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptxFIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FMESupporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdfWar_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdfENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 

Gettiing Started with IoT using Raspberry Pi and Python

  • 1. Martin Christen FHNW – University of Applied Sciences and Arts Northwestern Switzerland School of Architecture, Civil Engineering and Geomatics Institute of Geomatics Engineering [email protected] @MartinChristen Getting Started with IoT using a Raspberry Pi and Python Quelle: http://cloudtimes.org/2013/09/09/introducing-web-3-0-internet-of-things/Quelle: https://www.hifiberry.com/2016/02/the-new-raspberry-pi-3-is-out/
  • 2. 10 April 2016Insitute of Geomatics Engineering 2 Quelle: https://www.ncta.com/platform/industry-news/infographic-the-growth-of-the-internet-of-things/
  • 3. 10 April 2016Insitute of Geomatics Engineering 3 MQTT (Message Queuing Telemetry Transport) MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for “machine to machine” messaging such as with low power sensors or mobile devices such as phones or the Raspberry Pi. MQTT dates back to 1999. MQTT is: Open (ISO/IEC PRF 20922) Lightweight (2 bytes header) Reliable (QoS/patterns to avoid packet loss) Simple (TCP based, async, publish/subscribe, payload agnostic)
  • 4. 10 April 2016Insitute of Geomatics Engineering 4 How MQTT works Quelle: https://zoetrope.io/tech-blog/brief-practical-introduction-mqtt-protocol-and-its-application-iot
  • 5. 10 April 2016Insitute of Geomatics Engineering 5 XMPP Implementation: Eclipse Mosquitto • Lightweight server implementation of MQTT written in C • About 3 MB RAM with 1000 clients connected… • http://eclipse.org/mosquitto • Client support for Python 2.x and Python 3.x
  • 6. 10 April 2016Insitute of Geomatics Engineering 6 Dockerfile FROM ubuntu:14.04 ENV DEBIAN_FRONTEND noninteractive RUN apt-get update RUN apt-get upgrade -y RUN apt-get install wget build-essential libwrap0-dev libssl-dev -y RUN apt-get install python-distutils-extra libc-ares-dev uuid-dev -y RUN mkdir -p /usr/local/src WORKDIR /usr/local/src RUN wget http://mosquitto.org/files/source/mosquitto-1.4.8.tar.gz RUN tar xvzf ./mosquitto-1.4.8.tar.gz WORKDIR /usr/local/src/mosquitto-1.4.8 RUN make RUN make install RUN adduser --system --disabled-password --disabled-login mosquitto USER mosquitto EXPOSE 1883 CMD ["/usr/local/sbin/mosquitto"] based on: https://hub.docker.com/r/ansi/mosquitto/~/dockerfile docker build -t test-mosquitto . docker run -p 1883:1883 test-mosquitto
  • 7. 10 April 2016Insitute of Geomatics Engineering 7 Python Client pip3 install paho-mqtt Documentation: https://pypi.python.org/pypi/paho-mqtt/ Source: https://github.com/eclipse/paho.mqtt.python
  • 8. 10 April 2016Insitute of Geomatics Engineering 8 MQTT: Subscribe import paho.mqtt.client as mqtt def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("SensorXY/#") # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): print(msg.topic + " " + str(msg.payload)) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message host = "192.168.99.100" print("Connecting to " + host) client.connect(host, port=1883, keepalive=60) client.loop_forever()
  • 9. 10 April 2016Insitute of Geomatics Engineering 9 MQTT: Publish import paho.mqtt.client as mqtt def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # The callback for when a PUBLISH message is received from the server. # unused for this demo def on_publish(client, userdata, mid): pass client = mqtt.Client() client.on_connect = on_connect client.on_publish = on_publish host = "192.168.99.100" client.connect(host, port=1883, keepalive=60) client.loop_start() topic = "SensorXY" s = "" while s != "exit": s = input("payload >") client.publish(topic, s) client.loop_stop()
  • 10. 10 April 2016Insitute of Geomatics Engineering 10 Simple example: Remote-control a light from anywhere in the world In the first example we turn on/off a LED using MQTT. The LED is connected on GPIO Pin 11 (GPIO 17) https://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm
  • 11. 10 April 2016Insitute of Geomatics Engineering 11 How it works: Raspberri Pi MQTT Broker Subscribe and wait for command «light on» or «light off» Controller Interface Send command «light on», «light off», or «get status» DB save state (optional)
  • 12. 10 April 2016Insitute of Geomatics Engineering 12 Raspberry Pi Client import RPi.GPIO as GPIO import paho.mqtt.client as mqtt def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("Raspberry/#") # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): s = str(msg.payload, encoding="ascii") print("retrieved message: " + s) if s == "lighton": GPIO.output(LedPin, GPIO.LOW) elif s == "lightoff": GPIO.output(LedPin, GPIO.HIGH) # Initialize GPIO LedPin = 11 # pin GPIO 17, change if you connect to other pin! GPIO.setmode(GPIO.BOARD) GPIO.setup(LedPin, GPIO.OUT) GPIO.output(LedPin, GPIO.HIGH) # turn off led # Initialize MQTT client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message host = "192.168.99.100" print("Connecting to " + host) client.connect(host, port=1883, keepalive=60) client.loop_forever() sudo pip3 install paho-mqtt
  • 13. 10 April 2016Insitute of Geomatics Engineering 13 Control Raspberry Pi import paho.mqtt.client as mqtt client = mqtt.Client() host = "192.168.99.100" client.connect(host, port=1883, keepalive=60) client.loop_start() topic = "Raspberry" print("COMMANDS:") print("0: turn light off") print("1: turn light on") print("3: quit application") s=0 while s!=3: s = int(input("command >")) if s == 0: client.publish(topic, "lightoff") elif s == 1: client.publish(topic, "lighton") elif s == 3: print("bye") else: print("unknown command") client.loop_stop()
  • 14. 10 April 2016Insitute of Geomatics Engineering 14 Questions ?