2021-11-05 snapshot.
commit eda360a06892c0fe6165a188d11e9f5a99d6cbb3
Merge: 0b9b295 071c8cf
Author: Craig Oates <craig@craigoates.net>
Date: Fri Nov 5 18:24:33 2021 +0000
Merge branch 'unstable' into stable
commit 071c8cf5f3462e8cd1b95d48442c18ddf0eb8b40
Merge: 1534c04 56e05dc
Author: Craig Oates <craig@craigoates.net>
Date: Fri Nov 5 18:16:43 2021 +0000
Merge branch 'unstable' of git.abbether.net:return-to-ritherdon/light-meter into unstable
commit 1534c04635756d9cd1b70bb2ca9075f43862f58e
Author: Craig Oates <craig@craigoates.net>
Date: Fri Nov 5 18:15:45 2021 +0000
update README.
commit 56e05dceaf14996f11ef48eee4cb4f01ca429777
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Fri Feb 5 16:54:31 2021 +0000
use session to persist REST calls and expand exception handling.
Previously, the light-meter was creating a new HTTP request to send every new reading. This now
uses a persistant session to reduce the amount of requests made to the server -- and reduce low
on the system.
The extra exceptions listed and expanded on are mostly for testing. At the time of writing, the
system as a whole is hanging at various parts throughout the day and the intention is to monitor
the Light Meter to see if any of the new exceptions are the cause (or contributing) to the
hanging. The current trains-of-thought at the minute are too many requests (system load too
high) and requests not timing out properly.
commit b4571b0c1e5a904286619e6929bbbe157461b1d4
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Wed Jan 27 21:59:51 2021 +0000
create a Systemd service file.
This file is used to start the program at startup. It, also, restarts the
program if it crashes or throws an exception. The usual scenario which
causes the program to crash is the 'max. requests exceeded' exception in
the 'requests' module (Python). When that happens, this 'restart' service
has a 60 seconds wait period -- which acts as a 'backoff' period.
You will need to copy the .service file to the appropriate systemd
location, 'daemon-reload' systemctl, enable the service and start the
service. You will need to look-up how to do that -- this info. is beyond
the scope of this commmit.
commit 0b9b295036f15a2d9bfd9e6b09c1956ea4b1abce
Merge: 814fbdf b7140cb
Author: Craig Oates <craig@craigoates.net>
Date: Wed Jan 13 13:08:23 2021 +0000
Merge branch 'unstable' of return-to-ritherdon/light-meter into stable
commit b7140cbf2b9e6b23be37894ec3b12d21d162b6de
Author: Craig Oates <craig@craigoates.net>
Date: Wed Jan 13 12:59:44 2021 +0000
change info. about cronjob in README.
This is a minor change but I thought it was best to document it.
The factory typically shutdowns at 16:00 but for some reason I thought it was 18:00. Because of this, 'factory1' (the light-meter used for testing) was not shutting down properly. The factory's power was cut at the end of the day (again typically 16:00 but not always) and the Pi would have a dirty power-down. This, also, meant the server and its opposite relay [return-to-ritherdon/relay] would think it was still on but sending no new readings.
All of the above has no great effect of the **note** left in the README but I thought I should change it on the off-chance someone copies that line into a part of the system.
commit 46b8d53cc43e86b3ff8b3ed1db39edd73982f8c6
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Wed Jan 13 11:58:27 2021 +0000
remove merge conflict artefacts.
commit 2ad344846bc4babc6120a6c31952d7a7bdcb8fdf
Merge: 39cf8bc 6e4e425
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Wed Jan 13 11:51:02 2021 +0000
Merge remote-tracking branch 'origin/fact2temp' into unstable
commit 39cf8bc302db09f4fdd155b5d40d57e34cedbf92
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Wed Jan 13 11:22:47 2021 +0000
update URL used for RESTAPI calls.
I have given the 'mid-point' server a domain name to reduce the need to manually update the IP address if/when the
server needs to be restarted (for whatever reason). The changes here include the new URL.
commit 6e4e4254cf6bbdfb3d838945d1d65c78d43641a8
Author: Craig Oates <craig@craigoates.net>
Date: Wed Dec 16 17:18:07 2020 +0000
extend URL list for adding new light readings.
The base URL uses ritherdon.abbether.net now, in the main part of the
python code. I have added checks to see which device is running the
code and forms a complete URL for the API call.
The way the URL is formed for the API call is not the most elegant
solution but is was quick to write and the code has a limited
life-span. It will not require any further modification when it goes
live. So, the speed it took to write it was a good trade-off in my opinion.
commit 7a3e3df07af1ca878956eced2f4cbc9460751bf8
Author: Craig Oates <craig@craigoates.net>
Date: Wed Dec 16 16:53:19 2020 +0000
change URL to ritherdon.abbether.net
The URL used here is a domain name and not just an IP address. This
should reduce the need to update the IP address in the code if the
server, currently hosted on AWS at time of writing, needs to be
restarted. The servers on AWS do not keep the same IP address if you
stop and start them.
The abbether.net domain is a personal one and used as a way to reduce
project costs. I did not use this domain when I first wrote the code
here because I did not own it. Long story short, the Covid-19 malarkey
meant the project was put on hold and I ended up owning abbether.net
during the first lock-down. The decision to use the domain is one of
convince my end. I did not want to keep updating the code manually if
the server on AWS was stopping and starting.
commit 9532df813732253c2b063b5c81ffddd9e47a4c73
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Sun Jan 12 19:22:56 2020 +0000
adjust shutdown call in shutdown.sh.
commit a75cf4083f00e225b983aa2f687cc5f872b44019
Author: Craig Oates <craig@craigoates.net>
Date: Sun Jan 12 02:00:25 2020 +0000
add residency overview image to readme.
commit b0d6474809bc3b348a9b34491296120cea44e5c7
Author: Craig Oates <craig@craigoates.net>
Date: Sun Jan 12 01:39:48 2020 +0000
comment out testing/debugging print states in cli_meter.
commit 67bef91b143cefae1d914e2d52cc9b8db6ec9940
Author: Craig Oates <craig@craigoates.net>
Date: Sun Jan 12 01:34:03 2020 +0000
fix typo's in readme.
commit beccebc3ececafe07d25f257ebc63529f508a23a
Author: Craig Oates <craig@craigoates.net>
Date: Sun Jan 12 01:15:14 2020 +0000
add main-proj-architecture image (for readme).
commit 22bd78800ce08fff313bdd72a678bc02ee7cbded
Author: Craig Oates <craig@craigoates.net>
Date: Sun Jan 12 00:18:10 2020 +0000
update images in readme.
commit 234dffe4c08f3cdd823cb3f2719e0b5c9a044546
Author: Craig Oates <craig@craigoates.net>
Date: Sat Jan 11 23:40:42 2020 +0000
make edit to readme structure.
commit 9ccdc917787280c02235b20f3e1a974c9c5a4b54
Author: Craig Oates <craig@craigoates.net>
Date: Sat Jan 11 23:34:47 2020 +0000
add images for readme.
commit d99e04c87d9a85165700053cda81cfbec5bb8dc4
Author: Craig Oates <craig@craigoates.net>
Date: Sat Jan 11 23:12:03 2020 +0000
add hardware section to readme.
commit 445adcc53a6642cdf0be86a6829d30c4d9393b69
Author: Craig Oates <craig@craigoates.net>
Date: Sat Jan 11 22:04:00 2020 +0000
edit the readme.
commit fa98024e0fdebc9cdebe3cf9bd2d259562a5aef1
Author: Craig Oates <craig@craigoates.net>
Date: Sat Jan 11 21:33:38 2020 +0000
update readme.
commit 8e98fe2fac78e340cbcdd8d4219808be6dc7036e
Author: Craig Oates <craig@craigoates.net>
Date: Sat Jan 11 18:53:23 2020 +0000
add comments to startup, shutdown and cli-meter.
commit 0eaea3b7981f162497dc7f1cdb6b5879cc11784c
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Sat Jan 11 01:11:22 2020 +0000
refactor timers in scripts.
commit 9027a3bcb16a505d8a5b667239929deedf4abdca
Author: rtrp@factory1 <rtrp@factory1.com>
Date: Fri Jan 10 21:02:05 2020 +0000
create a make-logs script.
commit 5f264e7f60fa55b651c113131f552c0b2d68dea8
Author: Craig <craig@craigoates.net>
Date: Fri Jan 10 01:28:21 2020 +0000
add times to startup and shutdown scripts.
commit f0f4776a9b2b11994a22716a22ffb36117efaa70
Author: Craig <craig@craigoates.net>
Date: Fri Jan 10 00:07:26 2020 +0000
add start-up and shutdown scripts.
commit c5da9d59181eca2bf6a9f9882d4e6e651789076d
Author: Craig <craig@craigoates.net>
Date: Sun Jan 5 19:45:45 2020 +0000
add keyboard interrup exception.
commit 9ef10aef1690613d06783d87163c31c03757a114
Author: Craig <craig@craigoates.net>
Date: Sun Jan 5 19:15:40 2020 +0000
port 'cli' code from light_meter to cli_meter.
commit f89e7b3923f41bcb82b60ce92a03a1a4205c7cc9
Author: Craig Oates <craig@craigoates.net>
Date: Sun Dec 15 00:12:59 2019 +0000
add cli-meter.py
commit 32e5b464c60f99ccd7705071b4c441a3e76cd2c7
Author: Craig Oates <craig@craigoates.net>
Date: Sat Dec 14 23:52:28 2019 +0000
port over code from roaming-light project.
3 years ago
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Startup Script
|
|
|
|
# ====================================================================
|
|
|
|
# I wrote this script with the intention of using it to start a
|
|
|
|
# cron-job -- when the Raspberry Pi is turned on. Before you set the
|
|
|
|
# cron-job up, you must make sure you have either ran the
|
|
|
|
# "make-log-files.sh" script or created the appropriate log file and
|
|
|
|
# folder at the location specified at "logFile" below.
|
|
|
|
# ====
|
|
|
|
# Please note: This script calls another (Python) script at the end of
|
|
|
|
# it. The code in the Python script (cli_meter.py) is an infinite-loop
|
|
|
|
# so you will need to kill it manually or turn-off the Raspberry Pi.
|
|
|
|
# ====
|
|
|
|
# I put the "sleep 60" call at the start to reduce any errors
|
|
|
|
# occurring because a part of the system (I.E. curl) has not finished
|
|
|
|
# loading. 60 seconds is a little excessive but I wrote this script
|
|
|
|
# with the expectation of it running on an unmanned Raspberry Pi. So,
|
|
|
|
# reliable/consistent behaviour is my preference over "fast start-up
|
|
|
|
# times".
|
|
|
|
|
|
|
|
|
|
|
|
# sleep 60
|
|
|
|
|
|
|
|
logDate=$(date '+%Y-%m-%dT%TZ')
|
|
|
|
logFile="/home/rtrp/logs/startup-logs.txt"
|
|
|
|
mainURL="http://ritherdon.abbether.net/api/status/update" # Make sure this is valid.
|
|
|
|
|
|
|
|
getApiUrl () {
|
|
|
|
case $HOSTNAME in
|
|
|
|
(factory1) apiURL="${mainURL}/1";;
|
|
|
|
(factory2) apiURL="${mainURL}/2";;
|
|
|
|
(factory3) apiURL="${mainURL}/3";;
|
|
|
|
(gallery1) apiURL="${mainURL}/4";;
|
|
|
|
(gallery2) apiURL="${mainURL}/5";;
|
|
|
|
(gallery3) apiURL="${mainURL}/6";;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
logStatusChange () {
|
|
|
|
cat << EOF >> $logFile
|
|
|
|
$logDate
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
logStatusChange
|
|
|
|
getApiUrl
|
|
|
|
|
|
|
|
curl -S -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{"status": "on", "time": "'${logDate}'", "token": "QWERTYuiopasdfghjklzxcvbnm_1234567890"}' "${apiURL}"
|
|
|
|
|
|
|
|
python3 /home/rtrp/repos/light-meter/cli_meter.py
|