%3CLINGO-SUB%20id%3D%22lingo-sub-1236022%22%20slang%3D%22en-US%22%3EMicro%20Python%20on%20ESP32%20to%20send%20telemetry%20to%20Azure%20IoT%20Hub%20with%20MQTT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1236022%22%20slang%3D%22en-US%22%3E%3CP%3EWe%2C%20recently%2C%20published%20a%20sample%20of%20code%20using%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2FIoTMQTTSample%2Ftree%2Fmaster%2Fsrc%2FMicroPython%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMQTT%20with%20Micro%20Python%20on%20ESP32%3C%2FA%3E.%20ESP%20Board%20can%20run%20%3CA%20href%3D%22https%3A%2F%2Fdocs.micropython.org%2Fen%2Flatest%2Fesp32%2Fquickref.html%23networking%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emicro%20Python%3C%2FA%3E%2C%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.micropython.org%2Fen%2Flatest%2Fesp32%2Ftutorial%2Fintro.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eesp%20tool%20to%20flash%20a%20MicroPython%3C%2FA%3E%20binary%20on%20your%20board%2C%20play%20with%20interactive%20Python%20from%20the%20board%20connected%20via%20COM%20port.%3C%2FP%3E%3CP%3EIn%20this%20sample%2C%20we%20use%20picocom%20to%20monitor%20and%20trace%20execution%20on%20the%20board%20from%20the%20WSL%20(Windows%20Subsystem%20Linux).%20We%20also%20use%20rshell%20to%20allow%20copying%20files%20from%20your%20system%20to%20the%20board.%20Once%20micro%20python%20is%20installed%20on%20your%20board%2C%20it%20executes%20at%20boot%20time%2C%20boot.py%20and%20then%20main.py%20automatically.%20Use%20boot.py%20to%20initiate%20the%20Wi-Fi%20connection.%20In%20the%20main.py%20we%20use%20a%20MQTT%20client%20library%20to%20send%20telemetry%20message%20to%20Azure%20IoT%20Hub%20(and%20receiving%20message%20from%20the%20cloud)%3C%2FP%3E%3CP%3EEnjoy%20this%20sample%2C%20and%20open%20issue%20or%20propose%20PR%20if%20you%20hit%20problem%20with%20this%20sample%20or%20want%20to%20enrich%20it.%3C%2FP%3E%3CP%3EHappy%20coding%3C%2FP%3E%3CP%3EEric%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1236022%22%20slang%3D%22en-US%22%3E%3CP%3EInterested%20by%20Micro%20Python%3F%20Check%20this%20new%20sample%20on%20how%20to%20connect%20Azure%20IoT%20Hub%20with%20MQTT%20from%20Micro%20Python%20running%20on%20ESP32.%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22micropython.JPG%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F177842i8A767F9F9E0D0207%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22micropython.JPG%22%20alt%3D%22micropython.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1236022%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EESP32%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicroPython%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMQTT%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1938924%22%20slang%3D%22fr-FR%22%3ERe%3A%20Micro%20Python%20on%20ESP32%20to%20send%20telemetry%20to%20Azure%20IoT%20Hub%20with%20MQTT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1938924%22%20slang%3D%22fr-FR%22%3E%3CP%3Ecan%20you%20please%20share%20the%20sample%20code%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1941656%22%20slang%3D%22en-US%22%3ERe%3A%20Micro%20Python%20on%20ESP32%20to%20send%20telemetry%20to%20Azure%20IoT%20Hub%20with%20MQTT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1941656%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20agrebianis%2C%3C%2FP%3E%0A%3CP%3EThe%20code%20is%20available%20in%20the%20github%20repo%20mentioned%20in%20the%20first%20line%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2FIoTMQTTSample%2Ftree%2Fmaster%2Fsrc%2FMicroPython%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMQTT%20with%20Micro%20Python%20on%20ESP32%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EHave%20a%20look%20at%20the%20main.py%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2FIoTMQTTSample%2Fblob%2Fmaster%2Fsrc%2FMicroPython%2Fmain.py%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EIoTMQTTSample%2Fmain.py%20at%20master%20%C2%B7%20Azure-Samples%2FIoTMQTTSample%20(github.com)%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

We, recently, published a sample of code using MQTT with Micro Python on ESP32. ESP Board can run micro Python, use the esp tool to flash a MicroPython binary on your board, play with interactive Python from the board connected via COM port.

In this sample, we use picocom to monitor and trace execution on the board from the WSL (Windows Subsystem Linux). We also use rshell to allow copying files from your system to the board. Once micro python is installed on your board, it executes at boot time, boot.py and then main.py automatically. Use boot.py to initiate the Wi-Fi connection. In the main.py we use a MQTT client library to send telemetry message to Azure IoT Hub (and receiving message from the cloud)

Enjoy this sample, and open issue or propose PR if you hit problem with this sample or want to enrich it.

Happy coding

Eric

2 Comments
Occasional Visitor

can you please share the sample code ?

 

thank you

Microsoft

Hi agrebianis,

The code is available in the github repo mentioned in the first line: MQTT with Micro Python on ESP32.

Have a look at the main.py IoTMQTTSample/main.py at master · Azure-Samples/IoTMQTTSample (github.com)