Node-RED introduction: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
Line 27: Line 27:


[[File:Screen Shot 2021-12-31 at 3.44.31 pm.png]]
[[File:Screen Shot 2021-12-31 at 3.44.31 pm.png]]
* Note the very first line that shows:
** '''/home/pi/peter-hopper-t3/''' – the full path of the file
** '''peter_hopper_get_data.py''' – the file name
* We will need to use this information later when coding Node-RED.
[[File:Screen Shot 2021-12-31 at 3.57.14 pm.png]]
=== Finding the path and name of a file in the Terminal ===
* Open the '''Terminal'''.
* Enter the command '''ls''' to list all directory contents.
* Then enter the command '''pwd''' – which gives the path to the '''present working directory'''
* In this example the path to the pi directory is '''/home/pi'''
[[File:Screen Shot 2021-12-31 at 4.00.02 pm.png]]
* To change directory and enter the peter-hopper-t3 enter the command '''cd peter-hopper-t3'''
* To list all the contents of the peter-hopper-t3 directory enter '''ls'''
* To determine the full path to this directory enter '''pwd'''
* Notice that the path is the same as the output in the Python Shell.
[[File:Screen Shot 2021-12-31 at 4.02.51 pm.png]]
* To run the peter_hopper_get_data.py file enter '''python3 peter_hopper_get_data.py'''
[[File:Screen Shot 2021-12-31 at 4.03.48 pm.png]]
* The program output that we typically see in the Python Shell is now in the Terminal.
[[File:Screen Shot 2021-12-31 at 4.04.38 pm.png]]
=== Starting Node-RED ===
* To start Node-RED open the Terminal and enter the command Node-RED
[[File:Screen Shot 2021-12-31 at 4.06.17 pm.png]]
* You should see an output similar to below.
* I have some additional programs already running in Node-RED, so my display will be different.
[[File:Screen Shot 2021-12-31 at 4.07.06 pm.png]]
* Before shutting down the Raspberry Pi you should always stop Node-RED.
* Open a new Terminal window and enter '''node-red-stop'''
* If you need to restart Node-RED enter '''node-red''' or '''node-red-start'''
[[File:Screen Shot 2021-12-31 at 4.08.36 pm.png]]
=== 4. Opening the Node-RED interface using a Web Browser ===
Open the default web browser on the Raspberry Pi
In the Search bar enter the URL localhost:1880

Revision as of 05:09, 31 December 2021

Overview

  • The aim of this lesson is to start learning to use Node-RED which is a block-based programming language.
  • The appeal of Node-RED is that individual code segments are hidden in nodes.
  • Individual nodes can be connected using wires.
  • This makes the program much easier to visualise and program.

Learning Objectives

  • Learn how to start node-red on the Raspberry Pi.
  • Learn how to run Python programs in Node-RED.

Introduction to Node-RED on the raspberry Pi

  • Node-RED is a powerful and intuitive programming language pre-installed on the Raspberry Pi.
  • This lesson will serve as an introduction to the use of this platform.
  • In this lesson we will learn how to execute python programs.

Run the python file peter_hopper_get_data.py

  • From the main Raspberry Pi menu navigate to Programming and open Python3 IDLE
  • Open the saved file peter_hopper_get_data.py
  • The full listing is below.

  • Run the program by selecting Run > Run module.
  • The program will send output to the Python Shell.
  • A typical output in the Shell is presented below.

  • Note the very first line that shows:
    • /home/pi/peter-hopper-t3/ – the full path of the file
    • peter_hopper_get_data.py – the file name
  • We will need to use this information later when coding Node-RED.

Finding the path and name of a file in the Terminal

  • Open the Terminal.
  • Enter the command ls to list all directory contents.
  • Then enter the command pwd – which gives the path to the present working directory
  • In this example the path to the pi directory is /home/pi

  • To change directory and enter the peter-hopper-t3 enter the command cd peter-hopper-t3
  • To list all the contents of the peter-hopper-t3 directory enter ls
  • To determine the full path to this directory enter pwd
  • Notice that the path is the same as the output in the Python Shell.

  • To run the peter_hopper_get_data.py file enter python3 peter_hopper_get_data.py

  • The program output that we typically see in the Python Shell is now in the Terminal.

Starting Node-RED

  • To start Node-RED open the Terminal and enter the command Node-RED

  • You should see an output similar to below.
  • I have some additional programs already running in Node-RED, so my display will be different.

  • Before shutting down the Raspberry Pi you should always stop Node-RED.
  • Open a new Terminal window and enter node-red-stop
  • If you need to restart Node-RED enter node-red or node-red-start

4. Opening the Node-RED interface using a Web Browser

Open the default web browser on the Raspberry Pi In the Search bar enter the URL localhost:1880