Jump to content
Electronics-Lab.com Community

Search the Community

Showing results for tags 'node red'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Electronics Forums
    • Projects Q/A
    • Datasheet/Parts requests
    • Electronic Projects Design/Ideas
    • Power Electronics
    • Service Manuals
    • Theory articles
    • Electronics chit chat
    • Microelectronics
    • Electronic Resources
  • Related to Electronics
    • Spice Simulation - PCB design
    • Inventive/New Ideas
    • Mechanical constructions/Hardware
    • Sell/Buy electronics - Job offer/requests
    • Components trade
    • High Voltage Stuff
    • Electronic Gadgets
  • General
    • Announcements
    • Feedback/Comments
    • General
  • Salvage Area

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Yahoo


Skype


Location


Interests

Found 4 results

  1. How to Track the ISS Location with Node-RED Node-RED is a visual programming tool that allows you to create flows of data and logic using nodes. In this article, we will use Node-RED to track the location of the International Space Station (ISS) and display it on a world map. What You Need To follow this tutorial, you will need the following: A computer with Node-RED installed. You can download and install Node-RED from here. An internet connection to access the ISS location API and the world map node. Two Node-RED nodes: node-red-contrib-iss-location and node-red-contrib-web-worldmap. You can install them from the Node-RED palette or by running the following commands in your Node-RED user directory, typically ~/.node-red: npm install node-red-contrib-web-worldmap Get PCBs for Your Projects Manufactured You must check out PCBWAY for ordering PCBs online for cheap! You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Also, check out this useful blog on PCBWay Plugin for KiCad from here. Using this plugin, you can directly order PCBs in just one click after completing your design in KiCad. The Flow The flow we will create consists of four nodes: An inject node that triggers the flow every 10 seconds. An HTTP-request node that queries the ISS location API and returns the current latitude and longitude of the ISS. A function node that formats the location data into a message object that the world map node can use. A worldmap node that displays a world map and a marker for the ISS location. The flow looks like this: The Nodes Let’s take a closer look at each node and how to configure them. The Inject Node The inject node is used to trigger the flow at regular intervals. To configure it, double-click on it and set the following properties: Name: Every 10 seconds Repeat: interval Every: 10 seconds This will make the node send a timestamp message every 10 seconds. The HTTP Request Node The ISS location node is used to query the ISS location API and return the current latitude and longitude of the ISS. To configure it, double-click on it and set the following properties: Name: ISS Location URL: api.open-notify.org/iss-now.json This will make the node send a message object with the following properties: This node will return the following payload: the return payload contains thefollowing properties: latitude: a string indicating the current latitude of the ISS in degrees. longitude: a string indicating the current longitude of the ISS in degrees. The Function Node The function node is used to format the location data into a message object that the world map node can use. To configure it, double-click on the JSON node and set the following properties. Next, set the following properties on the change node: This will make the node send a message object with the same properties as the original message, except for the payload, which will be an object suitable for the world map node. Here is the final transformed payload that the map node can understand. The World Map Node The world map node displays a world map and a marker for the ISS location. To configure it, double-click on it and set the following properties: This will make the node display a world map widget on the dashboard, with various options to customize the view. The node will also listen for incoming messages with location data and display a marker on the map accordingly. The Result To see the result, deploy the flow and open the dashboard. You should see a world map with a blue globe icon indicating the current location of the ISS. The icon will move as the ISS orbits the Earth. You can also click on the icon to see the name and the coordinates of the ISS. Conclusion In this article, we have learned how to use Node-RED to track the location of the ISS and display it on a world map. We have used node-red-contrib-web-worldmap to query the ISS location API and display the map widget. We have also used a function node to format the location data into a message object that the world map node can use. We hope you have enjoyed this tutorial and learned something new. If you want to learn more about Node-RED and its nodes, you can check out these web pages: Node-RED node-red-contrib-iss-location (node) - Node-RED node-red-contrib-web-worldmap (node) - Node-RED Happy coding!
  2. Telegram is a popular messaging app that offers end-to-end encryption, cloud-based storage, and a variety of features for communication. One of these features is the ability to create and interact with bots, which are automated programs that can perform tasks or provide information. In this blog post, I will show you how to use Telegram bots to control your home automation system with Node-RED, a visual programming tool that allows you to connect and orchestrate devices, services, and APIs. Get PCBs For Your Projects Manufactured You must check out PCBWAY for ordering PCBs online for cheap! You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Also, check out this useful blog on PCBWay Plugin for KiCad from here. Using this plugin, you can directly order PCBs in just one click after completing your design in KiCad. 1. What You Need: To follow this tutorial, you will need: A Telegram account and a smartphone with the Telegram app installed. A Node-RED instance running on a device that can access your home automation system. You can use a Raspberry Pi, a computer, or a cloud service. For more information on how to install and run Node-RED, see here. The node-red-contrib-telegrambot node provides Telegram bot nodes for Node-RED. You can install it from the Node-RED palette manager or by running the following command in your Node-RED directory: npm install node-red-contrib-telegrambot A Telegram bot token is a unique identifier for your bot. You can create a bot and get its token by talking to the @BotFather bot on Telegram. For more details. A chat ID is a unique identifier for the chat between you and your bot. You can get your chat ID by sending a message to your bot. 2. How It Works: The basic idea is to use Node-RED to create a flow that receives messages from your Telegram bot, parses them to extract commands or queries, and then sends commands or responses back to your bot. The node-red-contrib-telegrambot node provides two main nodes for this purpose: the receiver node and the sender node. The receiver node listens for messages from your bot and outputs a message object with the following properties: msg.payload.chatId: The chat ID of the sender. msg.payload.type: The type of the message, such as “message”, “photo”, “location”, etc. msg.payload.content: The content of the message, such as a text string, a file ID, or an object with additional data. The sender node takes a message object as input and sends it to your bot. The message object should have the following properties: msg.payload.chatId: The chat ID of the recipient. msg.payload.type: The type of the message, such as “message”, “photo”, “location”, etc. msg.payload.content: The content of the message, such as a text string, a file ID, or an object with additional data. You can use other nodes in between the receiver and sender nodes to process the messages and perform actions on your home automation system. For example, you can use a switch node to route messages based on their type or content, a function node to write custom logic in JavaScript, or an HTTP request node to call external APIs. 3. A little recap of the previous blog: In the previous blog, we have seen how to use the telegram bot with node-red to trigger the temperature data. In this blog, we are going to see how to automate and trigger the Telegram bot to control the GPIO. 4. Telegram to Node-Red: In the last article, we have seen how to trigger the sensor readings from Node-Red to Telegram, now let's see how to trigger and get the sensor data from Telegram Bot. First, we need to use the telegram receiver node. And configure the node with your bot credentials. Then add a debug block. Next, just try to send some messages to your bot and look at the response in the debug console. Now, you can see your texts are coming under payload.content. So, we are going to filter the content then based on the content we are going to trigger the actions. Here are my complete blocks. In this, I have tried to filter the contents as Green, Red, Blue, Off, and Env. Based on the contents we are going to trigger the neo pixels with certain colors. Finally, just deploy the flow, open the telegram bot, and test out the connections. Let's try out the neo pixels. [ { "id": "eb8f9c0d054be30c", "type": "tab", "label": "Flow 2", "disabled": false, "info": "", "env": [] }, { "id": "ea63aa67.c972f", "type": "template", "z": "eb8f9c0d054be30c", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "{\"chatId\": 5379039379,\n\"type\":\"message\",\n\"content\":\"Temperature : {{payload}}, Humidity : {{humidity}}\"}", "output": "json", "x": 660, "y": 360, "wires": [ [ "9e00d0a7.d5ccf", "600063bd96d765e6" ] ] }, { "id": "9e00d0a7.d5ccf", "type": "debug", "z": "eb8f9c0d054be30c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 830, "y": 300, "wires": [] }, { "id": "600063bd96d765e6", "type": "telegram sender", "z": "eb8f9c0d054be30c", "name": "roboerto_bot", "bot": "ae1a60539b8e5308", "haserroroutput": true, "outputs": 2, "x": 830, "y": 380, "wires": [ [], [] ] }, { "id": "f2f9819ae972ae60", "type": "rpi-dht22", "z": "eb8f9c0d054be30c", "name": "", "topic": "rpi-dht22", "dht": "11", "pintype": 1, "pin": "7", "x": 500, "y": 380, "wires": [ [ "ea63aa67.c972f" ] ] }, { "id": "e4b8f2dd860a7973", "type": "telegram receiver", "z": "eb8f9c0d054be30c", "name": "", "bot": "ae1a60539b8e5308", "saveDataDir": "", "filterCommands": false, "x": 290, "y": 200, "wires": [ [ "ea58984a24ea493e" ], [] ] }, { "id": "ea58984a24ea493e", "type": "switch", "z": "eb8f9c0d054be30c", "name": "", "property": "payload.content", "propertyType": "msg", "rules": [ { "t": "eq", "v": "Green", "vt": "str" }, { "t": "eq", "v": "Red", "vt": "str" }, { "t": "eq", "v": "Off", "vt": "str" }, { "t": "eq", "v": "Blue", "vt": "str" }, { "t": "eq", "v": "Env", "vt": "str" }, { "t": "eq", "v": "Rainbow", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 6, "x": 450, "y": 140, "wires": [ [ "b410ed94340bb528" ], [ "13aa73e421c429c7" ], [ "4ed36e19be451327" ], [ "db816a1f10392614" ], [ "f2f9819ae972ae60" ], [] ] }, { "id": "b0edb6e1c2807920", "type": "rpi-neopixels", "z": "eb8f9c0d054be30c", "name": "Neo Pixel", "gpio": "18", "pixels": "8", "bgnd": "", "fgnd": "", "wipe": "60", "mode": "pixels", "rgb": "rgb", "brightness": "100", "gamma": true, "x": 660, "y": 100, "wires": [] }, { "id": "13aa73e421c429c7", "type": "function", "z": "eb8f9c0d054be30c", "name": "Red Led", "func": "\nmsg.payload = \"255,0,0\"\nreturn msg;\n\n\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 660, "y": 200, "wires": [ [ "b0edb6e1c2807920", "0d73aa1efdf96848" ] ] }, { "id": "b410ed94340bb528", "type": "function", "z": "eb8f9c0d054be30c", "name": "Green Led", "func": "\nmsg.payload = \"0,255,0\"\nreturn msg;\n\n\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 670, "y": 160, "wires": [ [ "b0edb6e1c2807920", "c173db3cc3868fe8" ] ] }, { "id": "4ed36e19be451327", "type": "function", "z": "eb8f9c0d054be30c", "name": "Off", "func": "\nmsg.payload = \"0,0,0\"\nreturn msg;\n\n\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 650, "y": 240, "wires": [ [ "b0edb6e1c2807920", "02e43d4dd4523371" ] ] }, { "id": "db816a1f10392614", "type": "function", "z": "eb8f9c0d054be30c", "name": "Blue Led", "func": "\nmsg.payload = \"0,0,255\"\nreturn msg;\n\n\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 660, "y": 280, "wires": [ [ "b0edb6e1c2807920", "15dcd2ff9b951c47" ] ] }, { "id": "c173db3cc3868fe8", "type": "template", "z": "eb8f9c0d054be30c", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "{\"chatId\": 5379039379,\n\"type\":\"message\",\n\"content\":\"Green LED Triggered\"}", "output": "json", "x": 860, "y": 80, "wires": [ [ "62f3360544d9ca11", "4abe16519bcdcaca" ] ] }, { "id": "62f3360544d9ca11", "type": "debug", "z": "eb8f9c0d054be30c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1030, "y": 80, "wires": [] }, { "id": "4abe16519bcdcaca", "type": "telegram sender", "z": "eb8f9c0d054be30c", "name": "roboerto_bot", "bot": "ae1a60539b8e5308", "haserroroutput": true, "outputs": 2, "x": 1030, "y": 120, "wires": [ [], [] ] }, { "id": "0d73aa1efdf96848", "type": "template", "z": "eb8f9c0d054be30c", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "{\"chatId\": 5379039379,\n\"type\":\"message\",\n\"content\":\"Red LED Triggered\"}", "output": "json", "x": 860, "y": 120, "wires": [ [ "4795fb81ce5c47a6", "12c1a78b02583d94" ] ] }, { "id": "4795fb81ce5c47a6", "type": "debug", "z": "eb8f9c0d054be30c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1030, "y": 180, "wires": [] }, { "id": "12c1a78b02583d94", "type": "telegram sender", "z": "eb8f9c0d054be30c", "name": "roboerto_bot", "bot": "ae1a60539b8e5308", "haserroroutput": true, "outputs": 2, "x": 1030, "y": 220, "wires": [ [], [] ] }, { "id": "15dcd2ff9b951c47", "type": "template", "z": "eb8f9c0d054be30c", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "{\"chatId\": 5379039379,\n\"type\":\"message\",\n\"content\":\"Blue LED Triggered\"}", "output": "json", "x": 860, "y": 160, "wires": [ [ "751fda5416547778", "46ea1f39f11d1b65" ] ] }, { "id": "751fda5416547778", "type": "debug", "z": "eb8f9c0d054be30c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1030, "y": 280, "wires": [] }, { "id": "46ea1f39f11d1b65", "type": "telegram sender", "z": "eb8f9c0d054be30c", "name": "roboerto_bot", "bot": "ae1a60539b8e5308", "haserroroutput": true, "outputs": 2, "x": 1030, "y": 320, "wires": [ [], [] ] }, { "id": "02e43d4dd4523371", "type": "template", "z": "eb8f9c0d054be30c", "name": "", "field": "payload", "fieldType": "msg", "format": "handlebars", "syntax": "mustache", "template": "{\"chatId\": 5379039379,\n\"type\":\"message\",\n\"content\":\"LED Off\"}", "output": "json", "x": 860, "y": 220, "wires": [ [ "e9aaa495e9c42799", "0730f1a37c585783" ] ] }, { "id": "e9aaa495e9c42799", "type": "debug", "z": "eb8f9c0d054be30c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1030, "y": 380, "wires": [] }, { "id": "0730f1a37c585783", "type": "telegram sender", "z": "eb8f9c0d054be30c", "name": "roboerto_bot", "bot": "ae1a60539b8e5308", "haserroroutput": true, "outputs": 2, "x": 1030, "y": 420, "wires": [ [], [] ] }, { "id": "e30abb1d7e9afcb0", "type": "inject", "z": "eb8f9c0d054be30c", "name": "Green", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 290, "y": 280, "wires": [ [ "b410ed94340bb528" ] ] }, { "id": "4a2a01d9556ad50f", "type": "inject", "z": "eb8f9c0d054be30c", "name": "Blue", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 290, "y": 360, "wires": [ [ "db816a1f10392614" ] ] }, { "id": "3f3ce5ea96251201", "type": "inject", "z": "eb8f9c0d054be30c", "name": "Red", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 290, "y": 320, "wires": [ [ "13aa73e421c429c7" ] ] }, { "id": "3f2c1cebdde09f03", "type": "inject", "z": "eb8f9c0d054be30c", "name": "Off", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 290, "y": 400, "wires": [ [ "4ed36e19be451327" ] ] }, { "id": "26b87a7af5f875cc", "type": "inject", "z": "eb8f9c0d054be30c", "name": "Env", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 290, "y": 440, "wires": [ [ "f2f9819ae972ae60" ] ] }, { "id": "ae1a60539b8e5308", "type": "telegram bot", "botname": "roboerto_bot", "usernames": "", "chatids": "", "baseapiurl": "", "updatemode": "polling", "pollinterval": "300", "usesocks": false, "sockshost": "", "socksprotocol": "socks5", "socksport": "6667", "socksusername": "anonymous", "sockspassword": "", "bothost": "", "botpath": "", "localbotport": "8443", "publicbotport": "8443", "privatekey": "", "certificate": "", "useselfsignedcertificate": false, "sslterminated": false, "verboselogging": false } ] 5. Conclusion: In this blog post, I showed you how to use Telegram bots to control your home automation system with Node-RED. You can use this method to create your own custom interface for your smart home devices and services. You can also extend the functionality of your bot by adding more nodes and logic to your flow. For example, you can use the command node to create custom commands with parameters, the callback query node to handle inline buttons, or the answer inline query node to provide suggestions. You can also use other nodes from the node-red-contrib-telegrambot package or other Node-RED packages to integrate with more Telegram features or other platforms. I hope you enjoyed this tutorial and learned something new. If you have any questions or feedback, please leave a comment below. Happy coding!
  3. Introduction In this tutorial, you will learn how to use Node-RED, a visual programming tool for the Internet of Things (IoT), to control an LED on an ESP32 board with a Raspberry Pi as the MQTT broker. MQTT is a lightweight and simple messaging protocol that allows devices to communicate with each other over a network. You will need the following components for this project: ESP32 development board USB cable to connect the ESP32 to your computer Raspberry Pi with Node-RED Computer with Arduino IDE and PubSubClient library installed Get PCBs For Your Projects Manufactured You must check out PCBWAY for ordering PCBs online for cheap! You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Step 1: Create a Device on Qubitro The first step is to create a device on the Qubitro platform. A device represents your physical device (Raspberry Pi) on the cloud. You need to create a device to obtain the MQTT credentials and topics for your Raspberry Pi. To create a device on Qubitro, follow these steps: 1. Log in to your Qubitro account and create a new project 2. Then go to the Devices page, select MQTT as the communication protocol, and click Next. 3. Enter all the details. 4. Copy the Device ID, Device Token, Hostname, Port, Publish Topic, and Subscribe Topic. You will need these values later in the code. Click Finish. You have successfully created a device on Qubitro. You can see your device on the Devices page. Step 2: Flash ESP32 with Arduino IDE The ESP32 is a powerful and versatile microcontroller that can run Arduino code. You will use the Arduino IDE to program the ESP32 and make it communicate with the MQTT broker using the PubSubClient library. To install the ESP32 board in Arduino IDE, you can follow the instructions in this tutorial or use the steps below: Open the preferences window from the Arduino IDE: File > Preferences. Go to the “Additional Board Manager URLs” field and enter the following URL: https://dl.espressif.com/dl/package_esp32_index.json. Open Boards Manager (Tools > Board > Boards Manager), search for ESP32, and click the install button for the “ESP32 by Espressif Systems”. Select your ESP32 board from Tools > Board menu after installation. Open the library manager from Sketch > Include Library > Manage Libraries. Search for PubSubClient and click the install button for the “PubSubClient by Nick O’Leary”. Restart your Arduino IDE after installation. Step 3: Connect LED to ESP32 The LED is a simple device that emits light when current flows through it. You will connect the LED to one of the GPIO pins of the ESP32 and control its state (on or off) with MQTT messages. In my case I'm going to use the onboard LED in the ESP32 Dev board. Step 4: Write Code for ESP32 The code for the ESP32 will do the following tasks: Connect to your Wi-Fi network Connect to the Qubitro MQTT broker on Raspberry Pi Receive messages from “output” and turn on or off the LED accordingly You can copy and paste the code below into your Arduino IDE. Make sure to replace <your_ssid>, <your_password>, <your_Qubtro_Credientials> with your own values. #include <WiFi.h> #define DEBUG_SW 1 #include <PubSubClient.h> //Relays for switching appliances #define Relay1 2 int switch_ON_Flag1_previous_I = 0; // Update these with values suitable for your network. const char* ssid = "ELDRADO"; const char* password = "amazon123"; const char* mqtt_server = "broker.qubitro.com"; // Local IP address of Raspberry Pi const char* username = ""; const char* pass = ""; // Subscribed Topics #define sub1 "output" WiFiClient espClient; PubSubClient client(espClient); unsigned long lastMsg = 0; #define MSG_BUFFER_SIZE (50) char msg[MSG_BUFFER_SIZE]; int value = 0; // Connecting to WiFi Router void setup_wifi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } randomSeed(micros()); Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); if (strstr(topic, sub1)) { for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); } Serial.println(); // Switch on the LED if an 1 was received as first character if ((char)payload[0] == 'f') { digitalWrite(Relay1, LOW); // Turn the LED on (Note that LOW is the voltage level // but actually the LED is on; this is because // it is active low on the ESP-01) } else { digitalWrite(Relay1, HIGH); // Turn the LED off by making the voltage HIGH } } else { Serial.println("unsubscribed topic"); } } // Connecting to MQTT broker void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("Attempting MQTT connection..."); // Create a random client ID String clientId = "ESP8266Client-"; clientId += String(random(0xffff), HEX); // Attempt to connect if (client.connect(clientId.c_str() , username, pass)) { Serial.println("connected"); // Once connected, publish an announcement... client.publish("outTopic", "hello world"); // ... and resubscribe client.subscribe(sub1); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying delay(5000); } } } void setup() { pinMode(Relay1, OUTPUT); Serial.begin(115200); setup_wifi(); client.setServer(mqtt_server, 1883); client.setCallback(callback); } void loop() { if (!client.connected()) { reconnect(); } client. Loop(); } After writing the code, upload it to your ESP32 board by selecting the right board and port from the Tools menu and clicking the upload button. Step 5: Create Node-RED Flow The Node-RED flow will do the following tasks: Connect to the MQTT broker on Raspberry Pi Subscribe to a topic named “output” Publish messages “true” or “false” to a topic named “output” Create a dashboard with a button and a text node You can create the Node-RED flow by dragging and dropping nodes from the palette and connecting them with wires. You can also import the flow from this link or use the JSON code below: [ { "id": "eb8f9c0d054be30c", "type": "tab", "label": "Flow 2", "disabled": false, "info": "", "env": [] }, { "id": "4ce6cd876fd5441f", "type": "mqtt out", "z": "eb8f9c0d054be30c", "name": "", "topic": "output", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "6d40b7b21c734b53", "x": 870, "y": 240, "wires": [] }, { "id": "974a7a8bb6db9bf9", "type": "mqtt in", "z": "eb8f9c0d054be30c", "name": "", "topic": "output", "qos": "2", "datatype": "auto-detect", "broker": "6d40b7b21c734b53", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 670, "y": 320, "wires": [ [ "d0dc7378c7bfb03b", "f1219a2eeabe825f" ] ] }, { "id": "d0dc7378c7bfb03b", "type": "debug", "z": "eb8f9c0d054be30c", "name": "debug 4", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 880, "y": 320, "wires": [] }, { "id": "6bd227b280e372b7", "type": "ui_switch", "z": "eb8f9c0d054be30c", "name": "", "label": "Light One", "tooltip": "", "group": "cd687a95.00e108", "order": 0, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "topic", "topicType": "msg", "style": "", "onvalue": "true", "onvalueType": "bool", "onicon": "", "oncolor": "", "offvalue": "false", "offvalueType": "bool", "officon": "", "offcolor": "", "animate": false, "x": 680, "y": 240, "wires": [ [ "4ce6cd876fd5441f" ] ] }, { "id": "f1219a2eeabe825f", "type": "ui_text", "z": "eb8f9c0d054be30c", "group": "cd687a95.00e108", "order": 1, "width": "6", "height": "2", "name": "", "label": "Status : ", "format": "{{msg.payload}}", "layout": "row-center", "x": 1060, "y": 320, "wires": [] }, { "id": "6d40b7b21c734b53", "type": "mqtt-broker", "name": "Qubitro Downlink", "broker": "broker.qubitro.com", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "r43MsJYzcVwZtUXVfZo6XD0Ym7CRegewPQXMt$ho", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" }, { "id": "cd687a95.00e108", "type": "ui_group", "name": "ESP32 Home Controller", "tab": "aa146f4d.b53ca", "order": 1, "disp": true, "width": "6", "collapse": false }, { "id": "aa146f4d.b53ca", "type": "ui_tab", "name": "Demo Lab", "icon": "dashboard", "order": 1, "disabled": false, "hidden": false } ] The input switch will send "true" when it is on, and it will send "false" when it triggers off. Then click on the Qubitro uplink pallet and edit the property. Here you need to replace your connection details and credentials. Next, just deploy the flow. And navigate to the /ui of the node-red server. Here you can toggle the switch to turn the lead on and off. Also, open the serial monitor and check the node-red response. Conclusion: In this tutorial, we have seen how to control the LED with Node-Red and MQTT Server.
  4. Things used in this project Hardware components Raspberry Pi 4 Model B × 1 Adafruit NeoPixel Ring: WS2812 5050 RGB LED × 1 Software apps and online services Node-RED How to Control NeoPixel LEDs with Node-RED and Raspberry Pi NeoPixel LEDs are a popular type of addressable RGB LEDs that can create amazing effects and animations. They are easy to control with a microcontroller like Arduino, but what if you want to use them with a Raspberry Pi? In this article, we’ll show you how to use Node-RED, a graphical programming tool, to control NeoPixel LEDs with a Raspberry Pi. Get PCBs For Your Projects Manufactured You must check out PCBWAY for ordering PCBs online for cheap! You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. What You’ll Need To follow this tutorial, you’ll need the following components: A Raspberry Pi board with Raspbian OS installed A WS2812B NeoPixel LED strip Some jumper wires You’ll also need to install Node-RED and the node-red-node-pi-neopixel node on your Raspberry Pi. We’ll explain how to do that later. Wiring the NeoPixel LED Strip The NeoPixel LED strip has three wires: 5V, GND, and DATA. The 5V and GND wires provide power to the LEDs, while the DATA wire carries the signal that controls the color and brightness of each LED. The Raspberry Pi can provide 5V and GND from its GPIO pins and connect the DATA pin to GPIO 18. The reason we use GPIO 18 is because it supports PWM (pulse-width modulation), which is needed by the node-red-node-pi-neopixel node. You can use other PWM-enabled GPIO pins, but you’ll need to change the settings accordingly. Installing Node-RED and node-red-node-pi-neopixel Node-RED is a graphical programming tool that lets you create applications by connecting nodes that perform different functions. You can install Node-RED on your Raspberry Pi by following this guide. To control the NeoPixel LEDs with Node-RED, you need to install a special node called node-red-node-pi-neopixel. This node can drive a strip of NeoPixel or WS2812 LEDs from a Raspberry Pi. You can install it by running the following command. npm install node-red-node-pi-neopixel You also need to install the Neopixel python driver, which is used by the node-red-node-pi-neopixel node. The easiest way to do that is to use the Unicorn HAT drivers install script, which you can run with this command: After installing node-red-node-pi-neopixel, you need to restart Node-RED for the changes to take effect. Creating a Node-RED Flow Now that everything is set up, you can create a Node-RED flow to control the NeoPixel LEDs. A flow is a collection of nodes that are connected by wires. Each node has an input and an output and can perform some action or function. To create a flow, you need to open the Node-RED editor in your web browser. By default, it runs on port 1880 of your Raspberry Pi’s IP address. For example, if your Raspberry Pi’s IP address is 192.168.1.3, you can access the Node-RED editor at http://192.168.1.3:1880. In the editor, you’ll see a palette of nodes on the left side, a workspace in the middle, and an info panel on the right side. You can drag nodes from the palette to the workspace and connect them by dragging wires from one node’s output to another node’s input. Here’s an example of a neo-pixel flow that controls the LEDs based on our user inputs. To create this flow, you need to do the following steps: Drag Copy and import the below JSON node-red flow. Change the LED count JSON Files: [ { "id": "60627e22237dc214", "type": "tab", "label": "Flow 2", "disabled": false, "info": "", "env": [] }, { "id": "f0395033145e84d7", "type": "ui_colour_picker", "z": "60627e22237dc214", "name": "Color Picker", "label": "COLOR PICKER", "group": "cd687a95.00e108", "format": "rgb", "outformat": "string", "showSwatch": true, "showPicker": true, "showValue": true, "showHue": false, "showAlpha": false, "showLightness": true, "square": "false", "order": 1, "width": 0, "height": 0, "passthru": true, "topic": "", "topicType": "str", "x": 490, "y": 380, "wires": [ [ "f6f366218f267026" ] ] }, { "id": "f6f366218f267026", "type": "function", "z": "60627e22237dc214", "name": "Set Color", "func": "var count = global.get('count')||0;\nmsg.payload = msg.payload.replace(/[rgb()\\s]/g,\"\");\nif(count===0){\n msg.payload = msg.payload;\n}\nelse{\n msg.payload = (count-1) + \",\" + msg.payload;\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "x": 680, "y": 380, "wires": [ [ "b4a4a424433ab3a2" ] ] }, { "id": "cc6b4172d7245dfd", "type": "function", "z": "60627e22237dc214", "name": "Rainbow Effect", "func": "var numberOfLEDs = 8;\nvar i;\nvar j;\n\nif (msg.payload==1)\n{\n for (i = 0; i < 255; i++) {\n\n for (j = 0; j < numberOfLEDs; j++) {\n\n var pos = 0;\n pos = Math.round(((j * 255 / numberOfLEDs) + i)) & 255;\n\n if (pos < 85) {\n var red = pos * 3;\n var green = 255 - pos * 3;\n var blue = 0;\n }\n else if (pos < 170) {\n pos -= 85;\n var red = 255 - pos * 3;\n var green = 0;\n var blue = pos * 3;\n }\n else {\n pos -= 170;\n var red = 0;\n var green = pos * 3;\n var blue = 255 - pos * 3;\n }\n var setColor = j + ',' + red + ',' + green + ',' + blue;\n node.send({ payload: setColor });\n }\n }\n}\nelse { \n msg.payload = \"0,0,0\"\n}\n\nreturn msg;\n\n\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 700, "y": 440, "wires": [ [ "b4a4a424433ab3a2" ] ] }, { "id": "b4a4a424433ab3a2", "type": "rpi-neopixels", "z": "60627e22237dc214", "name": "Neo Pixel", "gpio": "18", "pixels": "8", "bgnd": "", "fgnd": "", "wipe": "60", "mode": "pixels", "rgb": "rgb", "brightness": "100", "gamma": true, "x": 900, "y": 420, "wires": [] }, { "id": "125d1e66ad34b180", "type": "ui_switch", "z": "60627e22237dc214", "name": "", "label": "Rainbow switch", "tooltip": "", "group": "cd687a95.00e108", "order": 3, "width": 0, "height": 0, "passthru": true, "decouple": "false", "topic": "topic", "topicType": "msg", "style": "", "onvalue": "true", "onvalueType": "bool", "onicon": "", "oncolor": "", "offvalue": "false", "offvalueType": "bool", "officon": "", "offcolor": "", "animate": false, "x": 500, "y": 440, "wires": [ [ "cc6b4172d7245dfd" ] ] }, { "id": "cd687a95.00e108", "type": "ui_group", "name": "Neo Pixel Controller", "tab": "aa146f4d.b53ca", "order": 1, "disp": true, "width": "6", "collapse": false }, { "id": "aa146f4d.b53ca", "type": "ui_tab", "name": "Demo Lab", "icon": "dashboard", "order": 1, "disabled": false, "hidden": false } ] Neo Pixel Node Setup: Select the PIN and change the LED count as per your neo-pixel configuration. Deployment Setup: Next hit the deployment button and navigate to the UI page of the Node-red with /ui in the node-red page URL. You can select the LED color via the neo-pixel circle. Also, if you toggle the rainbow switch it will apply the rainbow effect to the ring. Conclusion In this article, I have shown you how to control NeoPixel LEDs with Node-RED and Raspberry Pi.
×
  • Create New...