SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
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 ?

Contenu connexe

Tendances

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 sampleMirco 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 CoreAndri 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 HATLeon 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 HTML5Leon 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 experienceAlexandre 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 BeyondSamsung Open Source Group
 

Tendances (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
 
Iotivity atmel-20150328rzr
Iotivity atmel-20150328rzrIotivity atmel-20150328rzr
Iotivity atmel-20150328rzr
 
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
 
IoTivity: From Devices to the Cloud
IoTivity: From Devices to the CloudIoTivity: From Devices to the Cloud
IoTivity: From Devices to the Cloud
 
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
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
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
 
Ipdtl
IpdtlIpdtl
Ipdtl
 
TinyOS 2.1 Tutorial: TOSSIM
TinyOS 2.1 Tutorial: TOSSIMTinyOS 2.1 Tutorial: TOSSIM
TinyOS 2.1 Tutorial: TOSSIM
 
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
 
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
 

En vedette

Python and the internet of things
Python and the internet of thingsPython and the internet of things
Python and the internet of thingsAdam Englander
 
Ashley Madison - Lessons Learned
Ashley Madison - Lessons LearnedAshley Madison - Lessons Learned
Ashley Madison - Lessons LearnedAdam Englander
 
Docker for Python Development
Docker for Python DevelopmentDocker for Python Development
Docker for Python DevelopmentMartin 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
動かしながら学ぶMQTTEiji 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 WiFiNaoto 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 PythonNú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 PythonSeggy 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.2014Bessie Wang
 
20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったことDaichi Morifuji
 

En vedette (20)

Python and the internet of things
Python and the internet of thingsPython and the internet of things
Python and the internet of things
 
Ashley Madison - Lessons Learned
Ashley Madison - Lessons LearnedAshley Madison - Lessons Learned
Ashley Madison - Lessons Learned
 
Docker for Python Development
Docker for Python DevelopmentDocker for Python Development
Docker for Python Development
 
Presentation final 72
Presentation final 72Presentation final 72
Presentation final 72
 
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...
 
Simply arduino
Simply arduinoSimply arduino
Simply arduino
 
IoT... this time it is different?
IoT... this time it is different?IoT... this time it is different?
IoT... this time it is different?
 
動かしながら学ぶMQTT
動かしながら学ぶMQTT動かしながら学ぶMQTT
動かしながら学ぶMQTT
 
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
 
Mqttの通信を見てみよう
Mqttの通信を見てみようMqttの通信を見てみよう
Mqttの通信を見てみよう
 
溫溼度數據統計
溫溼度數據統計溫溼度數據統計
溫溼度數據統計
 
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
 
MQTT meetup in Tokyo 機能概要
MQTT meetup in Tokyo 機能概要MQTT meetup in Tokyo 機能概要
MQTT meetup in Tokyo 機能概要
 
MQTTS mosquitto - cheat sheet -
MQTTS mosquitto - cheat sheet -MQTTS mosquitto - cheat sheet -
MQTTS mosquitto - cheat sheet -
 
Raspberry Pi Using Python
Raspberry Pi Using PythonRaspberry Pi Using Python
Raspberry Pi Using Python
 
IoT時代を支えるプロトコルMQTT技術詳解
IoT時代を支えるプロトコルMQTT技術詳解IoT時代を支えるプロトコルMQTT技術詳解
IoT時代を支えるプロトコルMQTT技術詳解
 
IoT Aquarium 2
IoT Aquarium 2IoT Aquarium 2
IoT Aquarium 2
 
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
 
20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと20150726 IoTってなに?ニフティクラウドmqttでやったこと
20150726 IoTってなに?ニフティクラウドmqttでやったこと
 
19. atmospheric processes 2
19. atmospheric processes 219. atmospheric processes 2
19. atmospheric processes 2
 

Similaire à Gettiing Started with IoT using Raspberry Pi and Python

容器與IoT端點應用
容器與IoT端點應用容器與IoT端點應用
容器與IoT端點應用Philip Zheng
 
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)Jakub Botwicz
 
MQTT - Austin IoT Meetup
MQTT - Austin IoT MeetupMQTT - Austin IoT Meetup
MQTT - Austin IoT MeetupBryan Boyd
 
MQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of ThingsMQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of ThingsBryan Boyd
 
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 ThingsAndy Piper
 
Virtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor NetworksVirtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor NetworksMatthias Kovatsch
 
Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...
Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...
Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...confluent
 
Ingesting and Processing IoT Data - using MQTT, Kafka Connect and KSQL
Ingesting and Processing IoT Data - using MQTT, Kafka Connect and KSQLIngesting and Processing IoT Data - using MQTT, Kafka Connect and KSQL
Ingesting and Processing IoT Data - using MQTT, Kafka Connect and KSQLGuido Schmutz
 
Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021
Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021
Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021StreamNative
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTTAndy Piper
 
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 MensNETWAYS
 
RDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA Interconnects
RDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA InterconnectsRDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA Interconnects
RDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA Interconnectsinside-BigData.com
 
Connecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of ThingsConnecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of ThingsMarkus Van Kempen
 
20151117 IoT를 위한 서비스 구성과 개발
20151117 IoT를 위한 서비스 구성과 개발20151117 IoT를 위한 서비스 구성과 개발
20151117 IoT를 위한 서비스 구성과 개발영욱 김
 
Apache Kafka Scalable Message Processing and more!
Apache Kafka Scalable Message Processing and more! Apache Kafka Scalable Message Processing and more!
Apache Kafka Scalable Message Processing and more! Guido Schmutz
 
Moto - Orchestrating IoT for business users 
and connecting it to YaaS
Moto - Orchestrating IoT for business users 
and connecting it to YaaSMoto - Orchestrating IoT for business users 
and connecting it to YaaS
Moto - Orchestrating IoT for business users 
and connecting it to YaaSLars Gregori
 
Gluing the IoT world with Java and LoRaWAN
Gluing the IoT world with Java and LoRaWANGluing the IoT world with Java and LoRaWAN
Gluing the IoT world with Java and LoRaWANPance Cavkovski
 
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 FinalExploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 Finalmasoodnt10
 

Similaire à Gettiing Started with IoT using Raspberry Pi and Python (20)

容器與IoT端點應用
容器與IoT端點應用容器與IoT端點應用
容器與IoT端點應用
 
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
 
MQTT - Austin IoT Meetup
MQTT - Austin IoT MeetupMQTT - Austin IoT Meetup
MQTT - Austin IoT Meetup
 
MQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of ThingsMQTT - A practical protocol for the Internet of Things
MQTT - A practical protocol for the Internet of Things
 
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
 
mqttvsrest_v4.pdf
mqttvsrest_v4.pdfmqttvsrest_v4.pdf
mqttvsrest_v4.pdf
 
Virtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor NetworksVirtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor Networks
 
1st RINASim webinar
1st RINASim webinar1st RINASim webinar
1st RINASim webinar
 
Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...
Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...
Ingesting and Processing IoT Data Using MQTT, Kafka Connect and Kafka Streams...
 
Ingesting and Processing IoT Data - using MQTT, Kafka Connect and KSQL
Ingesting and Processing IoT Data - using MQTT, Kafka Connect and KSQLIngesting and Processing IoT Data - using MQTT, Kafka Connect and KSQL
Ingesting and Processing IoT Data - using MQTT, Kafka Connect and KSQL
 
Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021
Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021
Apache Pulsar with MQTT for Edge Computing - Pulsar Summit Asia 2021
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
 
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
 
RDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA Interconnects
RDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA InterconnectsRDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA Interconnects
RDMA, Scalable MPI-3 RMA, and Next-Generation Post-RDMA Interconnects
 
Connecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of ThingsConnecting NEST via MQTT to Internet of Things
Connecting NEST via MQTT to Internet of Things
 
20151117 IoT를 위한 서비스 구성과 개발
20151117 IoT를 위한 서비스 구성과 개발20151117 IoT를 위한 서비스 구성과 개발
20151117 IoT를 위한 서비스 구성과 개발
 
Apache Kafka Scalable Message Processing and more!
Apache Kafka Scalable Message Processing and more! Apache Kafka Scalable Message Processing and more!
Apache Kafka Scalable Message Processing and more!
 
Moto - Orchestrating IoT for business users 
and connecting it to YaaS
Moto - Orchestrating IoT for business users 
and connecting it to YaaSMoto - Orchestrating IoT for business users 
and connecting it to YaaS
Moto - Orchestrating IoT for business users 
and connecting it to YaaS
 
Gluing the IoT world with Java and LoRaWAN
Gluing the IoT world with Java and LoRaWANGluing the IoT world with Java and LoRaWAN
Gluing the IoT world with Java and LoRaWAN
 
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 FinalExploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
Exploiting Network Protocols To Exhaust Bandwidth Links 2008 Final
 

Plus de 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 JupyterHubMartin Christen
 
Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25Martin 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 learnedMartin Christen
 
Mixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-StadtmodellenMixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-StadtmodellenMartin Christen
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with PythonMartin Christen
 
OpenStreetMap in 3D using Python
OpenStreetMap in 3D using PythonOpenStreetMap in 3D using Python
OpenStreetMap in 3D using PythonMartin 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 ProjectMartin Christen
 
OpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing BernOpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing BernMartin Christen
 

Plus de 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
 
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
 
Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25Lightning Talk GeoBeer #25
Lightning Talk GeoBeer #25
 
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...
 
Teaching with JupyterHub - lessons learned
Teaching with JupyterHub - lessons learnedTeaching with JupyterHub - lessons learned
Teaching with JupyterHub - lessons learned
 
Mixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-StadtmodellenMixed Reality Anwendungen mit 3D-Stadtmodellen
Mixed Reality Anwendungen mit 3D-Stadtmodellen
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
 
OpenStreetMap in 3D using Python
OpenStreetMap in 3D using PythonOpenStreetMap in 3D using Python
OpenStreetMap in 3D using Python
 
3d mit Python (PythonCamp)
3d mit Python (PythonCamp)3d mit Python (PythonCamp)
3d mit Python (PythonCamp)
 
Webilea: The OpenWebGlobe Project
Webilea: The OpenWebGlobe ProjectWebilea: The OpenWebGlobe Project
Webilea: The OpenWebGlobe Project
 
OpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing BernOpenWebGlobe - GeoSharing Bern
OpenWebGlobe - GeoSharing Bern
 
GeoBeer July 3rd, 2013
GeoBeer July 3rd, 2013GeoBeer July 3rd, 2013
GeoBeer July 3rd, 2013
 

Dernier

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Dernier (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

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 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/
  • 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 ?