wiki:nodered

Version 5 (modified by Ryan Erbstoesser, 2 years ago) ( diff )

update intro

Node-RED

Node-RED is software ran on Node.js that allows for flow-based visual programming in a browser, to wire together hardware, inputs, and services for Internet of Things (IoT) applications.

Node-RED can be used with the Gateworks SBCs.

Typically, Node-RED may actually run on a server machine and the Gateworks SBC acts as a client and talks back to the server. Or, Node-RED can be install on the Gateworks SBC itself.

This wiki page assumes the usage of a Gateworks Venice SBC with the latest kernel (5.10 or newer)

Install Node-RED on Gateworks SBC

Installing Node-Red on a Gateworks SBC isn't any different than many other Linux platforms, which instructions are detailed on the internet.

Doing the below commands will make the Gateworks SBC act as the 'server'

    sudo apt-get update
    sudo apt-get install mosquitto #if wanting to use the MQTT protocol to talk to client
    sudo apt-get install nodejs #beware Ubuntu default may be 10.19, and it would be better to use a newer version
    sudo apt-get install npm #get the node package manager
    sudo npm install -g --unsafe-perm node-red #install node-red using npm
    node-red #start the node-red application

Once node-red is running, use a browser to open the node-red gui on port 1880.

  • Demo Setup:
    • This demo takes an incoming MQTT message from a client and just prints it out in the debug screen.
    • Use the MQTT input module connected to a debug module ti replicate what is shown in the picture below.

Create a Client on Gateworks SBC

    sudo apt-get update
    sudo apt-get install python #if wanting to use the MQTT protocol to talk to client
    sudo apt-get install nodejs #beware Ubuntu default may be 10.19, and it would be better to use a newer version

Then, create a python script (example below) to send MQTT messages from the client SBC to the server SBC.

Gateworks Python Script to send MQTT Messages

root@focal-venice:~# cat gateworks.py 
# Compatible with python 2.* version
import sys
import os.path
import json
import time
import random
import paho.mqtt.client as mqtt
from datetime import datetime

def callbackMessage(msg):
    if msg:
        print("\n--- Command Message Received ---")
        print(str(msg['ack']))
        print(str(msg['ackId']))
        print(str(msg['command']))
        print(str(msg['uniqueId']))

def callbackTwinMessage(msg):
    if msg:
        print("\n--- Twin Message Received ---")
        print(json.dumps(msg))

def main(argv):
 while True:
    try:
        env = "enter_evn_name_here"

        uniqueId = "enter_device_id_here_example_device1"
        cpId = "enter_company_id_here_from_avnet_portal"
        print("in loop")
        client = mqtt.Client("clientone")
        broker = "122.24.11.93"
        client.connect(broker) 
        client.subscribe("house/bulbs")
        client.publish("house/bulbs","OFF")
        print("done publishing")

    except Exception as ex:
        print(ex.message)
        sys.exit(0)
    time.sleep(10)


if __name__ == "__main__":
    main(sys.argv)

Attachments (2)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.