Regular reader will know about the script that Aidan Ruff and I originally developed to put Node-Red and several other packages onto the Raspberry Pi for our own home control purposes. This has been developed with help from several people and in particular my friend Antonio “Mr Shark”.
WELL – here is the script which is intended to help set up certain Raspbian, Debian or similarly-based SBCs which now includes logging and handling Raspbian Stretch (tested on Raspberry Pi 2 and 3, 3B+). As well as it's original purpose of setting up a Raspberry Pi, the script also runs well with several other boards. See right hand side of the above image for what the script does, given a basic operating system install. We currently suggest NOT using this with DIET PI or the Raspberry Pi Zero as we are no longer testing either and the latter is just TOO SLOW.
February 18 2019
Raspbian and Pi Zero Wireless – users have reported success with latest update but we’ve not tested.
The local Blynk server is not installed in the script – see this blog entry, note that I now use all lowercase for the blynk directory name.
Still using Apache but soon will change to NGINX – also whichever web server you use – if you plan to use node-red-contrib-amazon-echo – you might want to shift the working port for Apache (or NGINX) from 80 to 86. Do this in /etc/apache2/sites-enabled/000-default.conf (one reference to change) or if you ARE using nginx change /etc/nginx/sites-available/default – two references to 80 change to 86 (my choice). The Amazon echo hub in NR I then set to 8980 and rebooted. The next para is taken from “A Good Day for Alexa” blog entry:
I am using port 8980 to avoid being the hated Linux ROOT user and so now, on my Raspberry Pi 3, I moved the web server to port 86 and using “iptables” have redirected port 8980 traffic to port 80 to keep Amazon happy while continuing to use port 8980 to keep Linux happy as PI user. All of this of course only matters if you want to use that particular node in Node-Red- with generation 3 DOT and similar Alexa devices.
sudo apt-get install iptables-persistent
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8980
sudo netfilter-persistent save
sudo netfilter-persistent reload
March 2 2019 - Just added a useful file/directory operations node to the installed Node-Red nodes along with the strangely missing node-red-contrib-influxdb node. Note that in order to use this you must have opted to install Grafana and Influxdb. Databases in Influxdb are added at the command line (I do this as user pi) simply by invoking the command “influx” and once in, using the commands “CREATE DATABASE mydatabase” followed by “exit”. All without quotes and using your choice of database name.
February 2019 – I’ve uploaded a new version with mods for Raspbian and in particular Node-Red and nodejs v10.x as currently used by the Node-Red guys on the Raspberry Pi.
Raspberry Pi users should log in a user PI and start with a clean Raspbian. Enable any hardware you want working before installing the script – like I2c.
Raspberry Pi users get the script in your /home/pi directory as below. Non-Raspberry Pi users start in your ROOT directory as user ROOT, initially.
Here’s how to get the script – 2019 version.
wget --no-check-certificate https://bitbucket.org/api/2.0/snippets/scargill/qexexb/master/files/script.sh
Originally designed to run under Debian – reader Antonio and I have also made the script compatible with Xenial in some cases. It now handles Raspbian and the Armbian versions of Debian and Xenial (Ubuntu).
One issue I have occasionally with new boards is lack of remote root access to install the script. For example on a Banana Pi 3 I had this.. there was PI access for the likes of WinSCP but not root access. This was easily solved as user Pi - after using "sudo passwd root" to ensure I had a known root password.
sudo sed -i 's/prohibit-password/yes/' /etc/ssh/sshd_config
sudo systemctl restart sshd
That won’t work in all cases but I’m parking that here for reference.
The easiest way to get the pre-2019 script – as ROOT user, in your ROOT directory is:
wget --no-check-certificate https://bitbucket.org/api/2.0/snippets/scargill/ekon6o/master/files/script.sh
This can now be run easily: bash script.sh – run as user root, it will start up, copy itself into PI user area, creating that if it does not exist then will give instructions.
Before I begin... no, we’re not a support shop – you may or may not end up having to tweak things for your system but please don’t write in to say “I tried this on a Mac and it doesn’t work”.
The level of interaction after the beginning is now almost zero thanks to a new menu-driven approach and many improvements. We continue to add/modify features as appropriate.
What is this about?
What we have here is an old explanation of how to get Xenial running in a VM – the purpose of this is merely as a base to test the script which includes installs and set-ups as below:
- Node-Red at port 1880 and lots of useful NODES
- Mosquitto (MQTT) with Websockets
- Webmin at port 10000
- Apache at port 80
- HA-Bridge at port 82 (suitable for Amazon Alexa)
- SQLite and PHPLiteAdmin
- MC File manager and editor
- Grafana with InfluxDB (only tested on a few setups – so OFF by default)
- Lots more – see the menu screen
Typically this setup would be used as the basis of a nerve-centre to control and monitor home control gadgets such as the ESP8266 units we discuss in this blog, Sonoff controllers and much more. Armed with this software, controlling the home is easy – and more importantly can be done YOUR WAY.
The Virtual Machine
Let’s take a look at what we did to get this running on a VM – you can of course duplicate all of this as you go along. We used the excellent VMware of VirtualBox on Windows PCs. This explanation covers VMware.
So – first things first – as I’ve done a video of the VirtualBox installation complete with sample use of Node-Red, here we’ll discuss the VMWARE version. Both of these were done as test mechanisms before using the script on real devices such as the Orange Pi Zero, Raspberry Pi, Odroid and other devices discussed at length in the blog.
We loaded up a copy of VMware (I used VirtualBox but the procedure is similar – VMware player is free of you can use the full commercial workstation) and made sure it works. That much is up to you. There is a wizard for creating new virtual machines - we chose a CUSTOM machine. Steps from that point on were:
NEXT - NEXT – “I will install the operating system later” – NEXT
Linux / Ubuntu 64-bit – NEXT – d:\test - NEXT
Number of processors – 1 - number of cores – 1 – NEXT
Memory for this machine – 1024MB – NEXT
Use Bridged Connection - NEXT
I/O Controller type LSI Logic - NEXT
Disk Type SCSI - NEXT
Create a new virtual Disk - NEXT
12GB (I used 16GB – 8GB would have done) – Store virtual disk as a single file - NEXT
At this point we gave the file a name – in our case d:\test\Ubuntu 640bit.vmdk - NEXT – FINISH
Under settings – hardware – CD/DVD we ticked “Use ISO image file” and selected the file we loaded from the Ubuntu website – “Ubuntu-16.04.1-server-amd64.iso” – OK.
At this point you’ll note reference to AMD64 – that had me as well but it works a treat on INTEL hardware.
Start off the VM – you get asked which language to use (ENGLISH) and various options will come up – the first being “Install Ubuntu Server” – that’s the one.
Once again you’ll get a language question – English. Location – in my case “United Kingdom” – if you don’t fit into the rules use “Other”.
Time Zone in my case – EUROPE and then country. Locale – in my case United Kingdom.
Hostname – we went with the default “Ubuntu” – but call it whatever you want.
At this point you get asked to create a user – it is important you make a user “pi”. Enter password also (though the new script will create user PI if it does not exist).
Partitioning – “use entire disk” (remember this is a virtual disk – not your real disk). You are then asked to confirm erasing disk – go with that. You then get asked to confirm AGAIN. YES.
HTTP Proxy just leave blank – CONTINUE.
Install security updates automatically.
Add OpenSSH server and CONTINUE (important for remote access)
Install GRUB bootloader – YES.
Installation is complete – CONTINUE. Let it run.
And voilà – one working copy of Ubuntu.
When run, the script will generate a Pi user if it does not exist - will make that user part of the correct groups and will ask you to restart the script as user Pi.
The BASH Script
This part is about running the script and the easiest way is to start in a terminal as user ROOT in the root directory.
do the WGET shown above and you will end up with a script file called “script.sh” in the root directory.
At this point BACK EVERYTHING UP to avoid disappointment – no, REALLY.
The script will if necessary create the Pi user but either way will now ask you to log in as user pi and repeat the procedure in the /home/pi directory - i.e. bash script.sh.
The point of this is to avoid another way which would be to create a file, load in the script contents ensuring you’re using Linux LF only format – then run the script after setting up permissions – this way you don’t have to do any of that.
In the end you will see a menu which will vary slightly depending on which system you are using – you won’t be asked about GPIO on a Raspberry Pi for example.
For the VM we left everything as you see here and tabbed to OK.
At this point you will be asked for a USER and ADMIN names (which can be user and admin if you like) and corresponding passwords. From there on – everything should happen with no user interaction.
After maybe 15 minutes to an hour - or a LOT longer on a Raspberry Pi Zero WIFI – you’ll see an invite to REBOOT – so REBOOT. When the board/VM boots up you will find hopefully a working system.
Assuming you've installed everything:
- Node-Red runs at port 1880
- Webmin at port 10000 (Webmin needs Pi or ROOT username and pass until we figure out how to add in the ADMIN user).
- Apache runs at port 80
- HA-BRIDGE will run at port 82 – It seems that Amazon Echo is quite happy with this but the Google product wants port 80!
Node-Red should include MQTT which will need admin username and password as will Node-Red itself. USER name and password is used by Node-Red Dashboard.
There is also the excellent MC – a file manager and editor.
I hope this brief introduction sets you off in the right direction and of course no doubt there will be discussing in the notes below.
Update 05 Jan 2017: At the time of writing I'm having issues with PIXEL in VirtualBox and DEBIAN on VirtualBox in terms of Apache not loading.. I'm sure we'll sort that - meantime some useful links. Debian may not come with SUDO depending on which installation - here's a fix link that worked for me in my VirtualBox image.. If SSH setup won't allow remote access using passwords, here's a link that helped me. Pixel of course will run in VirtualBox but by default it runs of a virtual DVD which is about as much use as an ashtray on a motorbike as nothing gets saved. Once running however it is a breeze to move over to the Virtual hard disk - you'll find that part way down the comments in this link. So right now I have VirtualBox running Xenial, Pixel and Debian and the only issues I have are with Pixel and Debian - Apache - watch this space. I’ve also improved the input for user and admin.
Important: Whatever you are using should have the SUDO command built in – it may not be obvious but Debian often does NOT have this installed by default – sort this FIRST. You should also make sure you have Pi user with SUDO group privilege – PI already has this of course and you may have added a user Pi – if not..
su -c "bash makepi"
Or, Here’s a useful link – takes seconds and is easy… basically – as root you can do - apt-get install –y sudo….. and you should make sure that your PI user is part of the sudo group.
The script works with both NanoPi NEO2 and the NanoPi M1+ and features temperature monitoring and other improvements.
If doing this as a non-Pi user – i.e. ROOT on a machine with no Pi user – follow instructions above OR a slightly easier way…
Having uploaded the script and given permissions… as ROOT
as before – but when it has completed and wants you to log in as PI – stay where you are and:
su - pi -c /home/pi/script.sh
That might save you a little hassle.
Update 19 Aug 2017: Script updated to handle Raspbian Stretch on Raspberry Pi – tested on RPi 3. Also added code to help with non-root access to GPIO using ONOFF library. See blog entry on GPIO.