ESP32
HardwareEspressif microcontroller with Wi-Fi and Bluetooth built into the chip.
Unlike an Arduino Uno, which needs a shield to connect to a network, the ESP32 already includes the radio in the chip. The original line uses two Xtensa cores; newer families (C3, C6) use RISC-V. For automation, the important part is the peripherals: UART for RS-485, SPI and I²C for modules, ADC for analog signals, and GPIOs for digital inputs and outputs.
Wi-FiBluetoothGPIOUARTSPII²CADC
C
LanguageLow-level language in which the official ESP32 framework is written.
C provides direct access to the chip's memory and registers, without intermediate layers that consume execution time. It is the language of ESP-IDF, Espressif's official SDK. When you need fine control of timing or memory—the typical case in industrial firmware—the code eventually ends up in C.
ESP-IDFpointerslow level
C++
LanguageAn extension of C with classes and objects; it is the language of Arduino Core.
Almost every valid C program is also valid C++, so the two coexist in the same project. C++ adds organization: grouping a sensor, its pins and its methods in a class instead of spreading global variables around. Arduino Core for ESP32 is C++, which is why you write `Serial.begin()` instead of calling the UART driver by hand.
Arduino Coreclasseslibraries
Arduino
FrameworkAn open platform that simplified access to microcontrollers—and whose API runs on the ESP32.
Arduino began as a board (the Uno, an 8-bit AVR without networking), but what is used here is another part of it: Arduino Core for ESP32, a compatibility layer that lets you program Espressif's chip with the Arduino API—`setup()`, `loop()`, `digitalWrite()`, `Serial`. It is built on ESP-IDF itself. The advantage is the huge library ecosystem; the cost is that the abstraction hides details that, in industrial firmware, you will eventually need to see. The two coexist: you can call ESP-IDF functions from an Arduino project.
Arduino Coresetup() and loop()Arduino IDElibrariesESP-IDF
VS Code
ToolMicrosoft's free code editor, used as the foundation of the environment.
On its own it is just an editor—the extensions are what turn it into a firmware environment. This is where you write code, navigate files, use the debugger and open the terminal. The historical alternative is Arduino IDE, which is simpler but much more limited for projects with many files.
editorextensionsdebugger
PlatformIO
ToolA VS Code extension that manages the compiler, libraries and board flashing.
It downloads the right toolchain, resolves libraries and flashes the firmware. The entire project is described in a `platformio.ini` file: which board, which framework (Arduino or ESP-IDF), which libraries and which versions. This makes builds reproducible—another person clones the repository and gets exactly the same binary.
platformio.initoolchainreproducible build
OTA
PracticeOver-The-Air: update firmware over the network, without a USB cable or visiting the equipment.
With a board on the bench, USB is enough. With thirty gateways spread across a plant, climbing a ladder to flash each one is not an option. The ESP32 stores two application partitions: it writes the new image to the idle partition, verifies its integrity and only then points the boot to it. If the new version does not confirm that it started correctly, the bootloader returns to the previous one—that rollback is what separates a remote update from an inaccessible device.
partitionsrollbackArduinoOTAElegantOTA
MQTT
ProtocolA lightweight messaging protocol using publish/subscribe, with a broker in the middle.
Devices do not talk directly to one another: they publish messages to topics (such as `factory/line1/temperature`) on a central server, the broker, and anyone interested subscribes to that topic. This decouples the producer from the consumer. It was designed for poor links, which matters on the factory floor: it has delivery levels (QoS) and Last Will, a message the broker publishes by itself when a device disappears without warning.
brokertopicsQoSLast WillMosquitto
Broker
InfrastructureThe server in the middle of MQTT: everything passes through it, and nothing passes without it.
The ESP32 never talks directly to the supervisor—it publishes to the broker, and the broker delivers to whoever subscribed to the topic. This makes it possible to replace the data consumer without touching the firmware. The broker also stores state: the retained message (the last value of a topic, delivered immediately to a newcomer) and the persistent session (messages queued while a client is offline). Authentication and topic permissions—who may publish and who may only read—live there as well.
MosquittoEMQXretained messagepersistent sessionTLSACL
REST API
ProtocolAn HTTP interface in which each address is a resource and the client asks when it needs something.
It is a question-and-answer model: someone calls `GET /api/temperature` and receives JSON in return. The difference from MQTT is who takes the initiative—in REST the client pulls the data when needed; in MQTT the broker pushes it as soon as it changes. In practice the two coexist: MQTT for continuous telemetry, REST for on-demand queries, configuration and integration with systems that already speak HTTP. The ESP32 plays both roles: it serves its own endpoints (that is how the embedded configuration portal works) and consumes external APIs.
HTTPJSONGET and POSTendpointESPAsyncWebServer
RS-485
HardwareAn electrical standard for carrying signals hundreds of meters in a noisy environment.
It is not a protocol: it is only the physical medium and says nothing about message format. The trick is differential transmission—the data travels as the voltage difference between two wires in a twisted pair, so noise that enters both is canceled at the receiver. It supports multiple devices on the same pair in a bus topology, with 120 Ω resistors at both ends to prevent reflection. The ESP32 does not speak RS-485 directly: it needs a transceiver, such as the MAX485, between the UART and the line.
twisted pairdifferentialMAX485120 Ω terminationhalf-duplex
Modbus
ProtocolA 1979 industrial protocol understood by practically every field device.
It works by question and answer: a master asks and a slave responds—no slave speaks on its own. Data lives in numbered registers, read and written through function codes. It comes in two forms: RTU, binary over serial (typically RS-485), and TCP, the same model over Ethernet. Its strength is ubiquity; its weakness is that it has no semantics at all—register 40001 is just a 16-bit number, and what it means is in the manufacturer's manual, not in the protocol.
master/slaveregistersRTUTCPfunction codes
OPC UA
ProtocolA modern industrial standard that transports data together with its meaning.
Where Modbus delivers an isolated number, OPC UA delivers a named object with a type, unit and description—the server publishes an information model that the client navigates. Security is part of the specification: certificates, authentication and encryption, rather than relying on the network being trusted. The cost is weight: it is much heavier than Modbus, so it usually appears from the supervisory layer upward, not in the simplest sensor.
IEC 62541information modelcertificatesclient/server
SCADA
SystemThe supervisory layer: it gathers field data, displays it, raises alarms and keeps history.
Supervisory Control and Data Acquisition. It is the system that talks to PLCs and gateways, draws mimic screens, raises alarms when a value leaves its range and keeps history for later analysis. Do not confuse it with HMI: an HMI is local and attached to a machine; SCADA sees the whole plant and normally runs on a server. For the ESP32, SCADA is usually the final destination of the data—directly or through an MQTT broker.
mimic screensalarmshistoryHMISCADA
IIoT
ContextIndustrial Internet of Things: applying IoT to the factory floor.
The difference from consumer IoT is not the technology but the requirement. Here data comes from PLCs, energy meters and process sensors, often through older protocols such as Modbus, and must reach supervisors and databases without failures. This is called OT/IT integration: connecting the operations network to the corporate network without compromising either one.
ModbusSCADAOPC UAOT/ITtelemetry