07/05/68
MQTT with Node-Red
for Data Logging
Internet of Things
What is data logging?
Data logging is the automated
process of capturing and
storing measurements from
sensors or systems at regular
intervals for later analysis and
decision-making.
1
07/05/68
Key points for Engineers:
• Involves sensors or instruments
• Data is recorded continuously or at
set intervals
• Stored in a digital format, often in a
microcontroller’s memory, SD card,
cloud, or PC.
• Used in experiments, industrial
systems, IoT, automotive, and more.
Data Logging with Node-Red
• File ESP32 (Sensor Node)▸ Reads data from sensors
• Sends data using MQTT protocol: Common broker: HiveMQ,
Mosquitto
• Node-RED Subscribes to MQTT topic and receives sensor data
• Can visualize, process, or forward data in real time
• Prepares data for storage Write to File
• Node-RED saves data to a local .txt, .csv, or .json file
• Enables later use for plotting, analysis, or reporting
2
07/05/68
IoT Data Logging
CSV
3
07/05/68
Example 1
• Analog data signal read by ESP32
• ESP32 public data via Wi-Fi with MQTT
Protocol to broker
• Node-Red subscript to data topic and
display
• Node-Red Function Node add time stamp to
data and prepare data to write into CSV
(Comma Separated Value) file format
• User can specify start/stop logging data
manually or can set number of data will be
record
How Function Node JavaScript Works
4
07/05/68
Node-Red Variables
Handel Stat/Stop or Count Logging
10
5
07/05/68
Logging
11
Extract Data
and Prepare
Date and
Time
12
6
07/05/68
Construct
CSV line
and
Add Header
13
Log
Count
14
7
07/05/68
Example 2
• Two Analog data signal read by ESP32
• ESP32 public data via Wi-Fi with MQTT
Protocol to broker
• Node-Red subscript to data topics and
display
• Joint Node: Joint two data into one
• Function Node: Add time stamp to data and
prepare data to write into CSV (Comma
Separated Value) file format
• User can specify start/stop logging data
manually or can set number of data will be
record
15
Function Node JavaScript:
✅ Add local date and time
✅ Build a CSV line with header
✅ Combine temperature and
humidity (joined from MQTT)
✅ Make it ready to write to file
16
8
07/05/68
Code
17
Code
18
9
07/05/68
Code
19
Code
20
10
07/05/68
Code
21
Quiz
22
11
07/05/68
CSV
23
Quiz
24
12