IOTHUB SOFTWARE · 04

Python for IoT Helper Servers

Python is useful as the middle layer between ESP devices, MQTT, notifications, and AI processing. It should be isolated, logged, and reproducible.

Installing Python hero image
Key TermsPythonpipterminalPATH

Python runs the middle server between ESP32 and AI. It is a programming language that reads almost like plain language. Nothing scary. Install it and move on.


Download

Go to python.org/downloads and click the yellow Download Python 3.x.x button. Any current version above 3.8 is fine.


Windows Install


Mac Install

Mac often uses python3 instead of python. In this series, read python as python3 on Mac when needed.

What Is pip?

pip installs Python packages. Think of it like an app store for Python.

bash
pip install package-name

For example, pip install flask installs Flask, a small web server package used later.


What Is the Terminal?

It is just a place where you type commands instead of clicking buttons. Do not be scared. We mostly use these three:

bash
python --version
pip install flask
python server.py

Checklist


When It Does Not Work

ProblemFix
python command not foundOn Windows, reinstall Python and check Add Python to PATH.
pip command not foundTry python -m pip --version.
Mac needs python3Normal on Mac. Use python3 instead.
Microsoft Store opensTurn off Python app execution aliases in Windows settings.

Python is operations code

Firmware should read sensors and publish data. Python is better suited for collecting device states, parsing MQTT messages, sending Telegram alerts, storing logs, and connecting to AI helpers.

Add logs from the beginning

At startup, log configuration path, service port, broker address, and token loading status. During runtime, log MQTT connection, parsing failures, notification results, and tracebacks.

Use a virtual environment

Installing packages globally makes projects interfere with each other. A venv keeps dependencies local to one IoT service and makes migration easier.

command
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Runtime checks