Setup Raspberry Pi Weather Station ============================================================================================================== 1. Download the latest Raspbian distro at https://www.raspberrypi.org/downloads/raspbian/ 2. Unzip the file. You'll get a file called something like 2016-05-27-raspbian-jessie.img 3. Put the SD card into your computer and then transfer the image to the SD card. An 8Gb card is sufficient for the servers. find out the device name of the SD card (e.g. /dev/sde ) sudo fdisk -l unmount the device if it has been mounted sudo umount /dev/sde1 sudo umount /dev/sde2 write img file to card (note this will erase the existing contents of the card completely) cd /home/dave/RaspberryPi/Downloads/Debian sudo dd bs=1M if=2016-05-27-raspbian-jessie.img of=/dev/sde sync 4. Eject or unmount the SD Card and put into the RPi 5. Connect the Raspberry to the network using an ethernet cable. We will set up the WiFi later. 6. Power on the RPi. A red light should glow and after a while the green light should blink (and that means the Linux is booting). A small yellow light tells you if you have network connectivity. 7. Determine the IP address for the RPI. I use Angry IP Scanner but other tools are available. If you are using the HDMI output you can just type: sudo ifconfig 8. ssh to pi ssh pi@ - default password is 'raspberry' configure using the raspi-config utility sudo raspi-config Do the following: 1. Expand Filesystem 2. Change User Password 3. Boot Options. Choose option B1. 4. Wait for Network at Boot - select 5. Internationalisation Options - I2 Change Timezone - set to Europe / London 9. Advanced Options A2. Hostname - choose a new name for your Raspi (e.g. wserver1) A4. SSH - Enable SSH A6. I2C - Enable automatic loading of I2C kernel module A7. Serial - Disable the serial connection Select Finish. Say to reboot request. When rebooted log back in via ssh using the new password you set. 9 Update the OS. sudo apt-get update (this will update the repository database) sudo apt-get -y upgrade (this will upgrade the current packages to the latest version) This may take a while, depending on how old the OS image is at time of installation. When done reboot the RPI (sudo reboot) 10. Add the following to .profile for root and pi user: alias ll='ls -l' EDITOR='vi'; export EDITOR Then run: . .profile Setup WiFi eth0 with static ip addresses ======================================================= sudo vi /etc/wpa_supplicant/wpa_supplicant.conf add lines: network={ ssid="your_AP_SSID" psk="Your_wifi_password" key_mgmt=WPA-PSK } sudo vi /etc/dhcpcd.conf add lines: interface eth0 static ip_address=192.168.1.200 static routers=192.168.1.254 static domain_name_servers=192.168.1.254 static domain_search= interface wlan0 static ip_address=192.168.1.203 static routers=192.168.1.254 static domain_name_servers=192.168.1.254 static domain_search= then reboot: sudo reboot Log in with the new ip address. Backup the RPi SDCard Contents (optional) ========================================= shutdown the RPi remove the sd card & mount on Linux PC find out what device it is using fdisk -l (sdd) cd to wherever you want to save the image cd /home/dave/RaspberryPi/Backups/ backup the sd card contents dd bs=1M if=/dev/sde of=Backup_WeatherPi_$(date +'%Y%m%d-%H%M%S').img ( to restore backup to SD Card use: dd bs=1M if= of=/dev/sde ) Install OWFS ==================================================================== OWFS stands for One Wire File System. It allows the devices on the 1-wire bus to be accessed like a regular file system on the Raspberry Pi. The devices are mounted onto a mount point in the file system, which can be wherever you want. I create a special mount point directly under the root filesystem at /1wire/OWFSRoot. sudo apt-get install owfs ow-shell Create a mountpoint for owfs: sudo mkdir -p /1wire/OWFSRoot Set up the following owfs.conf config file ==================================================================================== /etc/owfs.conf ==================================================================================== ==================================================================================== Mount DLINK1 to copy sqlite database ============================================ as root: mkdir -p /DLINK1 vi /etc/fstab add line: //192.168.1.1/Data/wstation /DLINK1 cifs credentials=/root/.credentials.leo,file_mode=0755,dir_mode=0775 0 0 vi /root/.credentials.dlink1 add lines: username=dave password=B1rthday01 mount -a -------------------------------------------------------------------------------------------------------------------------------------------- Useful command to copy database to DLINK1 -------------------------------------------------------------------------------------------------------------------------------------------- sudo /etc/init.d/piweather4jv2 stop; sudo cp /1wire/OWFSDATA/sqlitedb/piweather.db /DLINK1/sqlitedb/; sudo /etc/init.d/piweather4jv2 start -------------------------------------------------------------------------------------------------------------------------------------------- Auto-start for Java 1.8 PiWeather4JV2 ======================================= vi /etc/init.d/piweather4jv2 add lines: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/bin/sh ### BEGIN INIT INFO # Provides: piweather4jv2 # Required-Start: $remote_fs $network $syslog $named # Required-Stop: $remote_fs $network $syslog $named # Should-Start: piweather4jv2 # Should-Stop: piweather4jv2 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: piweather4jv2 # Description: Start and stop piweather4jv2 application ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin DESC="piweather4jv2 Application" NAME="piweather4jv2" PID=' ' APPJARDIR='/home/pi/NetBeansProjects/PiWeather4JV2/dist' # Location of application jar get_pid() { PID=$(ps uax | grep -i "java -jar ./PiWeather4JV2.jar" | grep -v grep | awk '{print $2}') } d_start() { get_pid if [ "${PID}" != "" ] then echo "${NAME} is already running." else cd ${APPJARDIR} /usr/bin/owfs java -jar ./PiWeather4JV2.jar & fi } d_stop() { get_pid if [ -z "${PID}" ] then echo "${NAME} is not running." else kill -9 "${PID}" umount OWFS fi } d_watch() { get_pid if [ -z "${PID}" ] then echo "${NAME} Not Running. Starting now..." d_start else echo "${NAME} OK" fi } d_status() { get_pid if [ -z "${PID}" ] then echo "${NAME} is not Running." else echo "${NAME} is Running. PID is ${PID}" fi } case "$1" in start) echo "Starting $DESC" "$NAME" d_start ;; stop) echo "Stopping $DESC" "$NAME" d_stop ;; watch) echo "Checking $DESC" "$NAME" d_watch ;; restart|force-reload) echo "Restarting $DESC" "$NAME" d_stop sleep 2 d_start ;; status) echo "Checking $DESC" "$NAME" d_status ;; *) echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|watch|status}" >&2 exit 1 ;; esac exit 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ chmod +x /etc/init.d/piweather4jv2 add it to the rcX.d dirs so it gets auto started on reboot: update-rc.d piweather4jv2 defaults To start manually: service piweather4jv2 start To test: service piweather4jv2 status Add following line to root's crontab to ensure it keeps running * * * * * /etc/init.d/piweather4jv2 watch >/dev/null 2>&1 Setting up Web Server and PHP ============================= Install lighttpd ------------------------------------------- sudo apt-get -y install lighttpd Install php and sqlite module ------------------------------------------- sudo apt-get -y install php5-common php5-cgi php5 php5-sqlite Enable the Fastcgi module which will handle the PHP pages ------------------------------------------- sudo lighty-enable-mod fastcgi-php Modify the web server document root ------------------------------------------- sudo vi /etc/lighttpd/lighttpd.conf Change the following line to read: server.document-root = "/var/www" Restart the web server ------------------------------------------- sudo service lighttpd force-reload Change doc root permissions ------------------------------------------- sudo chown www-data:www-data /var/www sudo chmod 775 /var/www Add user pi to the www-data group ------------------------------------------- sudo usermod -a -G www-data pi ( logout and login again as pi to get the new group ) Create directory for weather site pages ------------------------------------------- mkdir -p /var/www/PiWeb