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 ?
Ad

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)

容器與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 Meetup
Bryan 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 Things
Bryan Boyd
 
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
 
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
 
mqttvsrest_v4.pdf
mqttvsrest_v4.pdfmqttvsrest_v4.pdf
mqttvsrest_v4.pdf
RaghuKiran29
 
Virtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor NetworksVirtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor Networks
Matthias Kovatsch
 
1st RINASim webinar
1st RINASim webinar1st RINASim webinar
1st RINASim webinar
Vladimír Veselý
 
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 KSQL
Guido 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 2021
StreamNative
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
Andy 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 Mens
NETWAYS
 
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
inside-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 Things
Markus 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 YaaS
Lars 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 LoRaWAN
Pance Cavkovski
 
容器與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 Meetup
Bryan 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 Things
Bryan Boyd
 
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
 
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
 
Virtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor NetworksVirtual IoT Meetup: Connecting Sensor Networks
Virtual IoT Meetup: Connecting Sensor Networks
Matthias 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 KSQL
Guido 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 2021
StreamNative
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
Andy 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 Mens
NETWAYS
 
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
inside-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 Things
Markus 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 YaaS
Lars 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 LoRaWAN
Pance Cavkovski
 
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)

TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 

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 ?