diff --git a/cli_meter.py b/cli_meter.py index b967760..eeb30e9 100644 --- a/cli_meter.py +++ b/cli_meter.py @@ -13,7 +13,7 @@ import RPi.GPIO as GPIO import time, math import requests from datetime import datetime -import pdb +# import pdb # Using BCM (Broadcom) names when referencing the GPIO pins. GPIO.setmode(GPIO.BCM) @@ -22,7 +22,7 @@ GPIO.setwarnings(True) a_pin = 18 # Charges the capacitor. b_pin = 23 # Discharges the capacitor. -api_url = "http://35.176.14.135/api/readings/add/1" +api_url = "http://3.9.19.84/api/readings/add/1" def discharge(): GPIO.setup(a_pin, GPIO.IN) @@ -62,7 +62,7 @@ def get_timestamp(): def push_reading(lvalue): time = get_timestamp() headers = {"content-type": "application/json"} - payload = { "reading": int(lvalue), "time": time} + payload = { "reading": int(lvalue), "time": time, "token": "QWERTYuiopasdfghjklzxcvbnm_1234567890"} print(payload) res = requests.post(api_url, data=json.dumps(payload), headers=headers) diff --git a/shutdown.sh b/shutdown.sh new file mode 100755 index 0000000..28c2e82 --- /dev/null +++ b/shutdown.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +logDate=$(date '+%Y-%m-%dT%TZ') +logFile="/home/lm-1/logs/shutdown-logs.txt" + +getApiUrl () { + # Copy and Paste for the win! + case $HOSTNAME in + (factory1) apiURL="http://3.9.19.84/api/status/update/1";; + (factory2) apiURL="http://3.9.19.84/api/status/update/2";; + (factory3) apiURL="http://3.9.19.84/api/status/update/3";; + (gallery1) apiURL="http://3.9.19.84/api/status/update/4";; + (gallery2) apiURL="http://3.9.19.84/api/status/update/5";; + (gallery3) apiURL="http://3.9.19.84/api/status/update/6";; + esac +} + +logStatusChange () { + cat << EOF >> $logFile +$logDate +EOF +} + +logStatusChange +getApiUrl + +curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{"status": "off", "time": "'${logDate}'", "token": "QWERTYuiopasdfghjklzxcvbnm_1234567890"}' "${apiURL}" + +shutdown now \ No newline at end of file diff --git a/startup.sh b/startup.sh new file mode 100755 index 0000000..1c561cc --- /dev/null +++ b/startup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +logDate=$(date '+%Y-%m-%dT%TZ') +logFile="/home/lm-1/logs/start-logs.txt" + +getApiUrl () { + # Copy and Paste for the win! + case $HOSTNAME in + (factory1) apiURL="http://3.9.19.84/api/status/update/1";; + (factory2) apiURL="http://3.9.19.84/api/status/update/2";; + (factory3) apiURL="http://3.9.19.84/api/status/update/3";; + (gallery1) apiURL="http://3.9.19.84/api/status/update/4";; + (gallery2) apiURL="http://3.9.19.84/api/status/update/5";; + (gallery3) apiURL="http://3.9.19.84/api/status/update/6";; + esac +} + +logStatusChange () { + cat << EOF >> $logFile +$logDate +EOF +} + +logStatusChange +getApiUrl + +curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{"status": "on", "time": "'${logDate}'", "token": "QWERTYuiopasdfghjklzxcvbnm_1234567890"}' "${apiURL}"