Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iss19 #24

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Preferences_Chromium

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions create_sha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# used for generating the hash for the release and store it in a file

#---------------------------------------------------
tar -c ${HOME}/UCI-DWB/!(sha256sum.txt|.*) | sha256sum | tee sha256sum.txt
36 changes: 21 additions & 15 deletions scale/scale_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,17 @@

/**
* @brief the main function responsible for managing the scale
* @param argv this should contain the mode that the bin is running on at argv[1], the mode is
* detected by the startup script and fed into the scale at the end of the maintainance sequence
* @return this should never return unless in special circumstances such as the physical scale or
* the pi is damaged
* the pi is damaged(indicated by unresponsive scale)
*/
int main(void)
int main(int argc, char **argv)
{
// retrieve env var to get path for saving stuffs and determine the role of the bin
const char *homeDir = getenv("HOME");
assert(homeDir);
const char *mode = getenv("MODE"); // the MODE env var is defined during the scale setup
assert(mode);

char saveDir[100] = "";
strcat(saveDir, homeDir);
strcat(saveDir, "/UCI-DWB/");
strcat(saveDir, mode);
strcat(saveDir, "/javascript_and_json/result.json");
FILE *saveFile = fopen(saveDir, "w");
assert(saveFile);
fclose(saveFile);

char homeDir[] = "/home/pi";
assert(homeDir);
char logDir[100] = "";
strcat(logDir, homeDir);
strcat(logDir, "/UCI-DWB/scale");
Expand All @@ -52,6 +43,20 @@ int main(void)
uint8_t timeoutCounter = 0;
assert(log);

if ((strcmp(argv[1], "compost") && strcmp(argv[1], "recycle") && strcmp(argv[1], "landfill")))
{
scaleLogging("ERROR", "Unknown bin type", log, "PRE_LOOP");
return 1;
}
char *mode = argv[1];
char saveDir[100] = "";
strcat(saveDir, homeDir);
strcat(saveDir, "/UCI-DWB/");
strcat(saveDir, "javascript_and_json/result.json");
FILE *saveFile = fopen(saveDir, "w");
assert(saveFile);
fclose(saveFile);

int scale = openScale(log);
float result;
#ifdef DEBUG
Expand Down Expand Up @@ -92,6 +97,7 @@ int main(void)
if (timeoutCounter == TIMEOUT_LIMIT)
{
scaleLogging("ERROR", "Many Consecutive timeout", log, "AFTER_READ");
break;
}
}
else if (result == ERROR_FLUSH_FAILED)
Expand Down
4 changes: 2 additions & 2 deletions scale/scale_optimized.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "scale_optimized.h"
#include "scale_utils.h"

// #define SCALE_DEV_FILE "/dev/SCALE"
#define SCALE_DEV_FILE "/dev/ttyUSB0"
#define SCALE_DEV_FILE "/dev/SCALE"
// #define SCALE_DEV_FILE "/dev/ttyUSB0"

#define SCALE_MESSAGE_SIZE 6 //!< defined by the manual
#define RECONNECT_ATTEMPTS \
Expand Down
1 change: 1 addition & 0 deletions sha256sum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a5228b850982486851aebdbda05c37a89b8ba3907ef5079515cd278e03368b5e -
89 changes: 71 additions & 18 deletions shell_script/maintain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,71 @@
# NEED TO BE EXECUTED WITH THE SOURCE COMMAND

#time for the computer to reboot, based on food court inactive hour
reboot_time="24:00"
reboot_time="23:45"
project_name="UCI-DWB"

source ./utils.sh
startup_file="/home/${NON_ROOT_USER}/.bashrc" # NON_ROOT_USER set during initial installation
chmod u+x startup_file
non_root_user_dir="/home/${NON_ROOT_USER}"
env_var_storage_file="/home/pi/env_storage.txt"
display_file="/home/pi/.xinitrc"
source ${env_var_storage_file}
non_root_user_dir="/home/pi"
devBrand=iss9
mode=""

log()
{
touch /home/pi/maintainance.log
printf '%-20s %-7s %-15s %-s\n' "$(date --iso-8601=date) $(date +'%H:%M:%S')" "${1}" "\"[${2}]\"" "${3}" >> /home/pi/maintainance.log
return 0
}
# pin state ref: https://raspberrypi.stackexchange.com/questions/51479/gpio-pin-states-on-powerup
# pin graph ref:
# https://www.jameco.com/Jameco/workshop/circuitnotes/raspberry-pi-circuit-note.html

#--------------------------------------------------------------
log "INFO" "MAINTAIN" "Starting Maintainance"

check_bin_role
# pins if pulled high, indicate the correspoding bin types
compost_pin=22
recycle_pin=24
landfill_pin=10
gpio_dir="/sys/class/gpio"

# pin setup these may failed if the pin is already setup
echo ${compost_pin} > ${gpio_dir}/export
sleep 1
echo ${recycle_pin} > ${gpio_dir}/export
sleep 1
echo ${landfill_pin} > ${gpio_dir}/export
sleep 1
echo "in" > ${gpio_dir}/gpio${compost_pin}/direction
sleep 1
echo "in" > ${gpio_dir}/gpio${recycle_pin}/direction
sleep 1
echo "in" > ${gpio_dir}/gpio${landfill_pin}/direction
sleep 1

if [ $(cat ${gpio_dir}/gpio${compost_pin}/value) = 1 ] && [ $(cat ${gpio_dir}/gpio${recycle_pin}/value) = 0 ] && [ $(cat ${gpio_dir}/gpio${landfill_pin}/value) = 0 ]
then
mode=compost
elif [ $(cat ${gpio_dir}/gpio${compost_pin}/value) = 0 ] && [ $(cat ${gpio_dir}/gpio${recycle_pin}/value) = 1 ] && [ $(cat ${gpio_dir}/gpio${landfill_pin}/value) = 0 ]
then
mode=recycle
elif [ $(cat ${gpio_dir}/gpio${compost_pin}/value) = 0 ] && [ $(cat ${gpio_dir}/gpio${recycle_pin}/value) = 0 ] && [ $(cat ${gpio_dir}/gpio${landfill_pin}/value) = 1 ]
then
mode=landfill
else
log "ERROR" "GPIO" "Unknown Pin State"
sleep 5
reboot
fi

sed -i "s/export MODE=.*/export MODE=${mode}/g" ${display_file}

# MAINTAINANCE CODE
git -C ${non_root_user_dir}/${project_name}/ checkout release # change branch to receive update from release
git -C ${non_root_user_dir}/${project_name}/ checkout ${devBrand} # change branch to receive update from ${devBrand}
sudo ufw enable # enable firewall if not enabled
sudo ifconfig wlan0 up # turn on network
sleep 20 # give wlan0 time to wake up
sleep 11 # give wlan0 time to wake up

sudo service ntp restart >> /dev/null
sudo apt-get update >> /dev/null
Expand All @@ -34,32 +82,37 @@ if ! git -C ${non_root_user_dir}/${project_name}/ fetch ; then
exit 1 # exit and leave the screen blank so people can contact the team instead of infinite reboot
fi
TOTAL_FAILURE=$((TOTAL_FAILURE+1))
sed -i "s|^export TOTAL_FAILURE=.*$|export TOTAL_FAILURE=${TOTAL_FAILURE}|g" ${startup_file}
sed -i "s|TOTAL_FAILURE=.*$||g" ${env_var_storage_file}
echo "TOTAL_FAILURE=${TOTAL_FAILURE}" >> ${env_var_storage_file}
reboot
fi
# only pull and rerun stuffs if there is update
if [ $(git -C ${non_root_user_dir}/${project_name}/ rev-list --count origin/release...release) -gt 0 ]; then
if [ $(git -C ${non_root_user_dir}/${project_name}/ rev-list --count origin/${devBrand}...${devBrand}) -gt 0 ]; then
log "INFO" "UPDATE" "Found Upates"
if git -C ${non_root_user_dir}/${project_name}/ pull ; then
log "INFO" "UPDATE" "Finished Applying Update"
exec ${startup_file}
# reboot
else
log "ERROR" "UPDATE" "Error updating"
if [ "${TOTAL_FAILURE}" -gt 5 ]; then
log "ERROR" "UPDATE" "Failed updating more than 5 times"
exit 1 # exit and leave the screen blank so people can contact the team instead of infinite reboot
fi
TOTAL_FAILURE=$((TOTAL_FAILURE+1))
sed -i "s|^export TOTAL_FAILURE=.*$|export TOTAL_FAILURE=${TOTAL_FAILURE}|g" ${startup_file}
reboot

sed -i "s|TOTAL_FAILURE=.*$||g" ${env_var_storage_file}
echo "TOTAL_FAILURE=${TOTAL_FAILURE}" >> ${env_var_storage_file}
# reboot
fi
fi

sudo ifconfig wlan0 down
sed -i "s|^export TOTAL_FAILURE=.*$|export TOTAL_FAILURE=0|g" ${startup_file} # reset total failures to 0
touch ${env_var_storage_file} #store env storage for rc.local
sed -i "s|TOTAL_FAILURE=.*$||g" ${env_var_storage_file}
echo "TOTAL_FAILURE=0" >> ${env_var_storage_file}
log "INFO" "MAINTAIN" "Finish Maintainance"
su - ${NON_ROOT_USER} # change to non-root user for the rest of the day
shutdown -r ${reboot_time}
shutdown -r ${reboot_time} # schedule reboot everyday when the food court is not active

exit 0
# run scale code and start display
make -C ${non_root_user_dir}/${project_name}/scale
${non_root_user_dir}/${project_name}/scale/scale_main.out ${mode} &
sleep 1
114 changes: 0 additions & 114 deletions shell_script/setup.sh

This file was deleted.

Loading