Upgrading Nodejs on Raspberry Pi 2

I read about using the n helper for node to perform an upgrade, however this did not work for me.  Instead, I added another source and upgraded with apt-get.

If you see another way which consistently works, please let me know.  This worked for me, I had version 0.10 and this upgraded me to 0.12.

NOTE: I ran this as root, as sudo did not work.

You may want to perform an upgrade of packages before you do this.

The process should look something like this.

Then use apt-get to perform the upgrade.

The upgrade should look similar to this.


As I use node for node_red, I restarted node_red after the upgrade.  I experienced no issues with node_red after the upgrade to 0.12.


UPDATE 29 April 2016: Upgrading to other newer versions of node.js works this way too.  I recently just upgraded to v6 this same way, just use a different url.  You can find the urls for different versions here.  Although make sure that you check dependencies for other programs which depend on it, like node_red.



Static IP Address on Raspberry Pi 2

Using Raspian, howto set a static IP Address on the Raspberry Pi 2.

To set the Pi to a static IP address, you need to know the following:

Note:  You should verify with your router configuration that the above details match network settings.  If you do not, it may result in not being able to connect to your raspberry pi on the network or your raspberry pi may lose access to everything outside your network.

Now you edit /etc/network/interfaces and replace iface eth0 inet dhcp with iface eth0 inet static and add the information as above.  Example below, replace with information to suit the network settings for your Pi.

Now reboot

Installing Emoncms on Raspberrry Pi 2

Emoncms can do some great input processing and visual dashboards, along with many other things. Below is the process I used to install it on a Raspberry Pi 2 using Raspian.

Install Dependencies

Install all the dependencies.

During this install, it will prompt you for further information. Install pecl dependencies (redis and swift mailer)

Add pecl modules to php5 config

Configure dependencies


Configure redis to run without logging or data persistence.

Comment out redis log file and all the redis saving.

Then restart the Redis service


Emoncms uses Apache to route requests, so modrewrite needs to be enabled.

Modify the Apache2 config to allow rewrite.

Change (line 7 and line 11), AllowOverride None to AllowOverride All. Comment out line # CustomLog ${APACHE_LOG_DIR}/access.log combined Comment the access log to other-vhosts (add #)

Now Reboot the Pi

Install Emoncms

For the install Emoncms, it will be installed from the git repository for Emoncms. First, lets setup the web directory and permissions.

Download Emoncms from the git repository. For this we’re using a cloning a specialised version of Emoncms which has been designed to write less to the SD Card.

Configure Emoncms


Lets setup the mysql database for Emoncms. If you would like to move the mysql database to another location (for easier backup,etc), now is the time to do it. For this, I’ve chosen to move the Mysql database to /home/pi/data/mysql. I first create the directory and then copy the mysql data accross.

Now update the mysql configuration file to use the new location.

change line datadir to /home/pi/data/mysql Create the Emoncms database.

This will prompt you for a password and the following SQL will create the database.

Now create a user and assign permissions that Emoncms will use to access the mysql databse. In the commands below, update username and password to suit your choice.

Data directory

Now we create some directories were the Emoncms’ feed engines ( phpfina and phptimeseries) will store data. I chose /home/pi/data/.

Emoncms Configuration settings

Lets setup the configuration file for Emoncms. We copy the default.settings.php to settings.php.

Now we update the settings to suit this installation of Emoncms.

Update the following things: Database Settings. Update these to the username and password you created previously when setting up Mysql.

If you chose a different location to store your data directory earlier, update these lines to suit your data directories.

Setup the feedwriter script as a service.  Copy the service script to /etc/init.d/, update permissions and enable for service.

Now go to a web browser and go to the emoncms website. Update the IP-Address below to your host.

Click Register and create yourself a new Admin user. After you have successfully logged in and do not want to create any other users for this Emoncms, it is best to disable the register functionality. To do this, we edit the settings again.

And change $allowusersregister to FALSE.

As you have now gone through the initial setup for Emoncms, you can also disable the dbtest.


The following log entries should be created and help with this.



Installation of Pywws on Raspberry Pi 2 for Weather Station

This is the process I followed to install pywws on a Raspberry Pi 2 on Raspian.  I have a 3080 compatible weather station connected to the Raspberry Pi 2 via USB.

Install Dependencies

As pywws is written in Python, it has a few dependencies which need to be installed on the Raspberry Pi 2.  I like to make sure that before this I update to the latest updates.

Now install the python, libusb and gnuplot.  Libusb as we need to access the weather station via USB and gnuplot in order for draw graphs with pywws.

There are other dependencies if you want to use other features or pywws (eg. twitter), but these will give you the basics to get pywws up and running.  Other dependencies can be found here.

Install Pywws and permissions

After all the required software is installed, you can install pywws.

After it has installed, plug in the internal weather station unit to the Raspberry Pi 2 via USB. Now you can test to ensure it can talk to the weather station.

This command should produce some output that looks like this.

If this does not work, further information is available at http://jim-easterbrook.github.io/pywws/doc/en/html/guides/getstarted.html which may help. You have to run pywws in python using sudo. It is much better to run it as the user Pi and the give the Pi user access to the USB port. First create a group to grant the access and add the Pi user to the group

You need to identify the idVendor and idProduct for your WeatherStation that is plugged into the USB port. Look into the kernal log file.

Look for idVendor and idProduct, mine were idVendor=1941 and idProduct=8021. My kern.log look like this.

To modify the USB, create a rule that sets the usb port to the group weather

Copy and paste the following into this file. Make sure you update the idVendor and idProduct to suit your USB.

After you’ve saved and exit, reboot the Pi. Once the Pi has started again, test connecting to the weatherstation as user Pi, without sudo.

You should get the same results as you did above when you tested using the command with sudo. As we’ll be running this as user Pi, ensure that all the weather data is owned by user Pi.

Configuration of Pywws

I wanted readings every 5 minutes from the weather station and as pywws can easily read and log the weather station data every 5 minutes (recommended setting is 5min too), this was ideal. So, I set the weather station to log every 5 minutes.

It’s worth noting that the memory in the internal unit is not very large and although it will buffer some data, it cannot hold very much weather data. Now to setup where to log the data.  I chose /home/pi/data/weather, but it could be anywhere.  If a different directory is used, update the url through the rest of this page to the select directory.

All the weather station’s logged data should go into this directory. As per the getting started doco above for pywws, we now need to setup the timezone and weather station type. We will need to run the following command and it will create the configuration files the first time it is run.

The configuration files are found in the data directory /home/pi/data/weather/data. I adjusted the following in the weather.ini configuration file.

There is a full page in the doco about the weather.ini configuration settings here. I also update the configuration paths in the weather.ini file.

My full weather.ini looks like this.

Now create these directories and copy the pywws examples into them.

Then we run the command again.

This will probably need to run for a while to download the data. It should have some output similar to this.

So now that the weather station data can be downloaded, I want to setup a service that will run to download the weather data. There are two options, an hourly update or a live logger. I opted for the live logger as I wanted data updated as close to every 5min as possible. Pywws comes with a livelogger than can run as a daemon.  It can be run like this.

While this works well, it will not start automatically. A service init script is much easier to manage for me. Create a new init.d file by running the following.

Now copy and paste the following into this file. Update the DAEMON, DATADIR and LOGFILE to suit your installation.

Once the init script has been saved, it needs to be made executable and added to rc.d so it will start and stop at startup and shutdown.

You can also start/stop pywws as a service.