diff --git a/api.MD b/api.MD index f6f8514..a8b5f2c 100644 --- a/api.MD +++ b/api.MD @@ -84,13 +84,13 @@ curl localhost/api/v0/sensor-data/new -H "Content-Type: application/json" -X POS //put curl localhost/api/v0/sensor-data/update -H "Content-Type: application/json" -X PUT -d '{"id": "1", "id_sensor": "1" , "id_location": "3" , "sensordata": { "psi": "500", -"humidity": "11%", -"o3": "326ppm", -"no2": "445ppm", -"so2": "511ppm", -"co": "16ppm", -"temperature": "25C", -"windspeed": "2km/h", +"humidity": "11", +"o3": "326", +"no2": "445", +"so2": "511", +"co": "16", +"temperature": "25", +"windspeed": "2", }}' //delete @@ -160,10 +160,15 @@ Hour = 1 or wtv curl 'http://localhost/api/v0/sensor-data/data?year=2023&month=1&week=1&day=1&sensorid=1&locationid=1' - - //get specific data -http://localhost/api/v0/sensor-data/filter?windspeed=highest&limit=1 +http://localhost/api/v0/sensor-data/data?psi=highest + +//avg +http://localhost/api/v0/sensor-data/data?avg=temperature + +//sum +http://localhost/api/v0/sensor-data/data?sum=temperature + //pagination http://localhost/api/v0/sensor-data/data?week=1&sensorid=1&locationid=1&page=2&pagesize=10 diff --git a/consumerWebsite/app.js b/consumerWebsite/app.js index 9d61535..ab82e57 100644 --- a/consumerWebsite/app.js +++ b/consumerWebsite/app.js @@ -6,7 +6,7 @@ const ejs = require("ejs"); module.exports = app; -//process.nextTick(() => require("./mqttApp")); +process.nextTick(() => require("./mqttApp")); app.use(express.json()); app.set("json spaces", 2); @@ -68,7 +68,6 @@ app.use(function (err, req, res, next) { keyErrors[item.path] = item.message; } } - res.status = 422; } if (![404, 401, 422].includes(err.status || res.status)) { @@ -77,7 +76,6 @@ app.use(function (err, req, res, next) { console.error("========================================="); } res.status(err.status || 500); - // res.status(err.status || 500); if (req.get('Content-Type') && req.get('Content-Type').includes("json")) { res.json({ diff --git a/consumerWebsite/functions/api.js b/consumerWebsite/functions/api.js index 4f456d1..cdce376 100644 --- a/consumerWebsite/functions/api.js +++ b/consumerWebsite/functions/api.js @@ -8,6 +8,7 @@ async function getTokenByToken(token) { const splitAuthToken = token.split("-"); const rowid = splitAuthToken[0]; const suppliedToken = splitAuthToken.slice(1).join("-"); + if (!suppliedToken) return false; token = await tokenModel.findByPk(rowid, { include: userModel }); diff --git a/consumerWebsite/functions/sensorData.js b/consumerWebsite/functions/sensorData.js index 20a4176..b31123d 100644 --- a/consumerWebsite/functions/sensorData.js +++ b/consumerWebsite/functions/sensorData.js @@ -18,17 +18,17 @@ async function getSensorData() { const sensorData = await sensorDataModel.findAll(); return sensorData; } -async function addSensorData(id_sensor, id_location, sensordata) { +async function addSensorData(sensorid , locationid , measurement) { const sensorData = await sensorDataModel.create({ - sensorid: id_sensor, - locationid: id_location , - measurement: sensordata.measurement, + sensorid: sensorid, + locationid: locationid, + measurement: measurement }); //console.log("sensorData", sensorData); //console.log("sensorData", sensordata.measurement); - + //console.log("sensorData", sensorData.measurement); - io().emit('sensorData:new', sensordata) + io().emit('sensorData:new', sensorData.measurement); return sensorData; } @@ -674,6 +674,7 @@ async function getDatabyRange(queryString) { queryString.limit = queryString.pagesize; whereDate = {}; + ormQuery = {}; for (let query in queryString) { if (buildFunc[query]) { await buildFunc[query](queryString); @@ -700,6 +701,8 @@ async function getDatabyRange(queryString) { } } else { whereDate = {}; + ormQuery = {}; + for (let query in queryString) { if (buildFunc[query]) { await buildFunc[query](queryString); diff --git a/consumerWebsite/public/css/sp.css b/consumerWebsite/public/css/sp.css index 9f42978..ccbfc42 100644 --- a/consumerWebsite/public/css/sp.css +++ b/consumerWebsite/public/css/sp.css @@ -15,12 +15,11 @@ body { } .wrapper { position: relative; - max-width: 470px; + max-width: 600px; /* Increase the maximum width */ width: 100%; border-radius: 12px; - padding: 20px - 30px - 120px; + padding: 40px 50px 150px; /* Adjust the padding */ + background: #4070f4; box-shadow: 0 5px diff --git a/consumerWebsite/public/js/data.js b/consumerWebsite/public/js/data.js index cc69857..47dfe0d 100644 --- a/consumerWebsite/public/js/data.js +++ b/consumerWebsite/public/js/data.js @@ -1,5 +1,6 @@ //getting button from DOM id const buttons = document.querySelectorAll(".button-container button"); +const weeklybuttons = document.querySelectorAll(".weeklybutton-container button"); const queryButton = document.getElementById("querybutton-container"); $(document).ready(async function () { @@ -21,7 +22,7 @@ $(document).ready(async function () { labels: [], // Array to store timestamps datasets: [ { - label: "Average MeasurementData", + label: "Average Measurement Data", data: [], // Array to store measurements objects backgroundColor: "green", borderColor: "green", @@ -87,7 +88,6 @@ $(document).ready(async function () { chart.update(); }); } - // Event listeners for buttons document.getElementById("psiButton").addEventListener("click", function () { updateChart("psi"); @@ -116,4 +116,6 @@ $(document).ready(async function () { document.getElementById("coButton").addEventListener("click", function () { updateChart("co"); }); + + }); diff --git a/consumerWebsite/routes/api_routes.js b/consumerWebsite/routes/api_routes.js index a6f6faa..0663dae 100644 --- a/consumerWebsite/routes/api_routes.js +++ b/consumerWebsite/routes/api_routes.js @@ -19,7 +19,7 @@ router.use('/sensor', [auth, APIlogger], require('./sensor.js')); router.use('/sensor-data', [auth, APIlogger], require('./sensorData.js')); //apilog route -router.use('/apilog', [APIlogger], require('./apilog.js')); +router.use('/apilog', [auth, APIlogger], require('./apilog.js')); //latest sensor data to display on dashboard router.use('/latest-sensor-data', [APIlogger], require('./latestsensorData.js')); diff --git a/consumerWebsite/routes/apilog.js b/consumerWebsite/routes/apilog.js index 6b1eb89..ca88cc4 100644 --- a/consumerWebsite/routes/apilog.js +++ b/consumerWebsite/routes/apilog.js @@ -12,6 +12,7 @@ router.get("/", async (req, res, next) => { res.json(Res); }); +/* //get by route name? router.get("/route/:name", async (req, res, next) => { }); @@ -27,6 +28,8 @@ router.get("/method/:method", async (req, res, next) => { //by ip router.get("/ip/:ip", async (req, res, next) => { }); +*/ + diff --git a/consumerWebsite/routes/sensorData.js b/consumerWebsite/routes/sensorData.js index c3862f5..315ea0d 100644 --- a/consumerWebsite/routes/sensorData.js +++ b/consumerWebsite/routes/sensorData.js @@ -23,8 +23,9 @@ router.get("/", async (req, res, next) => { router.post("/new", async (req, res, next) => { try { - const { id_sensor, id_location, sensordata } = req.body; - let data = await addSensorData(id_sensor, id_location, sensordata); + //locationid + const { sensorid , locationid , measurement } = req.body; + let data = await addSensorData(sensorid , locationid , measurement); res.json({ message: "SensorData " + data.id + " added", ...data }); } catch (error) { console.error(error); @@ -34,8 +35,8 @@ router.post("/new", async (req, res, next) => { router.put("/update", async (req, res, next) => { try { - const { id, id_sensor, id_location, sensordata } = req.body; - await updateSensorData(id, id_sensor, id_location, sensordata); + const { id , sensorid , locationid , measurement } = req.body; + await updateSensorData(id, sensorid , locationid , measurement); res.status(200).json({ message: "SensorData " + id + " updated" }); } catch (error) { console.error(error); @@ -55,7 +56,6 @@ router.delete("/delete", async (req, res, next) => { }); router.get("/data", async (req, res, next) => { try { - console.log(req.query); const data = await getData(req.query); res.status(200).json(data); diff --git a/consumerWebsite/views/api.ejs b/consumerWebsite/views/api.ejs index f265e1f..c714966 100644 --- a/consumerWebsite/views/api.ejs +++ b/consumerWebsite/views/api.ejs @@ -12,46 +12,46 @@ - -
- -
-
- - -
-
+ +
+ +
+
+ + +
+
@@ -69,8 +69,8 @@

Get all location

- To get Location of sensors you need to make a GET call to the following url :
- https://api.teeseng.uk/api/v0/location + To get all location of sensors you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/location

Return Response :
@@ -91,9 +91,8 @@ Authorization JSON Your API key. - (Required) Example: curl https://api.teeseng.uk/api/v0/location -H "Authorization: - {provide your - API key here}" + (Required) Example: curl https://ecosaver.teeseng.uk/api/v0/location -H "auth-token: + {provide your API key here}" @@ -103,7 +102,7 @@

Get location by ID

To get Location you need to make a GET call to the following url :
- https://api.teeseng.uk/api/v0/location/{id} + https://ecosaver.teeseng.uk/api/v0/location/{id}

Return Response :
@@ -124,7 +123,7 @@ Authorization JSON (Required) Your API key. - Example: curl https://api.teeseng.uk/api/v0/location -H "Authorization: {provide + Example: curl https://ecosaver.teeseng.uk/api/v0/location/1 -H "auth-token: {provide your API key here}" @@ -132,16 +131,49 @@

+
+

Get location by name

+

+ To get Location you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/location/{location name} +
+
+ Return Response :
+ {"status":"200"} +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSON(Required) Your API key.Example: curl https://ecosaver.teeseng.uk/api/v0/location/ang mo kio -H "auth-token: + {provide your API key here}"
+

Add Location (Only for system or admin API key)

To add an Location you need to make a POST call to the following url :
- https://api.teeseng.uk/api/v0/location/new + https://ecosaver.teeseng.uk/api/v0/location/new

Example :
curl https://api.teeseng.uk/api/v0/location/new -H "Content-Type: application/json" -X POST -d '{"name": "SAMPLE", "added_by": "system" , "description": "test"}' + class="higlighted break-word">curl https://ecosaver.teeseng.uk/api/v0/location/new -H "Content-Type: application/json" -H "auth-token: {provide your API key here}" -X POST -d '{"name": "SAMPLE", "added_by": "system", "description": "test"}'

Return Response :
@@ -162,8 +194,8 @@ Authorization JSON Your API key. - (Required) Example: curl https://api.teeseng.uk/api/v0/location/new -H - "Authorization: {provide your + (Required) Example: curl https://ecosaver.teeseng.uk/api/v0/location/new -H + "auth-token: {provide your API key here}" @@ -171,8 +203,9 @@ Location name JSON Location name. - (Required) Location name. Example: curl https://api.teeseng.uk/api/v0/location/new - -H "Authorization: provide + (Required) Location name. Example: curl + https://ecosaver.teeseng.uk/api/v0/location/new + -H "auth-token: provide your API key here" -d '{"name":"Location name"}' @@ -180,8 +213,8 @@ Added by JSON System or Admin - (Required) System or Admin Example: curl https://api.teeseng.uk/api/v0/location/new - -H "Authorization: provide + (Required) Added_by Example: curl https://ecosaver.teeseng.uk/api/v0/location/new + -H "auth-token: provide your API key here" -d '{"added_by":"system"}' @@ -189,8 +222,8 @@ Description JSON Description of Location - (Required) System or Admin Example: curl https://api.teeseng.uk/api/v0/location/new - -H "Authorization: provide + (Required) Description Example: curl https://ecosaver.teeseng.uk/api/v0/location/new + -H "auth-token: provide your API key here" -d '{"description":"test"}' @@ -202,12 +235,12 @@

Update Location (Only for system or admin API key)

To update an Location you need to make a PUT call to the following url :
- https://api.teeseng.uk/api/v0/location/update + https://ecosaver.teeseng.uk/api/v0/location/update

Example :
curl https://api.teeseng.uk/api/v0/location/update -H "Content-Type: application/json" -X POST -d '{"id": "7" , "name": "SAMPLE", "added_by": "system" , "description": "test"}' + class="higlighted break-word">curl https://ecosaver.teeseng.uk/api/v0/location/update -H "Content-Type: application/json" -H "auth-token: {provide your API key here}" -X POST -d '{"id": "7" , "name": "SAMPLE", "added_by": "system" , "description": "test"}'

Return Response :
@@ -228,8 +261,8 @@ Authorization JSON Your API key. - (Required) example: curl https://api.teeseng.uk/api/v0/location/update -H - "Authorization: {provide your + (Required) example: curl https://ecosaver.teeseng.uk/api/v0/location/update -H + "auth-token: {provide your API key here}" @@ -237,8 +270,9 @@ ID JSON Location ID - (Required) Location ID Example: curl https://api.teeseng.uk/api/v0/location/update - -H "Authorization: provide + (Required) Location ID Example: curl + https://ecosaver.teeseng.uk/api/v0/location/update + -H "auth-token: provide your API key here" -d '{"id": "7"}' @@ -246,8 +280,9 @@ Location name JSON Location name. - (Optional) Location name. Example: curl https://api.teeseng.uk/api/v0/location/new - -H "Authorization: provide + (Optional) Location name. Example: curl + https://ecosaver.teeseng.uk/api/v0/location/new + -H "auth-token: provide your API key here" -d '{"name":"Location name"}' @@ -255,8 +290,8 @@ Added by JSON System or Admin - (Optional) System or Admin Example: curl https://api.teeseng.uk/api/v0/location/new - -H "Authorization: provide + (Optiona) Added_by Example: curl https://ecosaver.teeseng.uk/api/v0/location/new + -H "auth-token: provide your API key here" -d '{"added_by":"system"}' @@ -264,7 +299,8 @@ Description JSON Description of Location - (Optional) System or Admin Example: curl https://api.teeseng.uk/api/v0/location/new + (Optional) System or Admin Example: curl + https://ecosaver.teeseng.uk/api/v0/location/new -H "Authorization: provide your API key here" -d '{"description":"test"}' @@ -277,12 +313,12 @@

Delete Location (Only for system or admin API key)

To delete an Location you need to make a DELETE call to the following url :
- https://api.teeseng.uk/api/v0/location/delete + https://ecosaver.teeseng.uk/api/v0/location/delete

Example :
curl https://api.teeseng.uk/api/v0/location/delete -H "Content-Type: application/json" -X POST -d '{"id": "7"}' + class="higlighted break-word">curl https://ecosaver.teeseng.uk/api/v0/location/delete -H "Content-Type: application/json" -X POST -d '{"id": "7"}'


QUERY PARAMETERS

@@ -299,8 +335,8 @@ Authorization JSON Your API key. - (Required) example: curl https://api.teeseng.uk/api/v0/location/delete -H - "Authorization: {provide your + (Required) example: curl https://ecosaver.teeseng.uk/api/v0/location/delete -H + "auth-token: {provide your API key here}" @@ -308,19 +344,21 @@ ID JSON Location ID - (Required) Location ID Example: curl https://api.teeseng.uk/api/v0/location/delete - -H "Authorization: provide + (Required) Location ID Example: curl + https://ecosaver.teeseng.uk/api/v0/location/delete + -H "auth-token: provide your API key here" -d '{"id": "7"}'
+

Get all sensor

To get sensors you need to make a GET call to the following url :
- https://api.teeseng.uk/api/v0/sensor + https://ecosaver.teeseng.uk/api/v0/sensor

Return Response :
@@ -341,7 +379,7 @@ Authorization JSON Your API key. - (Required) Example: curl https://api.teeseng.uk/api/v0/sensor -H "Authorization: + (Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor -H "auth-token: {provide your API key here}" @@ -353,7 +391,7 @@

Get sensor by ID

To get Sensor you need to make a GET call to the following url :
- https://api.teeseng.uk/api/v0/sensor/{id} + https://ecosaver.teeseng.uk/api/v0/sensor/{id}

Return Response :
@@ -374,7 +412,8 @@ Authorization JSON (Required) Your API key. - Example: curl https://api.teeseng.uk/api/v0/sensor/{id} -H "Authorization: {provide + Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/{id} -H "Authorization: + {provide your API key here}" @@ -382,16 +421,50 @@

+
+

Get sensor by name

+

+ To get sensor by name you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor/{sensor name} +
+
+ Return Response :
+ {"status":"200"} +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSON(Required) Your API key.Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/AQI -H "auth-token: {provide + your API key here}"
+
+

Add Sensor (Only for system or admin API key)

To add a Sensor you need to make a POST call to the following url :
- https://api.teeseng.uk/api/v0/sensor/new + https://ecosaver.teeseng.uk/api/v0/sensor/new

Example :
curl https://api.teeseng.uk/api/v0/sensor/new -H "Content-Type: application/json" -X POST -d '{"sensorname": "test", "added_by": "system" , "mac_address": "99-6A-F8-7D-B4-94", "description": "test" , "location": "11"}' + class="higlighted break-word">curl https://ecosaver.teeseng.uk/api/v0/sensor/new -H "Content-Type: application/json" -H "auth-token: {provide your API key here}" -X POST -d '{"sensorname": "test", "added_by": "system" , "mac_address": "99-6A-F8-7D-B4-94", "description": "test" , "location": "11"}'

Return Response :
@@ -412,17 +485,18 @@ Authorization JSON Your API key. - (Required) Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: {provide your + (Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: {provide your API key here}" Sensor name JSON - Sesnsor name. - (Required) Location name. Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: provide + Sensor name. + (Required) Location name. Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide your API key here" -d '{"sensorname": "test"}' @@ -430,8 +504,9 @@ Added by JSON System or Admin - (Required) System or Admin Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: provide + (Required) System or Admin Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide your API key here" -d '{"added_by":"system"}' @@ -439,8 +514,8 @@ Mac Address JSON Mac Address - (Required) Mac Address Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: provide + (Required) Mac Address Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide your API key here" -d '{"mac_address": "99-6A-F8-7D-B4-94"}' @@ -448,42 +523,34 @@ Description JSON Description of Sensor - (Required) System or Admin Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: provide + (Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide your API key here" -d '{"description":"test"}' - Mac Address + Location ID JSON - Mac Address - (Required) Mac Address Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: provide - your API key here" -d '{"mac_address": "99-6A-F8-7D-B4-94"}' - - - - Location - JSON - Location - (Required) Location Example: curl https://api.teeseng.uk/api/v0/sensor/new - -H "Authorization: provide + Location ID + (Required) Location Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide your API key here" -d '{"location": "11"}'

+

Update Sensor (Only for system or admin API key)

To update a Sensor you need to make a PUT call to the following url :
- https://api.teeseng.uk/api/v0/sensor/update + https://ecosaver.teeseng.uk/api/v0/sensor/update

Example :
curl https://api.teeseng.uk/api/v0/sensor/update -H "Content-Type: application/json" -X POST -d '{"id": "2" ,"sensorname": "test", "added_by": "system" , "mac_address": "99-6A-F8-7D-B4-94" , "description": "test123" , "location": "11" }' + class="higlighted break-word">curl https://ecosaver.teeseng.uk/api/v0/sensor/update -H "Content-Type: application/json" -X POST -d '{"id": "2" ,"sensorname": "test", "added_by": "system" , "mac_address": "99-6A-F8-7D-B4-94" , "description": "test123" , "location": "11" }'

Return Response :
@@ -504,8 +571,8 @@ Authorization JSON Your API key. - (Required) example: curl https://api.teeseng.uk/api/v0/sensor/update -H - "Authorization: {provide your + (Required) example: curl https://ecosaver.teeseng.uk/api/v0/sensor/update -H + "auth-token: {provide your API key here}" @@ -513,8 +580,8 @@ ID JSON Sensor ID - (Required) Sensor ID Example: curl https://api.teeseng.uk/api/v0/sensor/update - -H "Authorization: provide + (Required) Sensor ID Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/update + -H "auth-token: provide your API key here" -d '{"id": "7"}' @@ -522,8 +589,9 @@ Sensor name JSON Sensor name. - (Optional) Sensor name. Example: curl https://api.teeseng.uk/api/v0/sensor/update - -H "Authorization: provide + (Optional) Sensor name. Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/update + -H "auth-token: provide your API key here" -d '{"sensorname": "test"}' @@ -531,8 +599,9 @@ Added by JSON System or Admin - (Optional) System or Admin Example: curl https://api.teeseng.uk/api/v0/sensor/update - -H "Authorization: provide + (Optional) System or Admin Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/update + -H "auth-token: provide your API key here" -d '{"added_by":"system"}' @@ -540,8 +609,9 @@ Mac Address JSON Mac Address - (Optional) Mac Address Example: curl https://api.teeseng.uk/api/v0/sensor/update - -H "Authorization: provide + (Optional) Mac Address Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/update + -H "auth-token: provide your API key here" -d '{"mac_address": "99-6A-F8-7D-B4-94"}' @@ -550,8 +620,8 @@ JSON Description of Sensor (Optional) Description of Sensor Example: curl - https://api.teeseng.uk/api/v0/sensor/update - -H "Authorization: provide + https://ecosaver.teeseng.uk/api/v0/sensor/update + -H "auth-token: provide your API key here" -d '{"description":"test"}' @@ -560,8 +630,8 @@ JSON Location of Sensor (Optional) Location of Sensor Example: curl - https://api.teeseng.uk/api/v0/sensor/update - -H "Authorization: provide + https://ecosaver.teeseng.uk/api/v0/sensor/update + -H "auth-token: provide your API key here" -d '{"location": "11"}' @@ -572,12 +642,12 @@

Delete Sensor (Only for system or admin API key)

To delete a sensor you need to make a DELETE call to the following url :
- https://api.teeseng.uk/api/v0/sensor/delete + https://ecosaver.teeseng.uk/api/v0/sensor/delete

Example :
curl https://api.teeseng.uk/api/v0/sensor/delete -H "Content-Type: application/json" -X POST -d '{"id": "7"}' + class="higlighted break-word">curl https://ecosaver.teeseng.uk/api/v0/sensor/delete -H "Content-Type: application/json" -X POST -d '{"id": "7"}'


QUERY PARAMETERS

@@ -594,8 +664,8 @@ Authorization JSON Your API key. - (Required) example: curl https://api.teeseng.uk/api/v0/sensor/delete -H - "Authorization: {provide your + (Required) example: curl https://ecosaver.teeseng.uk/api/v0/sensor/delete -H + "auth-token: {provide your API key here}" @@ -603,13 +673,617 @@ ID JSON Sensor ID - (Required) Sensor ID Example: curl https://api.teeseng.uk/api/v0/sensor/delete - -H "Authorization: provide + (Required) Sensor ID Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/delete + -H "auth-token: provide your API key here" -d '{"id": "7"}' + +
+

Get all sensor data

+

+ To get all location of sensors you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data +
+
+ Return Response :
+ {"status":"200"} +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor-data -H + "auth-token: + {provide your API key here}"
+
+
+

Get sensor data by ID

+

+ To get all location of sensors you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data/1 +
+
+ Return Response :
+ {"status":"200"} +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor-data/{id} -H + "auth-token: + {provide your API key here}"
+
+
+

Add Sensor data (Only for system or admin API key)

+

+ To add a Sensor data you need to make a POST call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data/new +
+
+ Example :
+ curl https://ecosaver.teeseng.uk/api/v0/sensor-data/new -H "Content-Type: application/json" + -H "auth-token: {provide your API key here}" -X POST -d ' + {"sensorid": "1" , "locationid": "1" , "measurement": { + "psi": "31", + "humidity": "90", + "o3": "5", + "no2": "5", + "so2": "5", + "co": "5", + "temperature": "31", + "windspeed": "8", + }}' +
+
+ Return Response :
+ {"status":"200"} +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: {provide your + API key here}"
Sensor IDJSONSensor ID.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"sensorid": "1"}'
Location IDJSONLocation ID.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"locationid": "1"}'
sensor MeasrementJSONMeasurement.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"measurement": {"psi": "31", "humidity": "90", "o3": + "5", "no2": "5", "so2": "5", "co": "5", "temperature": "31", "windspeed": "8"} + }'
+
+
+

Update Sensor data (Only for system or admin API key)

+

+ To update a Sensor data you need to make a PUT call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data/update +
+
+ Example :
+ curl https://ecosaver.teeseng.uk/api/v0/sensor-data/update -H "Content-Type: application/json" + -H "auth-token: {provide your API key here}" -X POST -d ' + {"id": "1" , "sensorid": "1" , "locationid": "1" , "measurement": { + "psi": "31", + "humidity": "90", + "o3": "6", + "no2": "6", + "so2": "6", + "co": "6", + "temperature": "32", + "windspeed": "6", + }}' +
+
+ Return Response :
+ {"status":"200"} +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) Example: curl https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: {provide your + API key here}"
Data IDJSONID.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"id": "1"}'
Sensor IDJSONSesnsor ID.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"sensorid": "1"}'
Location IDJSONLocation ID.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"locationid": "1"}'
sensor MeasurementJSONMeasurement.(Required) . Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor/new + -H "auth-token: provide + your API key here" -d '{"measurement": {"psi": "31", "humidity": "90", "o3": + "5", "no2": "5", "so2": "5", "co": "5", "temperature": "31", "windspeed": "8"} + }'
+
+ +
+

Delete Sensor Data (Only for system or admin API key)

+

+ To delete a sensor Data you need to make a DELETE call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data/delete +
+
+ Example :
+ curl https://ecosaver.teeseng.uk/api/v0/sensor-data/delete -H "Content-Type: application/json" -X POST -d '{"id": "7"}' +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) example: curl https://ecosaver.teeseng.uk/api/v0/location/delete -H + "auth-token: {provide your + API key here}"
IDJSONSensor data ID(Required) Sensor data ID Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/delete + -H "auth-token: provide + your API key here" -d '{"id": "1"}'
+
+ +
+

Get Sensor Data based on Querys

+

+ To get sensor Data based on queries you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data/data? +
+
+ Example :
+ curl https://ecosaver.teeseng.uk/api/v0/sensor-data/data?order=desc&limit=1 +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) example: curl https://ecosaver.teeseng.uk/api/v0/sensor-data/data? -H + "auth-token: {provide your + API key here}"
LimitJSONLimit the size of output(Optional) Location ID Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?limit=1 + -H "auth-token: provide + your API key here"
OrderJSONOrder the data from ascending or descending order.(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?order=asc + -H "auth-token: provide + your API key here"
YearJSONQuery data by year it was created(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?year=2023 + -H "auth-token: provide + your API key here"
MonthJSONQuery data by month it was created(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?month=1 or month=jan + -H "auth-token: provide + your API key here" +
WeekJSONQuery data by week it was created(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?week=1 + -H "auth-token: provide + your API key here" +
DayJSONQuery data by day it was created(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?day=1 + -H "auth-token: provide + your API key here" +
HourJSONQuery data by specific hour it was created(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?hour=1 + -H "auth-token: provide + your API key here" +
MinuteJSONQuery data by specific minute it was created(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?minute=1 + -H "auth-token: provide + your API key here" +
SensoridJSONQuery data by specific sensor id(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?sensorid=1 + -H "auth-token: provide + your API key here" +
Location idJSONQuery data by specific location id(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?locationid=1 + -H "auth-token: provide + your API key here" +
Highest metric JSONGet highest value of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?hightest=psi + -H "auth-token: provide + your API key here" +
Lowest metric JSONGet lowest value of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?lowest=psi + -H "auth-token: provide + your API key here" +
Average of metricJSONGet average of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?avg=psi + -H "auth-token: provide + your API key here" +
Sum of metricJSONGet total sum of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?sum=psi + -H "auth-token: provide + your API key here" +
Amount of metricJSONGet total amount of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?total=psi + -H "auth-token: provide + your API key here" +
PageJSONGet specific page (Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?page=2 + -H "auth-token: provide + your API key here" +
Page SizeJSONGet specific page size (Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/data?pagesize=10 + -H "auth-token: provide + your API key here" +
+
+
+

Get Sensor Data based on date range Querys

+

+ To get sensor Data based on queries you need to make a GET call to the following url :
+ https://ecosaver.teeseng.uk/api/v0/sensor-data/range? +
+
+ Example :
+ curl https://ecosaver.teeseng.uk/api/v0/sensor-data/range?startdate=2024-01-01&enddate=2024-01-02 +

+
+

QUERY PARAMETERS

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldTypeDescription
AuthorizationJSONYour API key.(Required) example: curl https://ecosaver.teeseng.uk/api/v0/sensor-data/range? + -H + "auth-token: {provide your + API key here}"
LimitJSONLimit the size of output(Optional) Location ID Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/range?limit=1 + -H "auth-token: provide + your API key here"
Start DateJSONStart date you wish to query by(Optional) Location ID Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/range?startdate=2021-01-01 + -H "auth-token: provide + your API key here"
End DateJSONEnd date you wish to query by(Optional) Location ID Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/range?enddate=2021-01-01 + -H "auth-token: provide + your API key here"
Amount of metricJSONGet total amount of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/range?total=psi + -H "auth-token: provide + your API key here" +
Average of metricJSONGet average of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/range?avg=psi + -H "auth-token: provide + your API key here" +
Sum of metricJSONGet total sum of certain metric(Optional) Example: curl + https://ecosaver.teeseng.uk/api/v0/sensor-data/range?sum=psi + -H "auth-token: provide + your API key here" +
+

API Keys

@@ -619,7 +1293,7 @@

-
+
@@ -641,36 +1315,24 @@ - X000 + 200 - Some parameters are missing. This error appears when you don't pass every - mandatory - parameters. + Sucessful request. - 403 + 401 Unknown or unvalid secret_key. This error appears if - you use an unknow API key or if your API key expired. + you use an unknown API key or if your API key expired or you didnt provide one. 500 Unvalid secret_key No API key was supplied. - Invalid - request. - - - - X003 - - Unknown or unvalid user token. This error - appears if - you use an unknow user token or if the user - token expired. + Invalid request. @@ -683,4 +1345,4 @@ - + \ No newline at end of file