How is Node-RED embedded?

NodeRED used following the “Embedding into an existing app” as described in the Node-RED documentation http://nodered.org/docs/embedding.html.

How do I SSH ?

Try to use the hostname to connect. You may have to use the IP Address instead. You can find it in the menu Settings / Parameters.

Default credentials are root/raspberry

Userdir can be found in cd /root/userdir/ Newly installed nodes are in cd /root/userdir/node_modules

Where do I find the NodeRED settings ?

on the ThingBox, Node-RED is installed in /root/thethingbox/node_modules/node-red/

You can update the file /root/thethingbox/node_modules/node-red/settings.js

You can also update the javascript object settings_nodered_ext into the file /root/thethingbox/thethingbox.js that expand the settings.js of Node-RED

In the file root\thethingbox\thethingbox.js

The settings are there:

var userDir="/root/userdir/";
var flowDir=userDir;
var settings_nodered_ext = {
	httpAdminRoot:"/",
	httpNodeRoot: "/",
	httpNodeCors: {
		origin: "*",
		methods: "GET,PUT,POST,DELETE"
	},
	SKIP_BUILD_CHECK:true,
	userDir: userDir,
	flowDir: flowDir,
	flowFile: flowDir + "flows.json",
	secondFlowDir: "/root/thethingbox/node_modules/node-red/flow/",
	verbose: true,
	flowFilePretty: true,
	otherPropToSave: ['origin', 'extra'],
	paletteCategories:['basic', 'subflows', 'input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'],
	hiddenWorkspaces: ['system'],
	functionGlobalContext: {
		settings: settings_ttb
		,userDir: userDir
		,settingslib: require('/root/thethingbox/settingsttb.js')
		,wpi: require('node-red/node_modules/wiring-pi') // https://www.npmjs.com/package/wiring-pi
		,CryptoJS: require('node-red/node_modules/crypto-js') // https://www.npmjs.com/package/cryptojs
		,HID: require('node-red/node_modules/node-hid') // https://www.npmjs.com/package/node-hid
	}
};
Note: the code above is the settings use for the version 2.1.0

The Node-RED settings are loaded too (since version 2.1.0) This file is located in root\thethingbox\node_modules\node-red\settings.js (http://nodered.org/docs/configuration.html) But those settings are overwritten by thethingbox :

  • uiPort
  • flowFile
  • flowFilePretty
  • userDir
  • httpAdminRoot
  • httpNodeRoot
  • httpNodeCors
  • functionGlobalContext
  • paletteCategories

How to get a unique ID?

Each thingBox or TimeSquAir has a unique ID.

It is an auto-generated UUID Or a serial number for commercially released devices.

Create a function node with:

msg.payload = context.global.settings.id;
return msg;

and display the payload.

This is useful to build a device dedicated MQTT topic.

You can also use the hostname as a unique ID.

How to get the hostname?

Just read the dedicated file:

![](images/node-red/hostname.png)

A good idea is toLowerCase is a function node (and may be trip line returns):

if (typeof msg.payload === 'string') {
    msg.hostname = msg.payload.toLowerCase();
}
return msg;

How can I find its IP address ?

  1. You can find it in the menu Settings / Parameters.

  2. You can also do a Avahi scan (see later)

  3. Third solution: Connect via SSH on your device. Enter : ifconfig and the ip will be written like that :

    eth0 inet addr: 192.168.0.21

How to do a avahi scan for devices on the local network?

If your device has the network name home1, use the following address in a browser: http://home1.local/avahi/scan

Find your devices in the list:

{
    "Freebox-Player.local": {
        address: "192.168.0.13",
        port: "24322"
    },
    "Freebox-Server.local": {
        address: "192.168.0.254",
        port: "445"
    },
    "SEC001599D37A46.local": {
        address: "192.168.0.192",
        port: "80"
    },
    "8b92cbf4-66a6-b585-7d95-42dfe20f3b1f.local": {
        address: "192.168.0.41",
        port: "8009",
        txt: {
            rs: "YouTube",
            nf: "1",
            bs: "FA8FCA68D963",
            st: "1",
            ca: "4101",
            fn: "Chromecast TV",
            ic: "/setup/icon.png",
            md: "Chromecast",
            ve: "05",
            rm: "9FC52B50D8684F1C",
            cd: "495E077770B2FE6FA3B7928C07402729",
            id: "8b92cbf466a6b5857d9542dfe20f3b1f"
        }
    },
    "home1.local": {
        address: "192.168.0.48",
        port: "9"
    },
    "Musique.local": {
        address: "fe80::2062:2f04:b9c1:a26b",
        port: "2020",
        txt: {
            UUID: "a30e8496-5fae-4cb2-a925-b0adc7d5b803",
            Token: "cacYIvbGk4MCffZk",
            DyngateID: "673678089"
        }
    },
    "tsabed.local": {
        address: "192.168.0.5",
        port: "9"
    },
    "musicttb.local": {
        address: "192.168.0.31",
        port: "9"
    },
    "MacBook-Pro-de-Alice.local": {
        address: "192.168.0.44",
        port: "54145",
        txt: {
            rpHA: "1a2fe580b87d",
            rpVr: "120.48",
            rpHN: "90634785a3b4",
            rpHI: "959ffa6d8822",
            rpFl: "0x0",
            rpBA: "2B:07:64:5F:FF:D0"
        }
    },
    "iPhone-de-Coline.local": {
        address: "192.168.0.32",
        port: "32498"
    }
}

Where I can find the Node-RED logs ?

  • On the non docker version From samba: \\yourDeviceName\TheThingBox\root\thethingbox\node_modules\node-red\public\console.txt
  • On the docker version From samba: \\yourDeviceName\TheThingBox\var\log\thethingbox\console.txt

How to launch NodeRED manually from the console?

  • On the non docker version From SSH as root: ~~~ service thethingbox restart ~~~
  • On the docker version From SSH as root: ~~~ docker restart thethingbox ~~~

The Thingbox expands the SDCard at first boot

At first boot, a Thingbox expands to the whole SDCard with resize2fs Script is in root\thethingbox\.auto-expand-scripts (deleted at first boot)

How to manually ‘npm install’ new nodes

Many nodes can be install with the “import / node” UI.

But you can add by yourself, preferably in /root/userdir to avoid erasing them with the updater.

In version 3.0.0, TheThingBox works in a docker container, NodeJS and npm work in this container and are not available on the device level.

To use npm, you should get the container cli with the command :

docker exec -it thethingbox bash
cd userdir
npm install --unsafe-perm --legacy-bundling --no-package-lock xxxx
exit

Where are my datas?

Flows and settings are stored outside in /root/userdir Be aware that if you install additional nodes yourself, they may store their data elsewhere.

Where is the flow stored?

Starting with the version 1.8.0, the used flow is the dynamic merge of

  • The user flow in \root\userdir\flows.json
  • The Thingbox flows in \root\thethingbox\node_modules\node-red\flow\
  • flows in nodes

Where are the sound files?

  • On the non docker version Some sound files are stored into /root/thethingbox/data/sounds/ and you can reach them with samba on \\yourDeviceName\TheThingBox\root\thethingbox\data\sounds\
  • On the docker version Some sound files are stored into /root/sounds/ and you can reach them with samba on \\yourDeviceName\TheThingBox\root\sounds\

How does the menu “import / Node” work?

See here.

The log is sent to the console.

The console log is sent to console.txt in the public folder so it can be read by the client browser. There is a menu item in the NodeRED right menu that opens it.

It is located in /root/thethingbox/node_modules/node-red/public/console.txton the device.

At boot, before starting a new console, a backup is done of in a file named “previousConsole.txt”. That allows to get an error when the device freezes.

Access it using Samba from your PC:

\yourDeviceName\TheThingBox\root\thethingbox\node_modules\node-red\public\previousConsole.txt

How to use the 1880 port?

Edit the PORT var in \root\thethingbox\thethingbox.js

How to add login/password?

Have a look to alexander blog: “Login for Node-Red on TheThingBox” http://www.vdsar.net/login-for-thethingbox/

I want to use HTTPS to access the Thingbox

Refer to “Use HTTPs”.

How can I access the files in the Thingbox?

The easiest way to access the files is to use your own computer: files are published on the network (using a protocol named Samba).

If this popups:

enter root and raspberry (if you didn’t change them, of course).

  • From Windows: Open a file browser and use

    \NameOfmyDevice.local

Windows 10 asks you for credentials? Follow the following tutorial to fix your network: https://tinkertry.com/how-to-change-windows-10-network-type-from-public-to-private

and you should see the files.

  • From Macintosh: In the Finder, choose “all” and you should see the device.

How to create a web server beside TheThingBox

See here.

Access the userdir

Access the userdir (non Docker version)

\\yourDeviceName\TheThingBox\root\userdir

Access the userdir (Docker version)

\\yourDeviceName\TheThingBox\root\container_thethingbox\userdir

How to write Node-RED nodes for the Thingbox?

Look here: How to write a Node-RED node for the Thingbox

And here: How to make NPM Packages for The Thingbox

Set your WiFi manually

To set your WiFi manually on TheThingBox, it must be plugged into ethernet. At boot, TheThingBox display its ethernet IP address. In a web browser, enter this address to have the web interface of your TheThingBox.

Via the menu on the top right, click on the ‘settings’ button, then click on the ‘TheThingBox’ tab. On the panel ‘Static IP’, select the interface to ‘WiFi’ and click on the ‘OK’ button. On the panel ‘WiFi’, select the Wi-Fi’s network you want to use and fill its password, then click on the ‘OK’ button.

On the next boot, your TheThingBox should be connected to your WiFi’s network.

Security

As a developement tool for end users, there is no activated security.

Here are the points to be closed if a end user product is built on top.

  • Samba allows access to files from the network
  • SSH is open with root/raspberry credentials
  • NodeRED UI is not protected with credentials
  • [To Be Investigated] The MQTT command tool (should be ok since it uses a double private/public key encryption)
  • The Linux OS login available with root/raspberry credentials
  • The SDCard can be mounted and acceded as a disk in a virtual machine.

Back to top