1
0
Fork 0
Browse Source

add start-up and shutdown scripts.

pull/1/head
Craig Oates 4 years ago
parent
commit
f0f4776a9b
  1. 6
      cli_meter.py
  2. 29
      shutdown.sh
  3. 27
      startup.sh

6
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)

29
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

27
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}"