element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Sending data from ESP32 [Arduino] to Node-RED and storing to InfluxDB using WebSocket
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oksbwn
  • Date Created: 1 Apr 2023 6:30 AM Date Created
  • Views 6816 views
  • Likes 5 likes
  • Comments 0 comments
  • esp32
  • tutorial
  • education
  • bi-directional
  • make
  • diy
  • node-red
  • getting started
  • basic
  • arduino
Related
Recommended

Sending data from ESP32 [Arduino] to Node-RED and storing to InfluxDB using WebSocket

oksbwn
oksbwn
1 Apr 2023

MQTT is a widely used protocol in IoT space, with low overhead and targeted towards constrained devices. However they are not real time and full-duplex. and when that is needed WebSocket can be an alternative. Moreover WebSocket can take more payload (w.r.t Size) then MQTT. I will not get into that detail of WS or MQTT there are lot of articles available. This post is going to be about using WS to exchange data between ESP32 and Node-RED. WS does not need any intermediary like a broker or so and is a 1:1 communication protocol.

1. WebSocket with Node-RED:

    Node-RED comes with Out of the Box support for WebSocket. You get WS in and Out nodes. In node is something that gives you incoming messages and out node, as you can assume, is used to write to the socket. 

image

The nodes can either be used as server or client. In this case we are going to use it as server. Both the cases you need to configure the nodes. To know more about how to use WS in Node-RED checkout the following video.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

2. Send data from ESP32 [Arduino] to Node-RED over WebSocket:

   To use WebSocket in Arduino, I have used ArduinoWebsockets(http://bit.ly/3LeAGVl) library. Also to parse JSON objects I have used ArduinoJson(http://bit.ly/3ZHI5Rs) library.  You can find the complete code here (https://github.com/WGLabz/Arduino-Node-RED-Websocket).  As of now the code simulates a Temperature and humidity sensor and send random values through WebSocket every x seconds, which is configurable, actually you can changes the code to set it from node-RED and persist it in Arduino. It also receives messages sent by Node-RED and if the message which is a JSON string ({data: 1 | 0}) with a data key which can have value 1 or 0, has data key then it changes the on-board LED status accordingly. 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

3. Storing data to InfluxDB from Node-RED

For timeseries data InfluxDB is an appropriate DB to use. Its also free to use. Node-RED by default does not support InfluxDB OOB. You need to install required libraries for that. I have used this one https://flows.nodered.org/node/node-red-contrib-influxdb. The data received from ESP32 is written to the InfluxDB database and can be queried and displayed in tools like Grafana or Node-RED dashboard. Here i am just storing the randomly generated Temperature and Humidity data to InfluxDB.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

I hope this help you in someway or other. You can find links to everything that I have used in the description of respective videos in YouTube. There are lot of links so am not posting here. 

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube