1
0
Fork 0
A REST-API built with Flask and Python. Its main purpose is to receive the readings from the light meters welding booths in the Ritherdon factory and make them available for consumption by the relay-controllers in the gallery.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

441 lines
17 KiB

2021.11.05 snapshot. commit 5ecf3f1173681333681f7cbf6bb883c6879af27b Author: Craig Oates <craig@craigoates.net> Date: Fri Nov 5 18:35:56 2021 +0000 update README. commit f2aa3734189817f4137c705009fa131062d5cf9b Author: Craig Oates <craig@craigoates.net> Date: Mon Jan 13 00:58:01 2020 +0000 make git ignore readings.db. commit 9c1a023ab4d47501ca5164a9c34d18db5c158f18 Author: Craig Oates <craig@craigoates.net> Date: Mon Jan 13 00:33:23 2020 +0000 make home page refresh every 60 seconds. commit b3efcc73c8536a605cf2d89e68c95ee3d2da6acf Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 16:18:16 2020 +0000 add comment to device_check_token. commit 747f6b847ca4b528958ab729b62c64692c6fdd29 Merge: bf21990 ba85b56 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 16:00:02 2020 +0000 merge of unstable into stable commit ba85b560ea5c8e809c8b00e9a7b9920ebc6c21f2 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 15:44:41 2020 +0000 add tim e of request info. to home. commit 427d263812895203946ff9d7c59b5ba107ec343b Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 15:21:36 2020 +0000 fix typo in YAML file. commit e7e492333076cfe2f3520abcc340f59f6a1b1095 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 15:18:40 2020 +0000 add get latest (all) device status to YAML (A.P.I.) file. commit b4d9ca04faae014700435cb99d373e7781d925e0 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 15:09:06 2020 +0000 reset database. commit 3e80738d32043681da593dc1fed8a02fadd02d6c Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 15:08:33 2020 +0000 add 400-error responses to GET requests in YAML file. commit 13e2f5d3ba970ad4cae7c632e509238976811d74 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 15:03:27 2020 +0000 add 400-error info. to PUT request in YAML file. commit b01178a711c730d95220da0e7e8c745c117d2380 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 14:57:21 2020 +0000 add try-blocks to post requests. commit d377ef4eca2516e10daff2ac548c7a6706ac519c Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 14:44:07 2020 +0000 add secirity token checks to status change A.P.I. call. commit 95cb4754289f8cb3f009c2547232c7f0fc1b4957 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 14:35:26 2020 +0000 add security token checks when adding new reading. commit bf2199012e7f8d4efb91253beea1af89c950e7de Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 00:17:39 2020 +0000 reset database. commit c24981a0e338f5c3a726352f3a4dcbe3e3a1d670 Author: Craig Oates <craig@craigoates.net> Date: Thu Jan 9 00:04:50 2020 +0000 reset database. commit 0bb4ed4be8a6402de71da5af921bd5882a2e28f1 Merge: bd20f7b f32e4ae Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 23:56:26 2020 +0000 Merge branch 'unstable' of return-to-ritherdon/midpoint into stable commit f32e4aec4a079bba4f53e8492a3e45412473cf9c Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 23:52:50 2020 +0000 update A.P.I. version to 1.0.0 - Alpha. commit 1008d3e2e445634c285bc50252e75db9630efea2 Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 23:51:16 2020 +0000 implement home page status report feature. commit 6394009f40cb4bf3e603b9d02e46245d15730237 Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 22:39:15 2020 +0000 implement get all status changes (all devices) A.P.I. call. commit fc3fe18b0e66d458a6c057f3bc34a61fe3afb10d Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 22:30:25 2020 +0000 implement get all status changes (per device) A.P.I. call. commit 65464fae5438d016eccfca4700fd8904c70f219e Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 21:59:35 2020 +0000 implement get device status latest A.P.I. call. commit 641fe8f6046c50d312394c281ab3fcc9e8f59a14 Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 21:08:07 2020 +0000 add device status-update logging. commit 312bcd70a6e87170aed56b5e60ca18191fb1c21f Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 19:04:38 2020 +0000 remove in-mem readings and refactor related items. commit c4590b906c454c726cba723b63dcb106649c1d37 Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 03:30:47 2020 +0000 add website info. section to home. commit 1ded49cfcfccb39e275bcf48e6366bd3b2c618d8 Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 03:20:48 2020 +0000 add artwork status bar to home page. commit 628ea5a9a2099966eec3fbabefcff6779a73e233 Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 02:28:56 2020 +0000 add styling and content to home page. commit 400c0f0310dd6e69a489d25934cd9d2b0bb57c4f Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 00:25:16 2020 +0000 add route for robots.txt. commit bb05c5e151e5c3abf71026691ede402d32a5f41d Author: Craig Oates <craig@craigoates.net> Date: Wed Jan 8 00:10:12 2020 +0000 create robot.txt file. commit 5bdd448b7ef12d98a4dbdf540155fc72f1bf0baf Author: Craig Oates <craig@craigoates.net> Date: Tue Jan 7 23:58:55 2020 +0000 add favicons. commit bd20f7be7d025d06a8c271b1fbd89a6089e4dcbc Merge: 1975e6e 2d6ba68 Author: Craig Oates <craig@craigoates.net> Date: Tue Jan 7 23:46:14 2020 +0000 Merge branch 'unstable' of return-to-ritherdon/midpoint into stable commit 2d6ba68682aeff040ed2407949ceb80c1d5989e5 Author: Craig Oates <craig@craigoates.net> Date: Tue Jan 7 23:43:37 2020 +0000 update requirements in proj-env. commit 1975e6ecbf4cf6c1b63ff22c343edad03d1ab5aa Author: Craig Oates <craig@craigoates.net> Date: Tue Jan 7 23:24:52 2020 +0000 create v-env. for server and update requirements. commit 373b6686ad62dba1fd6061eb3ae0497b646c59c1 Author: Craig Oates <craig@craigoates.net> Date: Mon Jan 6 01:18:35 2020 +0000 create html templates. commit 9f0c71ada2c39538f3c2c96bb9391cf44bef928e Author: Craig Oates <craig@craigoates.net> Date: Sun Jan 5 23:51:37 2020 +0000 port code over from test proj. commit c1f174f82882f41981e18608a12af2aa28bce617 Author: Craig Oates <craig@craigoates.net> Date: Sun Jan 5 22:52:51 2020 +0000 create virtual environment.
3 years ago
swagger: "2.0"
info:
description: >-
The 'Return to Ritherdon' project, by Nicola Ellis, is a two year art residency at Ritherdon & Co Ltd, a manufacturer of metal enclosures based in Darwen, Lancashire U.K. This website is part of the many outcomes produced throughout the duration of project.
version: "1.0.0 - Beta"
title: Return to Ritherdon Project A.P.I.
consumes:
- application/json
produces:
- application/json
basePath: /api
paths:
# Light-Meter A.P.I. Calls
# ====================================================================
/readings/add/{light_meter}:
post:
operationId: api.post_a_reading
tags:
- Log Light-Meter Readings
summary: >-
Posts a reading from one of the project's light meters and store
it in the database.
description: >-
Use this U.R.L. to post a new reading from of the light meters
used in the project. At the time of writing, there are three
light meters taking readings in the Ritherdon factory.
It is important to note which light meter is posting the
reading. Each light meter has its own table in the database
and it will corrupt the data integrity if you post a reading
from a meter into the wrong table. At the time of writing,
there are three meters taking light reading and posting them
to here.
parameters:
- name: light_meter
in: path
description: >-
The Id. of the light meter which has taken the reading. At
the time of writing, it should be a number between 1-3.
type: integer
required: True
- name: the_reading
in: body
description: >-
The data object which represents a single light reading
from light meter 1. It conveys the time the reading was
taken and the light value it recorded. Remember, each light
has their own table in the database so make sure you do not
post the light meter reading to the wrong URL. It will
corrupt the data integrity.
required: True
schema:
type: object
properties:
time:
type: string
format: date-time
example: 2019-10-19 17:04:57
description: >-
The date and time the reading was taken. Make sure
you use the UTC time format. This is because the
A.P.I. has made a design decision to standardise on
it.
reading:
type: integer
example: 23
description: >-
This represents the amount of light the light meter
recorded. This is the most important piece of data
you will post in this data-object.
token:
type: string
example: it-is-not-password-if-you-are-wondering
description: >-
This is basically a token to check the info. sent to
the server is from a valid machine.
responses:
201:
description: >-
The reading was successfully added to the database.
400:
description: >-
The data sent to the sever was invalid or incorrectly
formatted. The most likely reasons are invalid light-meter
Id. specified and incorrect datetime format used.
/readings/latest/{light_meter}:
get:
operationId: api.get_latest
tags:
- Request Light-Meter Readings
summary: >-
Returns the latest reading from the specified light meter.
description: >-
Use this U.R.L. to retrieve the latest reading from the
light meter you specified (in the U.R.L.). At the time of
writing, the project has only three light meters and are
labelled 1-3.
parameters:
- name: light_meter
in: path
description: >-
This is the Id. of the light meter which you are retrieving
the reading for. The Id. consists of a number between 1-3
at the time of writing.
type: integer
required: True
responses:
200:
description: >-
If the server can successfully retrieve the latest reading
for the specified light meter, you should receive a JSON
object like the one below. It should include the Id. of
the light meter it was taken with, the time the reading
was taken and the reading itself.
schema:
type: object
properties:
id:
type: integer
example: 2
description: >-
This is the Id. of the light meter which took the
reading. It should be between 1-3 at the time of
writing.
time:
type: string
example: 2019-10-19 17:04:57
description: >-
The time and date the reading was taken. The A.P.I.
has standardised on the U.T.C. format.
reading:
type: integer
example: 34
description: >-
This is the actual reading taken from the specified
light meter, at the time specified in this response
body (I.E. JSON object).
400:
description: >-
The light-meter Id. specified in invalid.
/readings/all/{light_meter}:
get:
operationId: api.get_all_readings
tags:
- Request Light-Meter Readings
summary: >-
Returns every reading taken by the specified light meter.
description: >-
Use this U.R.L. to retrieve all the reading from the
light meter you specified (in the U.R.L.). At the time of
writing, the project has only three light meters and are
labelled 1-3.
parameters:
- name: light_meter
in: path
description: >-
This is the Id. of the light meter which you are retrieving
the readings for. The Id. consists of a number between 1-3
at the time of writing.
type: integer
required: True
responses:
200:
description: >-
If the server can successfully retrieve all the readings
for the specified light meter, you should receive an array
of JSON objects like the one below. It should include the
database Id. of the reading, the time the reading was
taken and the reading itself.
schema:
type: object
properties:
id:
type: integer
example: 2
description: >-
This is the database Id. of the reading.
time:
type: string
example: 2019-10-19 17:04:57
description: >-
This is the time and date the reading was taken.
The A.P.I. has standardised on the U.T.C. format.
reading:
type: integer
example: 34
description: >-
This is the actual reading taken from the specified
light meter, at the time specified in this response
body (I.E. JSON object).
400:
description: >-
The light-meter Id. specified in invalid.
/readings/all:
get:
operationId: api.get_all_readings_for_every_meter
tags:
- Request Light-Meter Readings
summary: >-
Returns every reading taken by every light meter in the
project.
description: >-
Use this U.R.L. to retrieve all the readings from every light
meter in the project. There is no example of the data returned
because I can't seem to replicate it as a YAML schema which
is understood by Swagger. Because of this, it is registered as
a free-form object. To see what the data looks like when it is
returned, I recommend you use the "Try it out!" button to see a
working example.
responses:
200:
description: >-
All the readings were successfully retrieved from the
database and delivered.
schema:
type: object
additionalProperties: True
# Device A.P.I. Calls
# ====================================================================
/status/update/{device}:
post:
operationId: api.post_a_status_change
tags:
- Log Device Status Change
summary: >-
Logs a change in the status of the specified device.
description: >-
This is mostly to check if the devices included in this project
are turned on, off or an error has occured and they are
unreachable/crashed.
parameters:
- name: device
in: path
description: >-
The Id. of the device with the change in status. 1, 2 and 3
refer to the light-meters in Ritherdon and 4, 5 and 6
refer to the relays in the gallery. The pairing of each
meter and relay is as follows: 1->4, 2->5 and 3->6.
type: integer
required: True
- name: the_status_change
in: body
description: >-
The status change and the time the change occurred.
required: True
schema:
type: object
properties:
time:
type: string
format: date-time
example: 2019-10-19 17:04:57
description: >-
The date and time the change in status occurred. Make
sure to use the U.T.C. time format. This is because
the A.P.I. has made a design decision to standardise
on it.
status:
type: string
example: "on"
description: >-
The current status of the device you would like to log.
The two status types are "on" and "off".
token:
type: string
example: it-is-not-password-if-you-are-wondering
description: >-
This is basically a token to check the info. sent to
the server is from a valid machine.
responses:
201:
description: >-
The status update was successfully added to the database.
400:
description: >-
The data sent to the sever was invalid or incorrectly
formatted. The most likely reasons are invalid device Id.
specified and incorrect datetime format used.
/status/latest/{device}:
get:
operationId: api.get_latest_device_status
tags:
- Request Device Status
summary: >-
Returns the current status of the specified device.
description: >-
Use this U.R.L. to retrieve the current status of the device
you specified (in the U.R.L.). At the time of writing, the
project has six devices in total which are split equally
between Ritherdon and the gallery. Devices 1 to 3 (light-meters)
refer to the devices in Ritherdon and 4 to 6 (relays) are in
the gallery. Each light-meter and relay should pair up in the
following ways: 1->4, 2->5 and 3->6.
parameters:
- name: device
in: path
description: >-
This is the Id. of the device which you are retrieving the
current status for. The Id. should consist of a number
between 1 and 6, at the time of writing.
type: integer
required: True
responses:
200:
description: >-
If the server can successfully retrieve the current status
for the specified device, you should receive a JSON object
like the one below. It should include the Id. of the
device, the current status and the time it was logged.
schema:
type: object
properties:
id:
type: integer
example: 2
description: >-
The is the Id. of the device.
time:
type: string
example: 2019-10-19 17:04:57
description: >-
The time the status change was logged in the
database. The A.P.I. has standardised on the
U.T.C. format.
status:
type: string
example: on
description: The current status of the device.
400:
description: >-
The device Id. specified in invalid.
/status/all/{device}:
get:
operationId: api.get_all_status_log
tags:
- Request Device Status
summary: >-
Returns every status change logged by the specified device.
description: >-
Use this U.R.L. to retrieve every change in the specified
devices state. At the time of writing, the project has six
devices and are labelled 1 to 6. Devices (light-meters) 1 to 3
are located in the Ritherdon factory and 4 to 6 (relays) in the
gallery. The light-meters and relays are paired like so, 1->4,
2->5 and 3->6.
parameters:
- name: device
in: path
description: >-
The Id. of the device you are retrieving the status change
log for. The Id. should be a number between 1 and 6.
type: integer
required: True
responses:
200:
description: >-
If the server can successfully retrieve all the status logs
for the specified device, you should receive an array of
JSON objects like the one in the example below. It should
include the database Id. of the logged status change, the
time the status change was logged and the status itself.
schema:
type: object
properties:
id:
type: integer
example: 3
description: >-
This is the database Id. of the logged status change.
time:
type: string
example: 2019-10-19 17:23:23
description: >-
The time and date the status change was logged. The
A.P.I. has standardised on the U.T.C. format.
status:
type: string
example: off
description: >-
The status of the device after the change occurred.
400:
description: >-
The device Id. specified in invalid.
/status/all:
get:
operationId: api.get_all_status_logs_for_every_device
tags:
- Request Device Status
summary: >-
Returns every logged status change of every device in the
project.
description: >-
Use this U.R.L. to retrieve every logged status change of every
device used in this project. There is no example of the data
returned because I can't seem to replicate it as a YAML schema
which is understood by Swagger. Because of this. the return
type is registered as a free-form object. To see what the data
looks like when it is returned, I recommend you use the "Try it
out!" button to see a working example.
responses:
200:
description: >-
All the logged status changes of every device were
successfully retrieved from the database and delivered.
schema:
type: object
additionalProperties: True
/status/latest:
get:
operationId: api.get_current_status_for_all_devices
tags:
- Request Device Status
summary: >-
Returns the last recorded status change of every device in the
database.
description: >-
Use this U.R.L. to retrieve the last recorded status change of
every device used in this project. There is no example of the
data returned because I can't seem to replicate it as a YAML
schema which is understood by Swagger. Because of this. the
return type is registered as a free-form object. To see what
the data looks like when it is returned, I recommend you use
the "Try it out!" button to see a working example.
responses:
200:
description: >-
The last recorded status change of every device in this
project was retrieved successfully.
schema:
type: object
additionalProperties: True