Configure a Raspberry Pi device to run Node-RED and integrate with Cisco Meraki’s Scanning API, Dashboard API, Cisco Spark API and Google Static Maps API. In this guide, we will create a working product to share valuable real-time data in a Spark room using all of these APIs.

What do I need?

Before you begin, please make sure you have the following items available to continue with the configuration:

Raspberry Pi 3 Model B

pasted image 0 49

Micro-SD Card (suitable for Raspberry Pi 3 Model B use)

pasted image 0 7

Display and HDMI cable (For this example we are using a Cisco DX 70)

pasted image 0 1

pasted image 0 37

Keyboard and mouse (standard USB keyboard and mouse)

pasted image 0 13

pasted image 0 53

Power supply (Micro USB power supply that can supply at least 2A at 5V for the Model 3B)

pasted image 0 62

Download and Install the Latest Version of NOOBS

Next, we need to install the latest version of ‘New Out of the Box Software’; otherwise known as NOOBS.

NOOBS

Be sure to download the NOOBS ‘Offline and network install’ source file.

pasted image 0 29

Once the file has downloaded please check the SHA-1 hash, to ensure file integrity, and then proceed to preparing your blank Micro-SD card. You may use a Micro-SD to SD-Card adapter if required.

To prepare a blank SD-Card for NOOBS, download the SD Formatter Tool (MacOS).

Insert your target SD card into your computer, or an attached USB reader and run the ‘SDFormatter’ utility.

pasted image 0 50

Carefully select your target SD Card and choose the ‘Quick Format’ option (default) and then click ‘Format’. Once this has successfully completed you will see a ‘Card Format complete !’ message.

pasted image 0 36

Click ‘Close’.

Now extract the contents of the NOOBS_v2_4_2.zip file you downloaded in the previous step.

pasted image 0 19

Copy the extracted files onto the SD card that you just formatted, so that the .ZIP file NOOBS_v2_4_2 directory contents are placed in the root directory of the SD card.

Please Note: In some cases, the OS may extract the .ZIP file contents into a folder; if this is the case, please copy across the files from inside the folder rather than the folder itself.

Prior to removal, the root directory of your SD Card should look similar to the below.

pasted image 0 35

Safely eject the SD Card from your reader, and place the Micro-SD card into your Raspberry Pi and power-on.

Upon boot up, you should see a screen similar to the below.

pasted image 0 61

Before you progress any further, please change the default language to ‘English (US)’ and ensure the keyboard is configured for ‘us’ layout.

pasted image 0 44

Please Note: If you forget to update your keyboard layout here, you may need to adjust it post installation by modifying the layout configuration in /etc/default/keyboard.

Next it is time to connect your Raspberry Pi to your local Cisco Meraki wireless network. As you will need Internet access to continue the configuration process, please be sure to connect to an SSID that provides this service.

Click on the ‘Wifi networks’ icon to display a list of available networks, and select the network that you would like to join.

pasted image 0 10

Highlight the SSID you would like to connect to, and enter the required authentication password into the field provided. If your password is correct, you will be connected to the wireless network chosen and should be granted a range of installation package options.

To demonstrate this process, below we will connect to the RPNB_API SSID in the example below. Click on RPNB_API SSID, enter the password into the field box, and click ‘OK’ to continue.

pasted image 0 2

Once successfully connected, you will be presented with the following OS installation options.

pasted image 0 17

Select ‘Raspbian [RECOMMENDED]’ from the extended OS list and click ‘Install’.

pasted image 0 6

Confirm that it is OK to overwrite existing filesystems, by clicking ‘Yes’.

pasted image 0 51

The installation process will then begin. Please be patient. It might take a little while to finish. ; )

pasted image 0 32

Once the installation is finally complete, you will be prompted with the following ‘OS(es) Installed Successfully’ message.

pasted image 0 5

Please click ‘OK’ to continue. The system will then boot into the Raspbian GUI.

pasted image 0 39

Confirm you have Internet connectivity, by browsing or pinging your favorite website and then open a terminal window to continue. In the example below we will open a terminal window and test Internet connectivity at the same time, so we are quickly ready to progress to the next step.

pasted image 0 59

Now that we are connected and online, we will restart the Raspberry Pi to get ready for the next phase of configuration steps; Updating Raspberry Pi Software.

To safely restart your device, enter the following commands into your terminal window:

sudo shutdown -r now

pasted image 0 11

The system will reboot and you will be returned to the Raspbian GUI by which now you are ready to start the updates.

Updating Raspberry PI Software

The next step will prepare your Raspberry Pi with the latest Raspbian updates and also upgrade the Node.js and Node-RED packages.

Open a terminal window and update the system package list by entering: sudo apt-get update

pasted image 0 46

pasted image 0 64

Next upgrade all of your installed packages to their latest versions by entering:

sudo apt-get dist-upgrade

pasted image 0 14

You may be prompted to progress further. Please type ‘y’ and press ‘Enter’ to continue.

pasted image 0 65

Please be patient while the updates complete. It may take a while. : )

pasted image 0 26

Next we need to update Node.js and Node-RED. Luckily, Raspbian should already have Node.js and Node-RED installed by default, and as such, all we need to do is make sure they are running the latest version. This is an easy process and can be completed by entering: update-nodejs-and-nodered

pasted image 0 16

You may be prompted to progress further. Please type ‘y’ and press ‘Enter’ to continue.

Please be patient while the updates complete. It may take a while. : )

pasted image 0 9

pasted image 0 45

So, you’ve managed to upgrade Node.js and Node-RED. Great! Let’s quickly test that Node-RED is working as expected. You can start Node-RED by entering: node-red-start

pasted image 0 47

If you all goes well, you should see a Node-RED console log on the screen and a range of version numbers.

pasted image 0 12

Here we can confirm that, at the time of writing, the latest version v0.17.5 (https://nodered.org) is installed and running. Open up another terminal window now, so you can keep an eye on what is going on with Node-RED.

In the new terminal window, stop Node-RED before we continue, by entering: node-red-stop

pasted image 0 28

Node-RED is now stopped and you should be able to confirm this in the Node-RED logging console window by checking for the string ‘Stopped Node-RED graphical event wiring tool..”.

pasted image 0 18

You can clear this console window by clicking on the ‘X’ in the top right-hand corner of the window, or by typing ‘<Ctrl-C>’ to break out of the running process, and then ‘exit’ to close the window.

Updating NPM, Installing MongoDB and Node-Red Contrib Projects

We are now ready to install other application components and plug-ins required for this MVP project. To begin we will install the recommended Node Package Manager (NPM) version for Node-RED.

This is an easy process and can be completed by entering: sudo npm install -g [email protected]

pasted image 0 3

pasted image 0 27

Next, we will install mongoDB. mongoDB is the database system we will use to store all the data presented by the Cisco Meraki Scanning API. Installing mongoDB can be completed by entering:

sudo apt-get install mongodb

pasted image 0 23

pasted image 0 54

You may be prompted to progress further. Please type ‘y’ and press ‘Enter’ to continue.

Please be patient while this completes. It may take a while. : )

pasted image 0 31

It is now time to install the Node-RED contribution npm’s, which essentially equate to capabilities that can be integrated into a Node-RED instance. These capabilities can be used to create flows that achieve a desired set of outcomes.

Before we start the installation process, be sure to change your current working directory to “/home/pi/.node-red”. You can achieve this by entering: cd .node-red

pasted image 0 40

Please Note: If you chose not to start Node-RED for the first time in the previous section of this document, you will not be able access the directory above as it will not yet exist.

Once you are in the Node-RED directory we can install the various Node-RED modules used in this MVP. To begin we will install the Meraki CMX node package. This can be completed by entering:

npm i node-red-contrib-meraki-cmx

pasted image 0 8

pasted image 0 43

Next, we will install the Cisco Spark node package. This can be completed by entering:

npm i node-red-contrib-spark

pasted image 0 48

pasted image 0 56

Finally, we will install the MongoDB node package. This can be completed by entering:

npm i node-red-contrib-mongodb2

pasted image 0 60

pasted image 0 57

We have now completed the Node-RED module installation phase. It’s time for some housekeeping.

Node-red Housekeeping

We have almost finished preparing the Raspberry Pi device for our MVP project, but before we continue, it would be wise to complete some basic Node-RED housekeeping. This includes changing default listening ports, enabling a Node-RED UI username and password, and ensuring Node-RED starts automatically each time the system is rebooted.

Please Note: Although the steps included in this section constitute some good general security practices, they do not replace a risk and security assessment for any chosen deployment, and should only be considered as a basic starting point. These steps have only been included for the purpose of basic education and to meet the needs of this MVP. Items such as enabling HTTPS/SSL and comprehensive API security are deemed out of scope.

To begin we will select a suitable hosting port for the Node-RED server instance. The default port Node-RED uses for hosting its web page is 1880. As a good practice, it is recommended you host this service on a non-default port. In this example, we will change the node configuration from port 1880 to port 27555. To complete this configuration change, we need to make sure we are still in the Node-RED directory “/home/pi/.node-red”.

If you are unsure, you can check by entering: cd ./node-red

pasted image 0 4

Next, we need to edit the settings.js file and change the hosted port from 1880 to 27555 (or other desired port). A great tool to edit files is ‘vi’. We will not be going over the finer details of ‘vi’ in this document, but if you require some additional information on how to use this command-line text editor, please have a look at this webpage as a starting point:

https://www.tutorialspoint.com/unix/unix-vi-editor.htm

There are many other resources/documents online to help you out.

It is now time to edit the file. You can edit the settings.js file by entering:

sudo vi settings.js

pasted image 0 55

This will open your chosen file for editing. Once you are in editing mode, please change the Node-RED hosted port from 1880 to a port of your choosing. In this example, we are going to work with ‘27555’.

pasted image 0 52

Navigate your way down to the uiPort section and change the port configuration from 1880 to 27555 and then save and exit.

pasted image 0 63

Next, we will enable a username/password combination to provide some level of controlled access to the Node-RED server UI. To complete this, we will once again edit the settings.js file. Prior to editing the file however, we need to generate a salted hash that will represent the password we would like to use to access the Node-RED UI. We will use this hash as part of the configuration file changes applied in the coming steps.

Before we can calculate this hash, however, we need to install another npm module that allows us to create a hash from the command-line using both Node.js and the bcryptjs library. You can install the bcryptjs library by entering: sudo npm i bcryptjs

pasted image 0 41

pasted image 0 33

Now this package is installed, we can create our salted hash. To complete this, we need to once again make sure we are still in the Node-RED directory “/home/pi/.node-red”.

If you are unsure, you can check by entering: cd ./node-red

Next, we need to enter the following command, where <password> is the password of your choosing:

node -e “console.log(require(‘bcryptjs’).hashSync(process.argv[1], 8));” <password>

In the example below, we will calculate the hash value for the password ‘meraki’.

pasted image 0 38

pasted image 0 34

As you can see, the hash value for ‘meraki’ has been calculated as:

$2a$08$H15WmD7M4bfowdyGK5woge3ITpY0cWtbRKSPxf4WhwQcWXDGBtlbi

Last but not least, think of a login username you would like to use to access the Node-RED UI. For this example, we will use ‘redadmin’. So essentially our username/password pair will be redadmin with a password of meraki (not a good complex password, but you get the idea). We now have everything we need to edit the Node-RED settings.js file and enable UI authentication.

It is now time to edit the file again. You can edit the settings.js file by entering:

sudo vi settings.js

pasted image 0 24

Once you are in editing mode, scroll down to the ‘Securing Node-RED’ section of the settings file and uncomment the ‘adminAuth’ function, by removing all of the forward slashes associated with this function.

Once you have completed this, edit the ‘username’ field value to reflect the login username value you would like to configure, such as ‘redadmin’.

Next, replace the ‘password’ hash value with the value generated by the bcryptjs library in the previous section, such as ‘$2a$08$H15WmD7M4bfowdyGK5woge3ITpY0cWtbRKSPxf4WhwQcWXDGBtlbi’.

Finally, save and exit the file.

If you have done everything correctly, what you have essentially achieved, based on the example above, is enabled admin authentication on the Node-RED instance, changed the administrator login username to ‘redadmin’, and changed the login password to ‘meraki’.

You can see an example of these changes below.

pasted image 0 30

pasted image 0 42

Before we test our new login credentials, we will configure Node-RED to automatically start upon reboot. This will make sure that the service is always running and will not require manual intervention to restart, should a power outage or software issue occur.

To enable Node-RED to start as a service, please enter:

sudo systemctl enable nodered.service

pasted image 0 58

pasted image 0 21

Now that the Node-RED configuration file changes are complete, let’s restart the system and make sure Node-RED automatically starts up at boot, and that UI authentication works as expected as per the chosen configuration parameters.

To restart, enter the following commands into your terminal window:

sudo shutdown -r now

pasted image 0 15

The system will reboot and you will be returned to the Raspbian GUI. Next open up the browser, by clicking on the ‘globe’ icon.

pasted image 0 22

Once the browser starts, enter the following URL into the Address Bar: http://localhost:27555

This URL represents the non-standard port configuration we applied earlier as part of the example we are working through.

If all is well with your configuration, you should be prompted with the following screen.

pasted image 0 25

Next, enter your username and password pair, as configured: redadmin/meraki

pasted image 0

Next click ‘Login’ to authenticate your session to the Node-RED UI. You should now be presented with the Node-RED UI screen.

pasted image 0 20

Congratulations!! It’s time to move onto the next configuration phase. We will come back to the Node-Red UI again soon.