|
| 1 | +--- |
| 2 | +layout: docs-getting-started |
| 3 | +title: Running Node-RED on balena |
| 4 | +toc: toc-user-guide.html |
| 5 | +slug: balena |
| 6 | +redirect_from: |
| 7 | + - /docs/platforms/balena |
| 8 | +--- |
| 9 | + |
| 10 | +This guide is going to install Node-RED on an edge device using [balena.io](https://balena.io) in 1 click. Running Node-RED on balena, means that you are using containers and Node-RED can run alognside with other services such as MQTT, databases, LoRa Network Servers and more. balena is a platform for managing fleets of connected devices. |
| 11 | + |
| 12 | + |
| 13 | +### Hardware required |
| 14 | + |
| 15 | +To build this project, you will need: |
| 16 | + |
| 17 | +* Raspberry Pi 0, 2, 3, 4 or [balenaFin](https://www.balena.io/fin/) |
| 18 | +* An SD card if you are using a Raspberry Pi |
| 19 | +* Power supply and (optionally) Ethernet cable. |
| 20 | + |
| 21 | + |
| 22 | +### Software setp |
| 23 | + |
| 24 | +To set up this project, you'll need: |
| 25 | + |
| 26 | +* a [balenaCloud account](https://dashboard.balena-cloud.com/) (remember that the first 10 devices are fully-featured and free) |
| 27 | +* [balenaEtcher](https://www.balena.io/etcher/) to flash the SD card. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +## Tutorial |
| 32 | + |
| 33 | +### Deploy Node-RED in 1 click |
| 34 | + |
| 35 | +The Node-RED application with [balena-supervisor](https://balena.io/docs/reference/supervisor/supervisor-api/) flow [support](https://github.com/balena-io-projects/node-red-contrib-balena), can be managed remotely via balena [publicURL](https://balena.io/docs/learn/manage/actions/#enable-public-device-url). |
| 36 | + |
| 37 | +You can deploy this project to a new balenaCloud fleet in one click using the button below: |
| 38 | + |
| 39 | +[](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/balenalabs/balena-node-red) |
| 40 | + |
| 41 | +Clicking the deploy button will create an application with all the necessary code to deploy your Node-RED project. |
| 42 | + |
| 43 | +<img src="images/balena-creating-fleet.png" /> |
| 44 | + |
| 45 | +<img src="images/balena-device-nodeRED.png" /> |
| 46 | + |
| 47 | +Once the `Node-RED` service has been deployed on your device, copy your local IP (if you are using the same network) or just click on `Public Device URL` and access to the Node-RED UI. |
| 48 | + |
| 49 | +To access to the Node-RED UI, use `balena` as username and password. You may want to modify the `USERNAME` and `PASSWORD` on the balenaCloud Device Variables. |
| 50 | + |
| 51 | +Now you are ready to start using Node-RED on your device. |
| 52 | + |
| 53 | + |
| 54 | +### Deploy Node-RED from balena CLI |
| 55 | + |
| 56 | +The previous application was running Node-RED however if you would like to run more services alongisde on the same device, this is also possible. |
| 57 | + |
| 58 | +You will need to have installed on your computer the [git CLI](https://github.com/git-guides/install-git) and the [balena CLI](https://www.balena.io/docs/reference/balena-cli/). |
| 59 | + |
| 60 | +First thing you need to do is to clone the [balena Node-RED block](https://github.com/balenalabs/balena-node-red). |
| 61 | + |
| 62 | +```` |
| 63 | +cd ~/workspace |
| 64 | +mkdir balena-node-red-mqtt |
| 65 | +cd balena-node-red-mqtt |
| 66 | +git clone https://github.com/balenalabs/balena-node-red.git |
| 67 | +``` |
| 68 | +
|
| 69 | +#### Add MQTT mosquitto service |
| 70 | +
|
| 71 | +Let's add to the Node-RED service on balena another service. In this example we are going to add the MQTT mosquitto service. |
| 72 | +
|
| 73 | +Create a `docker-compose.yml` file and add this: |
| 74 | +
|
| 75 | +```` |
| 76 | +version: '2' |
| 77 | + |
| 78 | +volumes: |
| 79 | + data: |
| 80 | + database: |
| 81 | + |
| 82 | +services: |
| 83 | + node-red: |
| 84 | + build: ./balena-node-red |
| 85 | + volumes: |
| 86 | + - 'data:/data' |
| 87 | + restart: always |
| 88 | + privileged: true |
| 89 | + network_mode: host |
| 90 | + labels: |
| 91 | + io.balena.features.supervisor-api: '1' |
| 92 | + io.balena.features.balena-api: '1' |
| 93 | + environment: |
| 94 | + - "USERNAME=balena" |
| 95 | + - "PASSWORD=balena" |
| 96 | + - "ENCRIPTION_KEY=balena" |
| 97 | + cap_add: |
| 98 | + - SYS_RAWIO |
| 99 | + devices: |
| 100 | + - "/dev/mem:/dev/mem" |
| 101 | + - "/dev/gpiomem:/dev/gpiomem" |
| 102 | + - "/dev/i2c-1:/dev/i2c-1" |
| 103 | + ports: |
| 104 | + - 80:80 |
| 105 | + |
| 106 | + mqtt: |
| 107 | + image: arm32v6/eclipse-mosquitto |
| 108 | + network_mode: host |
| 109 | + ports: |
| 110 | + - "1883:1883" |
| 111 | + restart: always |
| 112 | +``` |
| 113 | +
|
| 114 | +#### Deploy the Node-RED and MQTT with balena CLI |
| 115 | +
|
| 116 | +* Sign up on your balena.io account. |
| 117 | +* Create a new fleet on balenaCloud. |
| 118 | +* Add a new device and download the image of the balenaOS that the balenaCloud creates. Remember to introduce your WiFi credentials, in case you are going to use WiFi. |
| 119 | +* Burn an SD card (if you are using the Raspberry Pi) using balenaEtcher. |
| 120 | +* Once the flashing process has completed, insert your SD card into the device and power it up. |
| 121 | +
|
| 122 | +When the device boots for the first time, it connects to your network automatically and then appears to the balenaCloud dashboard. After a few moments, you will see the new provisioned device listed and online. |
| 123 | +
|
| 124 | +Now using the balena CLI, push the code to your fleet using `balena push <the-name-of-your-fleet>`. And see the magic happening, your device is getting updated over-the-air. |
| 125 | +
|
| 126 | +Once the project has been built on the balena builders, you should see your device downloading the new images containers and starting them. |
| 127 | +
|
| 128 | +<img src="images/balena-nodeRED-mqtt.png" /> |
| 129 | +
|
| 130 | +In this repository you can find an example of [nodeRED and MQTT mosquitto](https://github.com/mpous/balena-nodered-mqtt) on balena. |
| 131 | +
|
| 132 | +
|
| 133 | +
|
0 commit comments