Difference between revisions of "OpenSprinkler Pi"

From Rayshobby Wiki
Jump to navigationJump to search
(Replaced content with "* '''Set Up RPi, RTC, WiFi, Data Log'''")
Line 1: Line 1:
= Download Location  =
* '''[[Set Up RPi, RTC, WiFi, Data Log]]'''
It is recommended to use Raspbian “wheezy”. There is unlikely to be any reason to use the slower soft-float version.
= Installation  =
Please refer to the instructions on http://www.raspberrypi.org
== Defaults  ==
{| border="1"
! scope="row" | Login:
| Username: pi<br>Password: raspberry
! scope="row" | IP address:
| via DHCP
== Initial Setup  ==
If you are using your Raspberry Pi without a monitor you will need to run the initial setup manually from the command line when you first log in to it via ssh:
<pre>sudo raspi-config</pre>
= DS1307 RTC  =
The following is collected from various sources:
* http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
* http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time
Edit <code>/etc/modules</code>
sudo editor /etc/modules
And add the following:
Add the modules to the kernel (they will automatically be added on subsequent boots from <code>/etc/modules</code>):
<pre>modprobe i2c-bcm2708
modprobe i2c-dev
modprobe rtc-ds1307</pre>
Comment out both <code>spi-bcm2708</code> &amp; <code>i2c-bcm2708</code> from <code>/etc/modprobe.d/raspi-blacklist.conf</code>
Install <code>i2c-tools</code>
<pre>sudo apt-get install i2c-tools</pre>
Look for ID #68 with <code>i2cdetect</code><br> On a 256MB Raspberry Pi Model B:
<pre>sudo i2cdetect -y 0</pre>
On a 512MB Raspberry Pi Model B:
<pre>sudo i2cdetect -y 1</pre>
The result should look like:
<pre>    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --  </pre>
As root:<br> On a 256MB Raspberry Pi Model B:
<pre>echo ds1307 0x68 &gt; /sys/class/i2c-adapter/i2c-0/new_device</pre>
On a 512MB Raspberry Pi Model B:
<pre>echo ds1307 0x68 &gt; /sys/class/i2c-adapter/i2c-1/new_device</pre>
Check the kernel logs for messages like
<pre>rtc core: registered ds1307 as rtc0</pre>
Then check for time from the clock (which will show <code>Sat 01 Jan 2000</code> if it is the first time it is used):
<pre>sudo hwclock -r</pre>
And then write the current system time to the clock:
<pre>sudo hwclock -w</pre>
The edit <code>/etc/rc.local</code>:
sudo editor /etc/rc.local
and add the following before <code>exit 0</code>:<br> On a 256MB Raspberry Pi Model B:
<pre>echo ds1307 0x68 &gt; /sys/class/i2c-adapter/i2c-0/new_device
hwclock -s</pre>
On a 512MB Raspberry Pi Model B:
<pre>echo ds1307 0x68 &gt; /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s</pre>
= Hardware watchdog =
The following is collected from:
* http://pi.gadgetoid.com/post/001-who-watches-the-watcher
Install <code>watchdog</code>
<pre>sudo apt-get install watchdog</pre>
Uncomment the following line in <code>/etc/watchdog.conf</code>
<pre>watchdog-device = /dev/watchdog</pre>
Edit <code>/etc/modules</code>
sudo editor /etc/modules
And add the following:
<pre># hardware watchdog
Run the following command to activate the module and service:
<pre>sudo modprobe bcm2708_wdog ; sudo service watchdog restart</pre>
= Wifi setup with a static address=
You are generally going to want a static IP address on your Raspberry Pi for OpenSprinkler.
There are two methods of connecting to a WPA network. wpa_supplicant is slightly more complicated but has the advantage that it should automatically reconnect if the network goes away temporarily.
== wpa_supplicant method ==
Edit <code>/etc/network/interfaces</code>
sudo editor /etc/network/interfaces
Add a new entry with the interface name the same as the IDString used in the next step with wpa_supplicant.
<pre>iface &lt;IDString&gt; inet static
address &lt;ip address&gt;
netmask &lt;netmask&gt;
gateway &lt;gateway address&gt;</pre>
Connect to the wifi network through the GUI or wpa_cli or directly edit <code>/etc/wpa_supplicant/wpa_supplicant.conf</code> and then restart the networking service. In all cases make sure you set the <code>IDString</code> to the same as in <code>/etc/network/interfaces</code> or you will not get a static address. If editing the conf file it will look similar to this for a WPA PSK network:
== /etc/network/interfaces method ==
Edit <code>/etc/network/interfaces</code>
sudo editor /etc/network/interfaces
Change the wlan0 interface type from manual to static and entering the following:
<pre>iface wlan0 inet static
address &lt;ip address&gt;
netmask &lt;netmask&gt;
gateway &lt;gateway address&gt;
wpa-ssid "&lt;SSID&gt;"
wpa-psk "&lt;presharedkey&gt;"</pre>
Restart networking with the following command or reboot.
sudo service networking restart
= Remote syslog =
If you have another server setup to act as a syslog server you can send the systems logs to it to reduce the writes to the Raspberry Pi's SD card.
Edit <code>/etc/rsyslog.conf</code>
sudo editor /etc/rsyslog.conf
Comment out all the lines not starting with a $ sign (i.e. all the rules).
Then add the following line:
*.* @
The restart the syslog service:
sudo service rsyslog restart
= Further steps  =
Further installation and configuration is done as per a standard Debian or [[Ubuntu Servers|Ubuntu]] setup.<br>E.g. Network configuration can be done through <code>/etc/network/interfaces</code>
= Data Logging on the Raspberry Pi =
As with all flash memory, the SD card that is used on the Pi in place of a hard drive to hold the operating system and programs has a limited number of write cycles. Programs and data on the card can be read any number of times but new data can only be written to each memory location on the card about ten thousand times. That may seem like a lot and for general programming and updating the OS it is plenty.
A problem arises when you want to have the Pi or something connected to it make frequent changes to one or more files such as for data logging. This can eventually ”wear out” the SD card.
One solution is to attach another storage device to the Pi and use that to hold frequently updated files. You could use a
* Flash drive
* USB hard drive
* Network Attached Storage (NAS)
* Probably even “cloud” storage.
== Flash Drive ==
Using a flash drive to store log files will keep power consumption to a minimum. A flash drive has the same write cycle limitation as the SD card but flash drives are relatively inexpensive and can be swapped out without having to transfer the operating system or programs.
The steps needed to make an attached storage device work reliably with the Pi include:
# Create a mount point for the storage device.This is a location in the file system that gives you a “path” to the attached storage.
# Set up the Pi to automatically mount the device at boot time.
# Move the log file to the attached storage and create a symbolic link from the the file's original location to the actual file on the attached storage.
# If using a flash drive, have a procedure to safely swap out the drive from time to time.
=== Create a Mount point: ===
To make a mount point named “flashdrive” at /media/flashdrive . Issue the command:
sudo mkdir /media/flashdrive
You can name the new mount point anything you like but be sure to substitute the name you give it in the following steps.
=== Mount a Storage device at Boot: ===
Find the ID of the storage device you will be using. Before you plug in the device, type on the Pi’s command line “<code>df –h</code>” (without the quotes). This will give you a listing of the memory usage on the Pi.
Plug in your storage device, wait a couple of seconds for the device to mount, then issue the “<code>df –h</code>” command again. You should now see the added device with its ID as something like “/dev/sda1”.
add the flash drive to the file system table (fstab) with the following commands:
sudo editor /etc/fstab
This opens the file in the editor. Move to the end of the file and add:
/dev/sda1 /media/flashdrive auto auto,user,rw,exec 0 0
Where “sda1” is the ID of the storage device and “flashdrive” is the name of the mount point you created.
Save the file and exit the editor.
Mount the drive (it will happen automatically from <code>/etc/fstab</code> on subsequent boots):
mount -a
The next time your Pi is booted up with the storage device plugged in you should see it in the “<code>df –h</code>” listing and you can use it just like any other directory on the system.
=== Create a Symbolic Link: ===
The instructions in this step are specific to the ospi.py Python interval program running on an OpenSprinkler Pi but should be general enough to be used in other situations.
With your attached storage device mounted, move the log file from it’s original location to the attached storage device. In the case of the ospi.py program, use the command:
sudo mv ./OSPi/static/log/water_log.csv /media/flashdrive/water_log.csv
Create a symbolic link from the file’s original location to the file on the attached storage with the command <code>ln -s [/path/to/file] [/path/to/symlink]</code> In this case:
ln -s /media/flashdrive/water_log.csv ./OSPi/static/log/water_log.csv
The logging program will now operate as if the file is still in its original location but will actually be writing to the attached storage device.
=== Swap Out the Flash Drive: ===
Unplugging a flash drive from a rev 2 Pi will cause the Pi to reboot, you can’t just unmount the attached flash drive and unplug it. It is recommended to shutdown the Pi and swap out the flash drive while the Pi is powered off. The safest way to do this is to issue the command:
sudo shutdown –h now
Once the Py has shutdown, turn off/disconnect the power and change the flash drive then restart the Pi.
== USB Hard drive ==
A hard drive does not have the write cycle limitation but requires more power to operate than a solid state device.
[[Category:IT_Documentation]] [[Category:Hardware]] [[Category:Raspberry_Pi]]

Revision as of 05:28, 12 August 2013