Skip to content

Commit

Permalink
Merge pull request #21 from hudsonvalleydigitalnetwork/develop
Browse files Browse the repository at this point in the history
Develop to Master (v0.5.0 Release)
  • Loading branch information
joecupano authored Jul 16, 2022
2 parents 848925c + be7dd85 commit bd05f95
Show file tree
Hide file tree
Showing 53 changed files with 4,665 additions and 1,203 deletions.
283 changes: 283 additions & 0 deletions HASviolet
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
#!/bin/bash

###
### HASviolet.sh
###
###

###
### REVISION: 20220714-0300
###

###
### Usage: HASviolet [COMMAND] [OPTION]
###
### COMMAND OPTION
###
### install install current release
### config configure HASviolet
### refresh reset HASviolet back to install (remove/new configs)
### remove remove HASviolet
### purge remove HASviolet and purge configs
### update upgrade to new version if available (git pull)
### websox
### install Install Web Interface
### start Start Web Interface
### stop Stop Web Interface
### status Web Interface Status
### removde Remove and disable Web Interface


###
###
### HASviolet has been designed for the following hardware:
### Raspberry Pi Zero Wireless
### Adafruit LoRa Radio Bonnet with OLED RFM95W @ 915 MHz https://www.adafruit.com/product/4074
### Sensors connected via i2c
### GPS USB modules
###
### Generic Python Libraries for i2c and SPI are installed as well as the following:
###
### Adafruit RFM9X Library
### https://github.com/adafruit/adafruit-circuitpython-rfm9x
###
### Adafruit Monochrome OLEDs based on SSD1306 drivers
### https://github.com/adafruit/Adafruit_SSD1306
###
### Adafruit_CircuitPython_framebuf
### https://github.com/adafruit/Adafruit_CircuitPython_framebuf
###
### Sparkfun Qwiic Python Package
### https://github.com/sparkfun/Qwiic_Py
###
### pyRF95
### https://github.com/ladecadence/pyRF95
###
###
###

##
## INIT VARIABLES AND DIRECTORIES
##

# HASviolet Directory tree
HASVIOLET_REPO="https://github.com/hudsonvalleydigitalnetwork/hasviolet.git"
HASVIOLET_HOME=$HOME/hasviolet
HASVIOLET_TEMPLATES=$HASVIOLET_HOME/templates
HASVIOLET_TEMPLATES_ETC=$HASVIOLET_TEMPLATES/etc
HASVIOLET_TEMPLATES_SRV=$HASVIOLET_TEMPLATES/server
HASVIOLET_LOCAL=$HOME/hasviolet-local
HASVIOLET_SERVER=$HASVIOLET_LOCAL/server
HASVIOLET_ETC=$HASVIOLET_LOCAL/etc
HASVIOLET_CONFIG=$HASVIOLET_ETC/HASviolet.json
HASVIOLET_SSL_KEY=$HASVIOLET_ETC/HASviolet.key
HASVIOLET_SSL_CRT=$HASVIOLET_ETC/HASviolet.crt
HASVIOLET_BANNER_COLOR="\e[0;104m\e[K" # blue
HASVIOLET_BANNER_RESET="\e[0m"

# HASviolet Install Support files

# Detect architecture (x86, x86_64, aarch64, ARMv8, ARMv7)
HASVIOLET_HWARCH=`lscpu|grep Architecture|awk '{print $2}'`
# Detect Operating system (Raspberry Pi OS)
HASVIOLET_OSNAME=`cat /etc/os-release|grep "PRETTY_NAME"|awk -F'"' '{print $2}'`
# Is Platform good for install- true or false - we start with false
HASVIOLET_CERTIFIED="false"


###
### FUNCTIONS
###

hasviolet_install(){
echo " "
echo "HASviolet Install"
echo " "
echo "- Install Dependencoes"
echo " "
sudo apt-get -y install git
sudo apt-get -y install python3-pip
sudo apt-get -y install python3-pil
sudo apt-get -y install libatlas-base-dev # Numpy Dependency
echo " "
echo "- Install Libraries"
echo " "
sudo pip3 install tornado
sudo pip3 install RPI.GPIO
sudo pip3 install spidev
sudo pip3 install pynmea2
sudo pip3 install python-metar
sudo pip3 install adafruit-circuitpython-ssd1306
sudo pip3 install adafruit-circuitpython-framebuf
sudo pip3 install adafruit-circuitpython-rfm9x
sudo pip3 install numpy # pyLoraRFM9x dependency
sudo pip3 install pyLoraRFM9x
sudo pip3 install sparkfun-qwiic
sudo pip3 install sparkfun-qwiic-bme280
sudo pip3 install sparkfun-qwiic-vl53l1x
echo " "
echo "- Create Directories"
echo " "
cd $HASVIOLET_HOME
mkdir $HASVIOLET_LOCAL
mkdir $HASVIOLET_ETC
echo " "
echo "- Copy config templates into $HASVIOLET_ETC"
echo " "
cp $HASVIOLET_TEMPLATES_ETC/* $HASVIOLET_ETC
echo " "
echo "- Generating self-signed SSL certificate -- /C=US/ST=New York/L=Hudson Valley/O=Hudson Valley Digital Network/OU=HASviolet/CN=hvdn.org"
echo " "
sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -subj "/C=US/ST=New York/L=Hudson Valley/O=Hudson Valley Digital Network/OU=HASviolet/CN=hvdn.org" -keyout $HASVIOLET_SSL_KEY -out $HASVIOLET_SSL_CRT
sudo chown pi:pi $HASVIOLET_SSL_KEY >/dev/null 2>&1
sudo chown pi:pi $HASVIOLET_SSL_CRT >/dev/null 2>&1
echo " "
echo "HASviolet Install complete"
echo " "
}

hasviolet_refresh(){
echo " "
echo "- Remove Config Directory"
echo " "
cd $HOME
sudo rm -rf $HASVIOLET_ETC

echo " "
echo "- Create Config Directory"
echo " "
cd $HOME
mkdir $HASVIOLET_ETC
echo " "
echo "- Copy config templates into $HASVIOLET_ETC"
echo " "
cp $HASVIOLET_TEMPLATES_ETC/* $HASVIOLET_ETC
echo " "
echo "- Generating self-signed SSL certificate -- /C=US/ST=New York/L=Hudson Valley/O=Hudson Valley Digital Network/OU=HASviolet/CN=hvdn.org"
echo " "
sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -subj "/C=US/ST=New York/L=Hudson Valley/O=Hudson Valley Digital Network/OU=HASviolet/CN=hvdn.org" -keyout $HASVIOLET_SSL_KEY -out $HASVIOLET_SSL_CRT
sudo chown pi:pi $HASVIOLET_SSL_KEY >/dev/null 2>&1
sudo chown pi:pi $HASVIOLET_SSL_CRT >/dev/null 2>&1

echo " "
echo "HASviolet Install complete"
echo " "
}

hasviolet_update(){
echo " "
echo "HASviolet Update"
echo " "
cd $HASVIOLET_HOME
git pull
cat RELEASE |more
}


###
### MAIN
###

KOMMAND=$1
KOPTION=$2

case "$KOMMAND" in
install)
hasviolet_install
;;
config)
python $HASVIOLET_HOME/HASviolet_config.py
;;
remove)
echo -e "${HASVIOLET_BANNER_COLOR}"
echo -e "${HASVIOLET_BANNER_COLOR} ## Remove HASviolet"
echo -e "${HASVIOLET_BANNER_RESET}"
cd ~
rm -rf $HASVIOLET_HOME
;;
purge)
echo -e "${HASVIOLET_BANNER_COLOR}"
echo -e "${HASVIOLET_BANNER_COLOR} ## Purge HASviolet"
echo -e "${HASVIOLET_BANNER_RESET}"
cd ~
rm -rf $HASVIOLET_HOME
rm -rf $HASVIOLET_LOCAL
;;
update)
hasviolet_update
;;
refresh)
hasviolet_refresh
;;
RX)
python $HASVIOLET_HOME/HASviolet_RX.py -s
;;
CHAT)
python $HASVIOLET_HOME/HASviolet_CHAT.py
;;
TX)
FIRSTARG=$1
shift 1
ALLARGS=$@
python $HASVIOLET_HOME/HASviolet_TX.py -c 1 -t 1 -d $FIRSTARG -m "$ALLARGS"
;;
BEACON)
# Beacon forever every 5 seconds
if [ -z $2 ]; then
python $HASVIOLET_HOME/HASviolet_TX.py -c 99999 -t 5
else
shift 1
FIRSTARG=$1
shift 1
ALLARGS=$@
python $HASVIOLET_HOME/HASviolet_TX.py -c 99999 -t 5 -d $FIRSTARG -m "$ALLARGS"
fi
;;
websox)
case "$KOPTION" in
status)
sudo systemctl status HASviolet_websox.service
;;
start)
sudo systemctl start HASviolet_websox.service
;;
stop)
sudo systemctl stop HASviolet_websox.service
;;
remove)
sudo systemctl stop HASviolet_websox.service
sudo systemctl disable HASviolet_websox.service
sudo rm -rf /lib/systemd/system/HASviolet_websox.service
sudo rm -rf $HASVIOLET_SERVER
;;
install)
# Make $HOME/hasviolet-local/server
mkdir $HASVIOLET_SERVER
# Copy Web Server files into $HASVIOLET_SERVER
cp -r $HASVIOLET_TEMPLATES_SRV/* $HASVIOLET_SERVER
# Creat Web Server CFG dir and copy config into it
mkdir $HASVIOLET_SERVER/cfg
cp $HASVIOLET_CONFIG $HASVIOLET_SERVER/cfg
cp $HASVIOLET_HOME/HASrf95.py $HASVIOLET_SERVER
cp $HASVIOLET_HOME/HASvioletHID.py $HASVIOLET_SERVER
cp $HASVIOLET_HOME/font5x8.bin $HASVIOLET_SERVER
cp $HASVIOLET_HOME/HASvioletRF.py $HASVIOLET_SERVER
# Copy and install Web Server service
sudo cp $HASVIOLET_SERVER/HASviolet_websox.service /lib/systemd/system/HASviolet_websox.service
sudo chown root:root /lib/systemd/system/HASviolet_websox.service
sudo chmod 644 /lib/systemd/system/HASviolet_websox.service
sudo systemctl daemon-reload
sudo systemctl enable HASviolet_websox.service
sudo systemctl start HASviolet_websox.service
;;
esac
;;
*)
echo -e "${HASVIOLET_BANNER_COLOR}"
echo -e "${HASVIOLET_BANNER_COLOR} ## ERROR: Unkown action or package"
echo -e "${HASVIOLET_BANNER_COLOR}"
echo -e "${HASVIOLET_BANNER_RESET}"
;;
esac

exit 0
26 changes: 24 additions & 2 deletions HASvioletHID.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,37 @@
from digitalio import DigitalInOut, Direction, Pull
from PIL import Image, ImageDraw, ImageFont


#
# STATICS
#

HASviolet_RXLOCK = False # True = RX is running
HASviolet_TXLOCK = False # True = TX is running
HASviolet_LOCAL = "/home/pi/hasviolet-local/" # Config file is in JSON format
HASviolet_SERVER = HASviolet_LOCAL + "server/" # Path to files. Change when Pi
HASviolet_ETC = HASviolet_LOCAL + "etc/" # Config file is in JSON format
HASviolet_CONFIG = HASviolet_ETC + "HASviolet.json" # Config file is in JSON format
HASviolet_SSL_KEY = HASviolet_ETC + "HASviolet.key" # SSL Key
HASviolet_SSL_CRT = HASviolet_ETC + "HASviolet.crt" # Cert Key
HASviolet_PWF = HASviolet_ETC + "HASviolet.pwf" # Password file user:hashedpasswd
HASviolet_MSGS = HASviolet_SERVER + "msgs/HASviolet.msgs" # radio writes msgs received here
HASviolet_LOGIN = HASviolet_SERVER + "HASviolet_LOGIN.html"
HASviolet_LOGINCSS = HASviolet_SERVER + "HASviolet_LOGIN.css"
HASviolet_INDEX = HASviolet_SERVER + "HASviolet_INDEX.html"
HASviolet_INDEXCSS = HASviolet_SERVER + "HASviolet.css"
HASvioletjs = HASviolet_SERVER + "HASviolet.js"
HVDN_LOGO = HASviolet_ETC + "HVDN_logo.xbm"


#
# VARIABLES
#

hasVIOLETcfg = "cfg/hasVIOLET.json"

class HAShid:
def __init__(self):
self.cfgjson = hasVIOLETcfg
self.cfgjson = HASviolet_CONFIG
with open(self.cfgjson) as configFileJson:
jsonConfig = json.load(configFileJson)
self.myoled = jsonConfig["HID"]["oled"]
Expand Down
26 changes: 23 additions & 3 deletions HASvioletRF.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,30 @@


#
# VARIABLES
# STATICS
#

hasVIOLETcfg = "cfg/hasVIOLET.json"
HASviolet_RXLOCK = False # True = RX is running
HASviolet_TXLOCK = False # True = TX is running
HASviolet_LOCAL = "/home/pi/hasviolet-local/" # Config file is in JSON format
HASviolet_SERVER = HASviolet_LOCAL + "server/" # Path to files. Change when Pi
HASviolet_ETC = HASviolet_LOCAL + "etc/" # Config file is in JSON format
HASviolet_CONFIG = HASviolet_ETC + "HASviolet.json" # Config file is in JSON format
HASviolet_SSL_KEY = HASviolet_ETC + "HASviolet.key" # SSL Key
HASviolet_SSL_CRT = HASviolet_ETC + "HASviolet.crt" # Cert Key
HASviolet_PWF = HASviolet_ETC + "HASviolet.pwf" # Password file user:hashedpasswd
HASviolet_MSGS = HASviolet_SERVER + "msgs/HASviolet.msgs" # radio writes msgs received here
HASviolet_LOGIN = HASviolet_SERVER + "HASviolet_LOGIN.html"
HASviolet_LOGINCSS = HASviolet_SERVER + "HASviolet_LOGIN.css"
HASviolet_INDEX = HASviolet_SERVER + "HASviolet_INDEX.html"
HASviolet_INDEXCSS = HASviolet_SERVER + "HASviolet.css"
HASvioletjs = HASviolet_SERVER + "HASviolet.js"
HVDN_LOGO = HASviolet_ETC + "HVDN_logo.xbm"


#
# VARIABLES
#


#
Expand All @@ -35,7 +55,7 @@

class HASrf:
def __init__(self):
self.cfgjson = hasVIOLETcfg
self.cfgjson = HASviolet_CONFIG
with open(self.cfgjson) as configFileJson:
jsonConfig = json.load(configFileJson)
self.radio = jsonConfig["RADIO"]["rfmodule"]
Expand Down
Loading

0 comments on commit bd05f95

Please sign in to comment.