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

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

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

Viewers also liked

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
 

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

Similar to 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 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
 
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
 
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
masoodnt10
 

Similar to 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
 

More from 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
 
GeoBeer July 3rd, 2013
GeoBeer July 3rd, 2013GeoBeer July 3rd, 2013
GeoBeer July 3rd, 2013
Martin Christen
 

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

Recently uploaded

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 

Recently uploaded (20)

Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 

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 ?