SlideShare a Scribd company logo
Elastic Network of Things
with MQTT and MicroPython
PyCon TW 2017
Wei Lin
source of picture
2
Control over Internet
3
Increasing devices
http://www.toobler.com/blog/google-provides-a-customized-os-for-internet-of-things-iot-brillo
4
Considerations
• Deploy, maintain, evolve
– With distributed devices
• Coordinate a group of devices
– IF This Then That
– IF These Then Those ?
• Devices coverage
– Small
– Low cost
• use Python on MCU?
5
MicroPython (uPy)
http://micropython.org/
2014/5/3 ~
• Damien George
• George Robotics Limited
6
ESP8266
RISC 32bits 80Mhz
64KB + 96KB SRAM
7
ESP-12 module teardown
http://www.my-iota.com/Development%20boards/ESP12%20Module/ESP-12%20Module.htm
ESP8266ESP8266 4MB flash4MB flash
8
ESP-12 module pinouts
https://nettigo.eu/products/esp-8266-12-wifi-module-with-9-gpio--2
https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/flash-firmware
3.3V only !3.3V only !
5V will kill it !5V will kill it !
9
ESP8266 modules
ESP-12
D1-mini
NodeMCU
10
ESP8266
erase Flash
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/flash-firmware
• Install esptool
pip install esptool
• erase Flash
esptool.py --port COM13 --baud 115200
erase_flash
11
ESP8266
flash uPy firmware
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/flash-firmware
• Download firmware
– http://micropython.org/download#esp8266
• Flash firmware
– esptool.py --port COM13 --baud 115200
write_flash --flash_size=32m 0x00000
../firmware/MicroPython_ESP8266.bin
12
This is MicroPython !
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
REPL: Read-Eval-Print Loop
https://learn.adafruit.com/micropython-basics-how-to-load-micropython-on-a-board/serial-terminal
13
uPy
upload script file
https://learn.adafruit.com/micropython-basics-esp8266-webrepl/send-and-get-files
https://learn.adafruit.com/micropython-basics-load-files-and-run-code/overview
• install ampy ( Adafruit MicroPython Tool )
pip install adafruit-ampy
• ampy commands
– list files
ampy --port {com_port} ls
– cat file
ampy --port {com_port} get {file}
– remove file
ampy --port {com_port} rm {file}
– upload file
ampy --port {com_port} put {file}
ex: ampy –port COM13 putput script.py
Remember to :
• break main loop
• surrender COM port
14
uPy – filesystem & flow
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/filesystem.html
• uPy
boot.py
main.py
• Arduino
setup( )
loop( )
15
MicroPython libraries
https://docs.micropython.org/en/latest/pyboard/library/
• MicroPython-specific libraries
– btree – simple BTree database
– framebuf — Frame buffer manipulation
–– machinemachine — functions related to the hardware
– micropython – MicroPython internals
– network — network configuration
– uctypes – access binary data in a structured way
16
uPy – ESP8266
documents
• MicroPython docs for ESP8266
– http://micropython.org/resources/docs/en/
latest/esp8266/
# Blink LED
from machine import Pin
p2 = Pin(2, Pin.OUT)
p2.value(0)
17
Setup WiFi connection
https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/network_basics.html
import network
nic=network.WLAN(network.STA_IF)
nic.active(True)
nic.connect('SSID','password')
nic.ifconfig()
# ESP8266 remembers last successful connection
18
Packages for MicroPython
https://pypi.python.org/pypi?%3Aaction=search&term=micropython&submit=search
• https://pypi.python.org/pypi?%3Aactio
n=search&term=micropython&submit
=search
19
MicroPython @ Adafruit
https://learn.adafruit.com/category/micropython
20
CommunicationCommunication
&&
CoordinationCoordination
21
MQTT messaging
one to one
https://sakshambhatla.wordpress.com/2014/08/11/simple-mqtt-broker-and-client-in-python/
broker
Node n_Alpha
Subscribe
uPy / n_Alpha
uPy / Hub
Node n_Beta
Subscribe
uPy / n_Beta
uPy / Hub
Node Client
publish
topic = “uPy / n_Alpha”
payload = “Hello”
22
MQTT messaging
one to one
https://sakshambhatla.wordpress.com/2014/08/11/simple-mqtt-broker-and-client-in-python/
broker
Node n_Alpha
Subscribe
uPy / n_Alpha
uPy / Hub
Node n_Beta
Subscribe
uPy / n_Beta
uPy / Hub
Node Client
publish
topic = “uPy / n_Beta”
payload = “Hello”
23
MQTT messaging
broadcast
https://sakshambhatla.wordpress.com/2014/08/11/simple-mqtt-broker-and-client-in-python/
broker
Node n_Alpha
Subscribe
uPy / n_Alpha
uPy / Hub
Node n_Beta
Subscribe
uPy / n_Beta
uPy / Hub
Node Client
publish
topic = “uPy / Hub”
payload = “Hello”
24
MQTT messaging
collect
https://sakshambhatla.wordpress.com/2014/08/11/simple-mqtt-broker-and-client-in-python/
broker
Node Boss
Subscribe
uPy / *
Node Client
publish
topic =
“uPy / n_Alpha”or
“uPy / n_Beta”or
“uPy / Hub”
25
Celery architecture
http://konarkmodi.com/DevOps-2013/images/celery-architecture.jpg
brokerClient
26
My message format
27
Deployment diagram
Docker container
on Raspberry Pi
28
Demo 1
• Note: shown code is experimental and
for demonstration only.
29
Classes and message flow
30
Message types and switch
31
Message type: command
32
Message type: function
33
RPC
https://www.rabbitmq.com/tutorials/tutorial-six-python.html
34
RPC? How?
35
Worker.request()
36
Asynch_result
37
Message type: eval
38
Message type: exec
39
Transmit behavior, not just data
40
IPython Parallel (IPP) architecture
https://ipython.org/ipython-doc/3/parallel/parallel_intro.html
41
IPP
• Message format
– http://ipyparallel.readthedocs.io/en/latest/development/messages.html
– http://ipyparallel.readthedocs.io/en/latest/development/connections.html#parallel-
connections
• Transmitting behavior(function)
1. serialize function object and args
2. transmit
3. un-serialize function object and args
4. execute
– https://github.com/ipython/ipyparallel/blob/master/ipyparallel/serialize/serialize.py
– https://github.com/ipython/ipyparallel/blob/master/ipyparallel/serialize/canning.py
42
Demo 2
• Note: shown code is experimental and
for demonstration only.
43
Message type: file
44
Message type: script
45
script_to_deploy.py
46
functions_def.py
47
Input & Output as vectors
• Input as a vector
• Output as a vector
48
If This Then That
49
The Problem
50
Machine to MachineMachine to Machine
&&
Event SystemEvent System
51
Edge computing
52
Probability of failure
http://www.modestdragon.com/bruce-lees-strength/
53
Design pattern
54
Event System
55
Lambda as “AND” gate
56
Classes
using frozen modules: https://learn.adafruit.com/micropython-basics-loading-modules/frozen-modules
57
Demo 3
• Note: shown code is experimental and
for demonstration only.
• using frozen modules technique:
– https://learn.adafruit.com/micropython-
basics-loading-modules/frozen-modules
58
Neuron.addConnection( )
Neuron.setWeight( )
59
Neuron.fire( )
60
Neuron.kick( )
61
If These Then Those
62
Cerebellum & Cortex
Train
Deploy
Subscribe: uPy / *
63
FutureFuture
64
User Interface – modern version
65
About Me
• Wei Lin
– Twitter: @Wei_1144
– Email: Wei1234c@gmail.com
• GitHub rep. for this talk:
https://github.com/Wei1234c/Elastic_Network_of_Things_with_
MQTT_and_MicroPython
66
Q & AQ & A

More Related Content

What's hot (20)

PDF
WebRTC と Native とそれから、それから。
tnoho
 
PPTX
Tiny ML for spark Fun Edge
艾鍗科技
 
PDF
TomcatCon: from a cluster to the cloud
Jean-Frederic Clere
 
PPTX
Hunting Performance Problems in Node.js and beyond
Daniel Khan
 
PDF
The origin: Init (compact version)
Tzung-Bi Shih
 
PDF
curl --http3 cheatsheet
Naoto MATSUMOTO
 
PDF
Deploying Prometheus stacks with Juju
J.J. Ciarlante
 
DOCX
Cacti安装手册
Yiwei Ma
 
PDF
Gameboy emulator in rust and web assembly
Yodalee
 
PDF
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
Takashi Yamamoto
 
PPTX
Webinar: Building Embedded Applications from QtCreator with Docker
Burkhard Stubert
 
PDF
Investigation report on 64 bit support and some of new features in aosp master
hidenorly
 
PDF
OpenWRT development solutions - Free wireless router product development
Paul Dao
 
PDF
A Close Look at ARM Code Size
Samsung Open Source Group
 
PDF
GPU Programming on CPU - Using C++AMP
Miller Lee
 
PDF
Investigation report on 64 bit support in Android Open Source Project
hidenorly
 
PDF
20141102 VyOS 1.1.0 and NIFTY Cloud New Features
雄也 日下部
 
PDF
機器學習應用於蔬果辨識
Kobe Yu
 
PDF
A Deep Dive into QtCanBus
Burkhard Stubert
 
WebRTC と Native とそれから、それから。
tnoho
 
Tiny ML for spark Fun Edge
艾鍗科技
 
TomcatCon: from a cluster to the cloud
Jean-Frederic Clere
 
Hunting Performance Problems in Node.js and beyond
Daniel Khan
 
The origin: Init (compact version)
Tzung-Bi Shih
 
curl --http3 cheatsheet
Naoto MATSUMOTO
 
Deploying Prometheus stacks with Juju
J.J. Ciarlante
 
Cacti安装手册
Yiwei Ma
 
Gameboy emulator in rust and web assembly
Yodalee
 
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
Takashi Yamamoto
 
Webinar: Building Embedded Applications from QtCreator with Docker
Burkhard Stubert
 
Investigation report on 64 bit support and some of new features in aosp master
hidenorly
 
OpenWRT development solutions - Free wireless router product development
Paul Dao
 
A Close Look at ARM Code Size
Samsung Open Source Group
 
GPU Programming on CPU - Using C++AMP
Miller Lee
 
Investigation report on 64 bit support in Android Open Source Project
hidenorly
 
20141102 VyOS 1.1.0 and NIFTY Cloud New Features
雄也 日下部
 
機器學習應用於蔬果辨識
Kobe Yu
 
A Deep Dive into QtCanBus
Burkhard Stubert
 

Similar to Elastic network of things with mqtt and micro python (20)

PDF
IoT: Internet of Things with Python
Lelio Campanile
 
PDF
Using Python for IoT: a return of experience, Alexandre Abadie
Pôle Systematic Paris-Region
 
PDF
Python for IoT, A return of experience
Alexandre Abadie
 
PDF
Lecture1 - Introduction-MCU-MPU-EMBEDDED.pdf
bachbuissrr
 
PPTX
IOT BASED SYSTEM DESIGN
AbhishekBhat36
 
PPTX
Nodemcu and IOT.pptx
DixonSunny2
 
PPTX
Null mumbai-iot-workshop
Nitesh Malviya
 
PDF
SDARPiBot - VLES'16
Arun Joseph
 
PDF
Pradeep_Embedded
pradeep22kumark
 
PDF
Getting Started with Embedded Python: MicroPython and CircuitPython
Ayan Pahwa
 
PPTX
Python urllib
udhayakumarc1
 
PDF
Micropython for the iot
Jacques Supcik
 
PDF
MQTT – protocol for yours IoT
Miroslav Resetar
 
PDF
Kamery, światło, akcja!
Matthias Hryniszak
 
PDF
Quest for a low powered home hub 120522
Paul Tanner
 
PDF
IoT Development from Prototype to Production
Mender.io
 
PDF
Gettiing Started with IoT using Raspberry Pi and Python
Martin Christen
 
PDF
Road to Republic of IoT - IoT Technologies & Machine Learning
Andri Yadi
 
PPTX
Oop2018 tutorial-stal-mo2-io t-arduino-en
Michael Stal
 
PDF
IoT Intro and Demo
Albert Suwandhi
 
IoT: Internet of Things with Python
Lelio Campanile
 
Using Python for IoT: a return of experience, Alexandre Abadie
Pôle Systematic Paris-Region
 
Python for IoT, A return of experience
Alexandre Abadie
 
Lecture1 - Introduction-MCU-MPU-EMBEDDED.pdf
bachbuissrr
 
IOT BASED SYSTEM DESIGN
AbhishekBhat36
 
Nodemcu and IOT.pptx
DixonSunny2
 
Null mumbai-iot-workshop
Nitesh Malviya
 
SDARPiBot - VLES'16
Arun Joseph
 
Pradeep_Embedded
pradeep22kumark
 
Getting Started with Embedded Python: MicroPython and CircuitPython
Ayan Pahwa
 
Python urllib
udhayakumarc1
 
Micropython for the iot
Jacques Supcik
 
MQTT – protocol for yours IoT
Miroslav Resetar
 
Kamery, światło, akcja!
Matthias Hryniszak
 
Quest for a low powered home hub 120522
Paul Tanner
 
IoT Development from Prototype to Production
Mender.io
 
Gettiing Started with IoT using Raspberry Pi and Python
Martin Christen
 
Road to Republic of IoT - IoT Technologies & Machine Learning
Andri Yadi
 
Oop2018 tutorial-stal-mo2-io t-arduino-en
Michael Stal
 
IoT Intro and Demo
Albert Suwandhi
 
Ad

Recently uploaded (20)

PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Ad

Elastic network of things with mqtt and micro python