MakerSpace

Figure 1: This Arduino project logs data to an SQL database.
In most Arduino projects, devices use messaging protocols like Message Queuing Telemetry Transport (MQTT) [1] or custom dashboard platforms such as Arduino Cloud [2] or ThingsBoard [3] to talk to each other. While those two approaches offer excellent solutions for viewing short-term sensor data, they have limitations when used for long-term historical storage.
A common solution that supports historical storage is to connect MQTT brokers to datalogging packages like Node-RED, InfluxDB, or Grafana. Another approach is to install SQL drivers on the Arduino controllers and then pass sensor data directly to a database server. There are Arduino C/C++ libraries for MariaDB/ MySQL, Microsoft SQL, PostgreSQL and even local SQLite 3 databases. SQL-based solutions have some useful benefits such as:
• No intermediate storage is required
• Access raw historical data or aggregate calculations
• Write custom queries
• Use back-end views and procedures to minimize dashboard code
Depending on your project requirements, using an SQL server could be a good fit for your next Internet of Things (IoT) project.
Figure 2: The garage table stores sensor data and a timestamp. The thetime field will default to the current time when a new record is inserted.
This article presents a sensor project that connects Arduino modules to a MySQL/ MariaDB server (Figure 1). Dashboards showing current values and historical trend charts will be created using some SQL widgets in Node-RED.
SQL Libraries for Arduinos
There are a few C/ C++ SQL libraries to choose from. For this project, I was quite happy with Charles Bell’s MySQL Connector Arduino package [4]: I found it straightforward, and it has some good examples. This and the other SQL packages can be installed directly using the Arduino IDE’s library manager.
This story is from the #293/April 2025: Trojan Horse edition of Linux Magazine.
Start your 7-day Magzter GOLD free trial to access thousands of curated premium stories, and 9,000+ magazines and newspapers.
Already a subscriber ? Sign In
This story is from the #293/April 2025: Trojan Horse edition of Linux Magazine.
Start your 7-day Magzter GOLD free trial to access thousands of curated premium stories, and 9,000+ magazines and newspapers.
Already a subscriber? Sign In

MADDOG'S DOGHOUSE
Planning and community effort can help welcome Linux beginners online without precluding more advanced discussions.

Cash as Cash Can
Mike Schilli uses the YNAB tool to keep an eye on his finances. Until recently, YNAB didn't have a terminal Ul programmed in Go, but Mike delivers it here.

Innovator
Re-inventing the Ubuntu experience

Play video games natively on Linux Gaming Your Way
Bazzite, an immutable Linux distro adapted for gaming, lets you play your favorite video games on your PC, handheld, or home theater PC.

Installing mods on Steam Deck Steam Gems
The Steam Deck gaming console offers a galaxy of creative modifications for the games you love to play.

Zack's Kernel News
Chronicler Zack Brown reports on the latest news, views, dilemmas, and developments within the Linux kernel community.

System Monitoring
Mission Center, a graphical system monitor, groups all important system statuses in a compact, intuitive interface.

Exploring the Unbound DNS resolver Unbound
The Unbound DNS resolver offers comprehensive security and many other useful features.

Mix It Up
Solve Bash blind spots by embedding other scripting languages into your Bash scripts to get the features you need. Pete shows you solutions for floating-point math, charting, GUIs, and hardware integration.