Monitor Remote IoT Sensor Data with MQTT & InfluxDB via n8n

This workflow automates capturing temperature and humidity data from a remote ESP32 sensor via MQTT and stores it efficiently in InfluxDB. It solves monitoring challenges by ensuring clean data ingestion and real-time updates using n8n automation.
mqttTrigger
code
httpRequest
+1
Workflow Identifier: 1607
NODES in Use: Sticky Note, MQTT Trigger, Code, HTTP Request
Monitor IoT sensor data with MQTT and n8n

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Workflow Does

This workflow listens to MQTT messages from a DHT22 sensor on the topic “wokwi-weather.”
It takes the incoming JSON data, checks it for correct temperature and humidity values, and changes it into a format InfluxDB needs.
Then, it sends this data to an InfluxDB database for storage.
The workflow stops bad or incomplete data from reaching the database.


Who Should Use This Workflow

This is for anyone who needs to save sensor data from an MQTT broker into InfluxDB.
Ideal for hobbyists or beginners monitoring environment data in places like greenhouses or small IoT projects.

No deep technical skills needed, the workflow handles data parsing and validation automatically.
Small errors or bad data are caught early to keep database clean.


Tools and Services Used

  • MQTT Broker (Mosquitto): Sends live sensor data from the DHT22.
  • n8n Automation Platform: Runs the workflow to process data.
  • DHT22 Sensor: Measures temperature and humidity.
  • InfluxDB v2: Saves time series sensor data with proper format.


Beginner Step-by-Step: How to Use This Workflow in n8n

Download and Import Workflow

  1. Click the Download button on this page to save the workflow file.
  2. Go to the n8n editor where the workflow will run.
  3. Click the Import from File option and select the downloaded file to load the workflow.

Configure Credentials and Settings

  1. Open the MQTT Trigger node and add your MQTT broker credentials.
  2. Make sure the topic matches your sensor topic, typically “wokwi-weather”.
  3. Open the HTTP Request node and fill in your InfluxDB Organization ID, bucket name, and API Key.
  4. If needed, update the InfluxDB URL to match your server location.

Test and Activate

  1. Trigger the workflow by sending a test MQTT message or waiting for live sensor data.
  2. Check the workflow result in n8n to confirm data parses and posts to InfluxDB.
  3. Toggle the workflow Active switch to put it into production mode.
  4. Ensure the MQTT broker and InfluxDB remain accessible while the workflow runs.

You may want to consider self-host n8n if running this workflow on a server.


Inputs, Processing, and Output

Inputs

  • MQTT messages on topic “wokwi-weather” containing sensor JSON strings.

Processing Steps

  • The MQTT Trigger catches new messages.
  • A Code node parses each JSON string.
  • The node validates that “temp” and “humidity” exist and are numbers.
  • If valid, the node formats data into InfluxDB line protocol.
  • An HTTP Request node sends the formatted line to InfluxDB.

Output

  • Clean sensor data stored in the InfluxDB bucket with timestamps.
  • Errors thrown in workflow if data is malformed or missing.


Edge Cases and Failures

  • If MQTT message is not valid JSON, the workflow throws an “Invalid JSON” error.
  • If JSON misses “temp” or “humidity” fields or they are not numbers, the workflow throws a “Missing or invalid humidity/temp” error.
  • If InfluxDB API token or URLs are wrong, HTTP errors like 401 appear.
  • MQTT connection failure causes no sensor data reception.

Handling these early prevents bad data from polluting the database.


Customizations Ideas

  • Change MQTT topic in the MQTT Trigger node to listen to other sensor feeds.
  • Edit the Code node to match your sensor’s JSON field names (like “temperature” instead of “temp”).
  • Add extra tags in the line protocol string to mark sensor location or type.
  • Update the HTTP request URL to send data to cloud-hosted InfluxDB.
  • Add error handling nodes or retry logic for resilience.


Summary

✓ Workflow listens to MQTT sensor messages, parses JSON data, validates values.

✓ Converts sensor data into InfluxDB line protocol format.

✓ Sends data to InfluxDB with authentication, preventing bad data storage.

→ Helps save time by automating sensor data storage.

→ Makes sure database only gets correct, usable data.


Monitor IoT sensor data with MQTT and n8n

Visit through Desktop to Interact with the Workflow.

Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.
Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

Frequently Asked Questions

The workflow receives MQTT data that is not a valid JSON string. The JSON parser in the Code node fails, leading to this error. Check the sensor or message publisher to send properly formatted JSON.
This happens if the API Key used in the HTTP Request node headers is missing, expired, or incorrect. Make a new API Key in InfluxDB with write permission and update the node headers with the exact key.
The MQTT Trigger node listens on the topic “wokwi-weather” and expects messages as JSON strings containing numeric fields named “temp” and “humidity”.
Yes. Update MQTT broker credentials and URL in the MQTT Trigger node. Also, change the InfluxDB URL and tokens in the HTTP Request node to point to cloud services.

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.