The ESP8266 is an 80–160 MHz Tensilica L106 SoC with a full 802.11 b/g/n WiFi stack built in. The ESP-01 module — the smallest form factor — costs about 9 RON per piece at Optimus Digital. Three of them, a Raspberry Pi acting as an MQTT broker, a handful of DHT11 sensors and some passive components add up to under 120 RON for a three-node indoor temperature and humidity mesh.
This article covers the hardware shopping list, programming the ESP-01 with Arduino IDE via a USB-UART adapter, writing a minimal MQTT publish sketch, setting up the Mosquitto broker on the Raspberry Pi, and subscribing to the data stream with a Python script.
The ESP-01 and its limitations
The ESP-01 breaks out only two GPIO pins (GPIO0 and GPIO2) alongside the UART lines (TX, RX), power (3.3 V) and ground. That is enough for a single-wire DHT sensor or a Dallas DS18B20 temperature probe, but not enough for multi-sensor arrays. For those, the ESP-12E module (used on the NodeMCU and Wemos D1 Mini boards) exposes 11 usable GPIOs and costs about 16 RON at Robofun — a better choice if you plan to expand later.
The ESP-01 draws up to 250 mA during WiFi transmission bursts. A USB power bank or a 3.3 V linear regulator powered from a 5 V source must handle this peak. The AMS1117-3.3 is the standard choice: it is stocked at Elecpro for 1.20 RON per piece and handles up to 800 mA continuous.
Shopping list (3-node build)
- 3 × ESP-01 module — 27 RON total at Optimus Digital
- 3 × DHT11 temperature and humidity sensor — 9 RON total at Robofun
- 3 × AMS1117-3.3 voltage regulator — 3.60 RON total at Elecpro
- 3 × 10 µF electrolytic capacitor (decoupling on the 3.3 V rail) — 2 RON total
- 3 × 100 nF ceramic capacitor — 1.20 RON total
- 1 × USB-to-UART adapter (CH340 or CP2102) — 12 RON at Optimus Digital, reusable across all nodes
- 1 × full-size breadboard — 15 RON at Robofun
- Jumper wire kit — 8 RON at Optimus Digital
- Raspberry Pi 3 B or 4 (if you already have one, cost is zero; otherwise budget 180 RON)
Total without the Pi: approximately 78 RON. With a Pi: approximately 258 RON.
Programming the ESP-01 with Arduino IDE
Install the ESP8266 board package in Arduino IDE by adding http://arduino.esp8266.com/stable/package_esp8266com_index.json to File → Preferences → Additional Boards Manager URLs. Open the Boards Manager, search for esp8266 and install version 3.x.
To upload firmware to the ESP-01, connect the USB-UART adapter as follows: RX on the adapter to TX on the ESP-01, TX on the adapter to RX on the ESP-01, GND to GND and 3.3 V to VCC. Pull GPIO0 low (connect to GND) before applying power to enter the bootloader. Select Generic ESP8266 Module as the board and set the upload speed to 115200 baud.
A minimal MQTT publish sketch
Install the PubSubClient library via the Arduino Library Manager (search for PubSubClient by Nick O'Leary).
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* mqttHost = "192.168.1.200";
const int mqttPort = 1883;
const char* nodeId = "node01";
DHT dht(2, DHT11);
WiFiClient wifiClient;
PubSubClient mqtt(wifiClient);
void connectWifi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
}
void connectMqtt() {
while (!mqtt.connected()) {
mqtt.connect(nodeId);
delay(500);
}
}
void setup() {
dht.begin();
connectWifi();
mqtt.setServer(mqttHost, mqttPort);
connectMqtt();
}
void loop() {
mqtt.loop();
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (!isnan(temperature)) {
char payload[32];
snprintf(payload, sizeof(payload), "%.1f", temperature);
mqtt.publish("sensors/node01/temperature", payload);
snprintf(payload, sizeof(payload), "%.1f", humidity);
mqtt.publish("sensors/node01/humidity", payload);
}
delay(30000);
}
Replace nodeId with node02 and node03 for the other two ESP-01 modules, and update the topic strings accordingly. The 30-second interval keeps the WiFi radio active but reduces the duty cycle to about 5%, which matters for battery-powered nodes.
Setting up Mosquitto on the Raspberry Pi
On Raspberry Pi OS, install Mosquitto with:
sudo apt update && sudo apt install -y mosquitto mosquitto-clients
By default, Mosquitto 2.x requires explicit configuration to allow unauthenticated connections from the LAN. Create /etc/mosquitto/conf.d/local.conf with:
listener 1883
allow_anonymous true
Then restart the service:
sudo systemctl restart mosquitto
Verify that Node 1 is publishing by running on the Pi:
mosquitto_sub -h localhost -t "sensors/#" -v
You should see lines such as sensors/node01/temperature 22.5 every 30 seconds once the ESP-01 connects.
Subscribing and logging with Python
Install the paho-mqtt library on the Pi:
pip3 install paho-mqtt
A minimal logger that appends CSV rows to a file:
import paho.mqtt.client as mqtt
import csv, time, os
LOG_FILE = "/home/pi/sensors.csv"
def on_message(client, userdata, msg):
with open(LOG_FILE, "a", newline="") as f:
writer = csv.writer(f)
writer.writerow([time.strftime("%Y-%m-%d %H:%M:%S"), msg.topic, msg.payload.decode()])
client = mqtt.Client()
client.on_message = on_message
client.connect("localhost", 1883)
client.subscribe("sensors/#")
client.loop_forever()
Run it with python3 logger.py & or configure it as a systemd service so it restarts automatically after reboots.
Range and interference notes
The ESP-01's PCB antenna is rated for about 40 m line-of-sight. In a typical Romanian apartment with concrete walls, expect 8–15 m through one or two walls before the RSSI drops below -80 dBm and connections become unstable. Placing nodes close to the access point or using a mesh router (such as those available in Altex's TP-Link Deco range) extends coverage without adding infrastructure complexity to the project.
Further reading
The Arduino ESP8266 documentation covers deep-sleep modes, OTA updates and the full WiFi API. The Mosquitto documentation describes TLS and username/password authentication for setups exposed outside the LAN.
Related on this resource: running Home Assistant on the same Raspberry Pi as the MQTT broker and using an Arduino Nano for GPIO-based sensor inputs that feed into the same network.