Skip to content

Commit

Permalink
Merge pull request #5 from phamduchongan93/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
phamduchongan93 authored Jun 12, 2023
2 parents 43dfccf + ee596ac commit fd5cacd
Show file tree
Hide file tree
Showing 36 changed files with 8,121 additions and 31 deletions.
167 changes: 136 additions & 31 deletions communitygarden-cli
Original file line number Diff line number Diff line change
@@ -1,26 +1,106 @@
#!/bin/bash
# Author: An Pham, Myriam
# Filename: communnity-garden.sh
# Version: testing

# declaring modules function
## declaring modules function
clean () {
sudo_check
apt-get clean
apt-get autoclean -y
apt-get autoremove -y
}

print_status(){
local message="$1"
local status="$2"

# Get the number of columns, but subtact 8 to leave space for the status.
local columns=$((COLUMNS-8))

# Print left-aligned message and right-aligned status.
printf "%-*s [%s] \n" "$columns" "$message" "$status"
}


install_essential () {
apt install python3-configobj python3-pil python3-serial python3-usb python3-pip
# pacakges require for network wifi
apt install network-manager
}

sudo_check () {
if [ "$EUID" -ne 0 ]
then echo "Please run as root or with sudo"
exit
fi
}

checking_weather_station_connection () {
ls /dev/ttyUSB0
[ "$?" = 1 ] && print_status "Finding Davis Weather station ..." "Ok" || print_status "Finding Davis weather station ..." "Fail"
}

install_weewx_dependency () {
# tested
sudo_check
apt install python3-cheetah
apt install
apt install \
python3-configobj \
python3-pil \
python3-serial \
python3-usb \
python3-pip -y
pip3 install Cheetah3
}

install_weewx () {
install_weewx_dependency
download_and_install_weewx
install_database
}

download_weewx () {
echo "Downloading weewx file"
wget -o weex-4.10.2 https://weewx.com/downloads/weewx-4.10.2.tar.gz
[ "$?" = 1 ] && echo "Failed to download weewx" & exit 1
enable_weewx () {
cd /home/weewx
cp util/systemd/weewx.service /etc/systemd/system
systemctl enable weewx
systemctl start weewx
}

status_weewx () {
systemctl status weewx
}

uninstall_weewx () {
systemctl stop weewx
systemctl daemon-reload
rm -r /home/weewx
rm /etc/systemd/system/weewx.service
}

print_line () {
echo "============================"
}

download_and_install_weewx () {
local weewx_url='https://weewx.com/downloads/weewx-4.10.2.tar.gz'
local weewx_dest='/var/temp/weewx/'

mkdir -p "${weewx_dest}"
print_line
echo "Downloading weewx file..."
wget -o "${weewx_dest}weex-4.10.2" "${weewx_url}"
[ "$?" = 1 ] && print_status "Downloading weewx file..." "Ok" || print_status "Downloading weewx file.." "Fail"
cp -v weewx-4.10.2.tar.gz "${weewx_dest}"
cd "${weewx_dest}"
print_line
echo "Extracting downloaded file"
tar xvzf weewx-4.10.2.tar.gz
cd weewx-4.10.2
python3 ./setup.py build
python3 ./setup.py install
[ "$?" = 0 ] && echo "Success. The application has been installed at /home/weewx " || echo "Failed to install weewix"
print_line
enable_weewx
}

wifi_check () {
Expand All @@ -31,7 +111,8 @@ wifi_check () {
install_wifi_private () {
local username=${1}
local password=${2}

# WARNING: do not remove the line below,. This is used as backup for comfinguration.
cp -v /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
cat << EOF > /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="eduroam"
Expand All @@ -49,14 +130,9 @@ EOF
wpa_cli -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
}

install_weewix () {
apt-get update
apt-get install weewx
}

install_database () {
# Required if you are using MySQL (MariaDB):
apt install mariadb-client python3-mysqldb
apt install mariadb-client python3-mysqldb sqlite3 -y
}


Expand All @@ -67,19 +143,49 @@ main () {
do
case "$1" in
--install-dependency )
install_dependency
install_essential
shift
;;
--install-weewx )
download_weewx
install_weewx
shift
;;

--install-weewx )
download_weewx
--enable-weewx)
# tested
enable_weewx
shift
;;

--database-sql )
# tested
install_database
shift
;;
--clean|-c )
clean
shift
;;
--install-wifi-eduroam )
shift
# school username and password without @edu
install_wifi_private "$1" "$2"
shift
;;
--download-weewx )
download_and_install_weewx
shift
;;
--uninstall-weewx )
uninstall_weewx
shift
;;
--check-weather-station )
checking_weather_station_connection
shift
;;
--status-weewx )
status_weewx
shift
;;
--version | -v)
echo '1.0'
shift
Expand All @@ -94,22 +200,21 @@ main () {
done
}


##
help () {
echo "Usuage: $(basename $0) <--con|--dis|-a|-ac>. First, edit the variable to match your bluetooth interface MAC address. "
echo "Usuage: $(basename $0) <--install-dependency|-v>. First, edit the variable to match your bluetooth interface MAC address. "
echo ''
echo 'Where:'
echo ' -r,--restart restart the bluetooth headset connection'
echo ' -l,--list show current bluetooth devices'
echo ' --dis,--disconnect disconnect bluetooth headset'
echo ' -a,--audio connect with audio only'
echo ' -ac,--audio-mic connect with both audio and mic'
echo ' -m,--mute mute the audio'
echo ' -um,--unmute unmute the audio'
echo ' -i,--install install dependency'

echo ' --install-dependency install essential dependency'
echo ' --install-weewx download and install weewx'
echo ' --download-weewx download weewx only'
echo ' --uninstall-weewx uninstall weewx'
echo ' --status-weex check status of weewx'
echo ' --clean | -c clean unused packages'
echo ''
echo 'Example:'
echo " $(basename $0) -c | --check Check if the device is connected"
echo " $(basename $0) -v | --version Check the version of the program "
}

main "$@"
18 changes: 18 additions & 0 deletions docs/analysis/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Alternative Analysis


| | Alternative 1 ( Running EC2 VPN) | Alternative 2 ( Running router) | Alternative 3 (reactivate 4g providers) |
|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|--------------------------------------------------------------------------------------------------------------|
| Initial Cost | $0.00 | $40.00 | $0.00 |
| Monthly Cost | $7.00 | $0.00 | $90.00 |
| Expected Time (months) | 9.00 | 9.00 | 9.00 |
| | | | |
| | Description | IT and campus Involvement | Benefit |
| Alternative 1 | Initiate Eduroam wifi from the school and spin up VPN server | High | Bypass IT firewall. Student credential is stored on the sd card (security issue). Can deploy more services. |
| Alternative 2 | Purchase router to connect campus network | Medium (due to isolation) | Private network, but the cost is high when two stations are in different locations |
| Alternative 3 | Reactivate 4g providers $90 for 2 sensors station. | none | |
| Alternative 4 | Activate 4g hotspot $25 per station | none | private network, two stations can connect one hotspot. |
| | | | |
| **Note** (An) | I would recommend the first 2 months of the project to rely on the network campus without disclosing the services deployed, since most of the sensors don’t require a lot of bandwidth. However, throughout the project, the bandwidth will increase knowing video streaming services would be deployed and implemented (due to outdoor camera devices), which is believed to start in the Fall semester. | | |
| Researcher | An Pham, Myriam Boutros. | | |

1 change: 1 addition & 0 deletions docs/analysis/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_name: Alternative Analysis
17 changes: 17 additions & 0 deletions docs/community-garden/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Welcome to MkDocs

For full documentation visit [mkdocs.org](https://www.mkdocs.org).

## Commands

* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs -h` - Print help message and exit.

## Project layout

mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.
Binary file added docs/community-garden/docs/weewx-data-logger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/community-garden/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_name: Community Garden
17 changes: 17 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Welcome to MkDocs

For full documentation visit [mkdocs.org](https://www.mkdocs.org).

## Commands

* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs -h` - Print help message and exit.

## Project layout

mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
site_name: My Docs
11 changes: 11 additions & 0 deletions modules/install_wireguard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Name: install wiregoard on server


generate_private_key () {

}

generate_public_key () {
sudo_check
cat /etc/wireguard/private.key | wg pubkey | sudo tee /etc/wireguard/public.key
}
1 change: 1 addition & 0 deletions modules/mqtt_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/python 3
4 changes: 4 additions & 0 deletions modules/simulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# Description: Use to simulator data when weather station is offline.
# Name: An Pham
# resources: https://karellen.blogspot.com/2014/08/weewx-with-simulated-data.html
Loading

0 comments on commit fd5cacd

Please sign in to comment.