Changes between Initial Version and Version 1 of nodered


Ignore:
Timestamp:
12/17/2021 07:41:19 PM (2 years ago)
Author:
Ryan Erbstoesser
Comment:

start node red page

Legend:

Unmodified
Added
Removed
Modified
  • nodered

    v1 v1  
     1= Node-RED
     2
     3Node-RED can be used with the Gateworks SBCs.
     4
     5Typically, 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.
     6
     7= Install Node-RED on Gateworks SBC
     8
     9Doing the below commands will make the Gateworks SBC act as the 'server'
     10{{{
     11
     12    sudo apt-get update
     13    sudo apt-get install mosquitto #if wanting to use the MQTT protocol to talk to client
     14    sudo apt-get install nodejs #beware Ubuntu default may be 10.19, and it would be better to use a newer version
     15    sudo apt-get install npm #get the node package manager
     16    sudo npm install -g --unsafe-perm node-red #install node-red using npm
     17    node-red
     18}}}
     19
     20Once node-red is running, use a browser to open the node-red gui on port 1880.
     21 * eg http://122.24.11.93:1880/
     22
     23= Create a Client on Gateworks SBC
     24{{{
     25
     26    sudo apt-get update
     27    sudo apt-get install python #if wanting to use the MQTT protocol to talk to client
     28    sudo apt-get install nodejs #beware Ubuntu default may be 10.19, and it would be better to use a newer version
     29
     30}}}
     31
     32Then, create a python script (example below) to send MQTT messages from the client SBC to the server SBC.
     33
     34== Gateworks Python Script to send MQTT Messages
     35{{{
     36root@focal-venice:~# cat gateworks.py
     37# Compatible with python 2.* version
     38import sys
     39import os.path
     40import json
     41import time
     42import random
     43import paho.mqtt.client as mqtt
     44from datetime import datetime
     45
     46def callbackMessage(msg):
     47    if msg:
     48        print("\n--- Command Message Received ---")
     49        print(str(msg['ack']))
     50        print(str(msg['ackId']))
     51        print(str(msg['command']))
     52        print(str(msg['uniqueId']))
     53
     54def callbackTwinMessage(msg):
     55    if msg:
     56        print("\n--- Twin Message Received ---")
     57        print(json.dumps(msg))
     58
     59def main(argv):
     60 while True:
     61    try:
     62        env = "enter_evn_name_here"
     63
     64        uniqueId = "enter_device_id_here_example_device1"
     65        cpId = "enter_company_id_here_from_avnet_portal"
     66        print("in loop")
     67        client = mqtt.Client("clientone")
     68        broker = "122.24.11.93"
     69        client.connect(broker)
     70        client.subscribe("house/bulbs")
     71        client.publish("house/bulbs","OFF")
     72        print("done publishing")
     73
     74    except Exception as ex:
     75        print(ex.message)
     76        sys.exit(0)
     77    time.sleep(10)
     78
     79
     80if __name__ == "__main__":
     81    main(sys.argv)
     82
     83}}}
     84
     85
     86