Table of Contents
The Grafana + InfluxDB stack is the gold standard for IoT data visualisation. InfluxDB handles time-series data storage with built-in downsampling and retention policies, while Grafana transforms that data into beautiful, interactive dashboards. This combination is used by thousands of IoT deployments worldwide and runs entirely on your own hardware.
Why Grafana and InfluxDB for IoT
Time-series databases like InfluxDB are purpose-built for IoT sensor data:
- InfluxDB: Stores billions of timestamped data points efficiently with automatic compression
- Grafana: Visualises data from any source with 50+ panel types and templating
- Together: Query weeks of sensor data and render it in milliseconds
- Cost: Both are open-source. Run on a ₹500/month VPS or a Raspberry Pi
Installing InfluxDB on Ubuntu
# Add InfluxDB repository (Ubuntu/Debian)
wget -q https://repos.influxdata.com/influxdata-archive_compat.key
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
sudo apt update && sudo apt install -y influxdb2
# Start and enable
sudo systemctl start influxdb
sudo systemctl enable influxdb
# Access setup at http://localhost:8086
# Create org: 'zbotic', bucket: 'iot_sensors', retention: 30d
Setting Up Grafana
# Add Grafana repository
sudo apt install -y apt-transport-https software-properties-common
wget -q -O - https://apt.grafana.com/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/grafana.gpg
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update && sudo apt install -y grafana
# Start and enable
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
# Access at http://localhost:3000
# Default login: admin / admin
Sensors for Data Visualisation
Designing Your Data Schema
Design your InfluxDB schema for efficient querying:
// InfluxDB line protocol format:
// measurement,tag1=val1,tag2=val2 field1=val1,field2=val2 timestamp
// Example data points:
sensors,device=esp32-01,location=mumbai temperature=32.5,humidity=65.2 1711900800000000000
sensors,device=esp32-02,location=pune temperature=28.1,humidity=72.8 1711900800000000000
// Best practices:
// - Tags: device_id, location, sensor_type (indexed, for filtering)
// - Fields: temperature, humidity, pressure (not indexed, for values)
// - Measurement: group related sensors (sensors, energy, air_quality)
Sending ESP32 Data to InfluxDB
Send data from ESP32 to InfluxDB using HTTP POST:
#include
#include
#include
const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASSWORD";
const char* influxUrl = "http://YOUR_SERVER:8086/api/v2/write?org=zbotic&bucket=iot_sensors&precision=s";
const char* influxToken = "YOUR_INFLUXDB_TOKEN";
#define DHT_PIN 4
DHT dht(DHT_PIN, DHT22);
void sendToInflux() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (isnan(temp) || isnan(hum)) return;
HTTPClient http;
http.begin(influxUrl);
http.addHeader("Authorization", String("Token ") + influxToken);
http.addHeader("Content-Type", "text/plain");
// Line protocol format
String payload = "sensors,device=esp32-01,location=mumbai ";
payload += "temperature=" + String(temp, 1);
payload += ",humidity=" + String(hum, 1);
int httpCode = http.POST(payload);
Serial.printf("InfluxDB response: %dn", httpCode);
http.end();
}
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
Serial.println("Connected!");
}
void loop() {
sendToInflux();
delay(30000); // Every 30 seconds
}
Building Grafana Dashboards
Create powerful dashboards in Grafana:
- Add InfluxDB as a data source (Settings → Data Sources → InfluxDB)
- Use Flux query language for InfluxDB 2.x
- Create panels: time series for trends, stat for current values, gauge for limits
- Use variables for dynamic device selection
// Flux query for temperature over last 24 hours
from(bucket: "iot_sensors")
|> range(start: -24h)
|> filter(fn: (r) => r._measurement == "sensors")
|> filter(fn: (r) => r._field == "temperature")
|> filter(fn: (r) => r.location == "mumbai")
|> aggregateWindow(every: 5m, fn: mean)
Alerting and Notifications
Set up alerts for critical conditions:
- Grafana Alerting: Set thresholds on any panel — alert when temperature exceeds 50 degrees Celsius
- Notification channels: Email, Telegram, Slack, PagerDuty, webhooks
- InfluxDB tasks: Run scheduled Flux scripts for data processing and anomaly detection
Recommended Product
BME280 Environmental Sensor (Temperature, Humidity, Barometric Pressure)
Frequently Asked Questions
Can Grafana and InfluxDB run on Raspberry Pi?
Yes, both run on Raspberry Pi 4 (4 GB recommended). Performance is adequate for up to 50 devices with moderate data rates. For larger deployments, use a dedicated server.
How much storage does InfluxDB need for IoT?
A single sensor sending data every 30 seconds uses approximately 50 MB per year in InfluxDB. With 20 sensors, expect 1 GB per year. InfluxDB compresses time-series data very efficiently.
Is there a cloud-hosted option?
Yes, InfluxDB Cloud offers a free tier with 30-day retention. Grafana Cloud offers a free tier with 10,000 metrics. Both have servers in multiple regions, though not yet in India.
What is the difference between InfluxDB and Prometheus?
InfluxDB uses push-based ingestion (devices send data). Prometheus uses pull-based collection (server scrapes endpoints). For IoT with ESP32 devices, InfluxDB’s push model is more natural and easier to implement.
{“@context”: “https://schema.org”, “@type”: “FAQPage”, “mainEntity”: [{“@type”: “Question”, “name”: “Can Grafana and InfluxDB run on Raspberry Pi?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “Yes, both run on Raspberry Pi 4 (4 GB recommended). Performance is adequate for up to 50 devices with moderate data rates. For larger deployments, use a dedicated server.”}}, {“@type”: “Question”, “name”: “How much storage does InfluxDB need for IoT?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “A single sensor sending data every 30 seconds uses approximately 50 MB per year in InfluxDB. With 20 sensors, expect 1 GB per year. InfluxDB compresses time-series data very efficiently.”}}, {“@type”: “Question”, “name”: “Is there a cloud-hosted option?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “Yes, InfluxDB Cloud offers a free tier with 30-day retention. Grafana Cloud offers a free tier with 10,000 metrics. Both have servers in multiple regions, though not yet in India.”}}, {“@type”: “Question”, “name”: “What is the difference between InfluxDB and Prometheus?”, “acceptedAnswer”: {“@type”: “Answer”, “text”: “InfluxDB uses push-based ingestion (devices send data). Prometheus uses pull-based collection (server scrapes endpoints). For IoT with ESP32 devices, InfluxDB’s push model is more natural and easier to implement.”}}]}
Ready to Build Your IoT Project?
Browse our complete collection of ESP32 boards, sensors, and IoT components. Fast shipping across India with technical support.
Add comment