I have had a good share of frustration with damaging Raspberry Pi SD cards due to wearing out/improper shut downs as a result from power failures and was looking for solution to this sort of problems for a while.
At first I thought I had the wrong SD cards, then that my power supply wasn’t good, then that I wasn’t running the latest kernel version, tried to reduce writes to the card by fiddling with swap files, using RAM disks, moving the root fs to external drive and so forth. Finally I came to the conclusion that you can’t expect from SD card based OS running in R/W mode to be reliable in the long term.
SD cards do wear out when written to and are quite sensitive to powering down while a write operation is in progress. Chances are that sooner or later you will end up with a bad SD card. In my case it was always sooner. As I have mentioned in my post yesterday, I have found a ready to use SD card image that runs the root file system in read-only mode. That means you never have to worry about SD card wear or power failures. The down side is that you can’t run applications that require R/W disk access, like MySQL database for example. You can switch temporary between R/W and R/O modes to perform updates, new software installation.
In my case I’d like to have the RFM2Pi board forward the wireless transmissions to external and more reliable emoncms installation. Here are my steps:
- I grabbed the IPE– Industrial Perennial Environment is a special blackout-proof flavour of Raspbian. Used root/root as username/password
- I ran “firstboot” as recommended to expand the SD card to its full size.
- Swithed the root fs to R/W mode so that the following steps can happen by running
ipe-rw
- I configured the networking for my LAN
nano /etc/network/interfaces
- I had to re-create the SSH keys so that I am able to SSH into the Raspberry Pi
sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server
- I had to make sure that Raspberry Pi’s UART is disconnected from the console and available for programs to use. The problem here is that /boot/cmdline.txt is mounded on a R/O partition, easiest way is to insert the SD card in a computer and edit that file there. Remove the text that make reference to the UART i.e.
console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
- Run
nano /etc/inittab
At the bottom of the file comment out the line (by adding a ‘#’ at beginning)
# T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
[Ctrl+X] then [y] then [Enter] to save and exit
Now that the UART is free to use, I need to set up the RFM2Pi software.
I’d like to thank Jerome Lafréchoux for his great work on creating a python gateway script that will interface the RFM12B to emoncms. Setting it up is easy:
sudo apt-get install git-core git clone http://github.com/Jerome-github/oem_gateway.git cd oem_gateway cp oemgateway.conf.dist oem_gateway.conf nano oemgateway.conf
The configuration file oemgateway.conf contains the configuration settings and is pretty straight forward to understand. I needed to forward RFM2Pi readings to a remote emoncms, so my configuration looks like this:
# OemGateway Configuration file example # Copy this as oemgateway.conf (or any custom name) and edit settings # Each listener and each buffer has # - a [[name]]: a unique string # - a type: the name of the class it instantiates # - a set of init_settings (depends on the type) # - a set of runtime_settings (depends on the type) # Both init_settings and runtime_settings sections must be defined, # even if empty. Init settings are used at initialization, and runtime # settings are refreshed on a regular basis. # All lines beginning with a '#' are comments and can be safely removed. #################### # Gateway settings # #################### [gateway] # loglevel must be one of DEBUG, INFO, WARNING, ERROR, and CRITICAL # see here : http://docs.python.org/2/library/logging.html loglevel = DEBUG ############# # Listeners # ############# [listeners] # This listener manages the RFM2Pi module [[RFM2Pi]] type = OemGatewayRFM2PiListener [[[init_settings]]] com_port = /dev/ttyAMA0 [[[runtime_settings]]] sgroup = 210 frequency = 8 baseid = 15 sendtimeinterval = 60 # This listener gets data from a socket [[Socket]] type = OemGatewaySocketListener [[[init_settings]]] port_nb = 50011 [[[runtime_settings]]] ########### # Buffers # ########### [buffers] # The two following buffers instantiate the same class, # that formats the data for an emoncms instance. # One sends the data to a local instance, the other one # to a distant one. # If active is set to False, the buffer neither records nor sends any data, # but it holds unsent data until active becomes True. [[emoncms_local]] type = OemGatewayEmoncmsBuffer [[[init_settings]]] [[[runtime_settings]]] domain = localhost apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx protocol = http:// active = False path = /emoncms [[emoncms_remote]] type = OemGatewayEmoncmsBuffer [[[init_settings]]] [[[runtime_settings]]] domain = emoncms.org apikey = ************MY API KEY ******************* protocol = http:// active = True path =
Finally I had to set that the script runs at each boot by adding the following line to /etc/rc.local, just before the “exit 0″ statements:
(sleep 10; python /root/oem_gateway/oemgateway.py --config-file /root/oem_gateway/oemgateway.conf)&
A reboot and we are in business. Finally a Raspberry Pi RFM2Pi gateway that isn’t afraid of power failure or SD card wear.
(68)