· 9 years ago · Oct 17, 2016, 04:32 PM
1#!/bin/bash
2
3echo 'Please ensure your Weather Station HAT is connected to you Raspberry Pi, with the battery installed.'
4echo 'Please ensure your Raspberry Pi is connected to the Internet'
5echo 'Press any key to continue'
6
7read -n 1 -s
8
9##Update and upgrade - especially important for old NOOBS installs and I2C integration
10sudo apt-get update && sudo apt-get upgrade -y
11
12##Enable I2C
13sudo raspi-config nonint do_i2c 0
14
15##Update config files.
16echo "dtoverlay=w1-gpio" | sudo tee -a /boot/config.txt
17echo "dtoverlay=pcf8523-rtc" | sudo tee -a /boot/config.txt
18echo "i2c-dev" | sudo tee -a /etc/modules
19echo "w1-therm" | sudo tee -a /etc/modules
20
21##Check the RTC exists
22if ls /dev/rtc** 1> /dev/null 2>&1; then
23 echo "RTC found"
24else
25 echo "No RTC found - please follow manual setup to Troubleshoot."
26 exit 1
27fi
28
29#Initialise RTC with correct time
30echo "The current date set is:"
31date
32read -r -p "Is this correct [y/N] " response
33response=${response,,} # tolower
34if [[ $response =~ ^(yes|y)$ ]]; then
35 sudo hwclock -w
36else
37 read -p "Enter todays date and time (yyyy-mm-dd hh:mm:ss): " user_date
38 sudo hwclock --set --date="$user_date" --utc #set hardware clock
39fi
40#update system clock
41sudo hwclock -s
42
43#Update hwclock config
44sudo perl -pi -e 's/systz/hctosys/g' /lib/udev/hwclock-set
45
46#Remove hwc package
47sudo update-rc.d fake-hwclock remove
48sudo apt-get remove fake-hwclock -y
49
50sudo apt-get install i2c-tools python-smbus telnet -y
51
52#Install Database software
53sudo apt-get install apache2 mysql-server python-mysqldb php5 libapache2-mod-php5 php5-mysql -y
54
55mysql -uroot -e "CREATE DATABASE 'weather'"
56mysql -uroot -e "USE weather; CREATE TABLE WEATHER_MEASUREMENT(ID BIGINT NOT NULL AUTO_INCREMENT,REMOTE_ID BIGINT,AMBIENT_TEMPERATURE DECIMAL(6,2) NOT NULL,GROUND_TEMPERATURE DECIMAL(6,2) NOT NULL,AIR_QUALITY DECIMAL(6,2) NOT NULL,AIR_PRESSURE DECIMAL(6,2) NOT NULL,HUMIDITY DECIMAL(6,2) NOT NULL,WIND_DIRECTION DECIMAL(6,2) NULL,WIND_SPEED DECIMAL(6,2) NOT NULL,WIND_GUST_SPEED DECIMAL(6,2) NOT NULL,RAINFALL DECIMAL (6,2) NOT NULL,CREATED TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY ( ID ));"
57sudo reboot