Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Tale152/brittany into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
ElisaTronetti committed Jan 12, 2022
2 parents 7e52500 + 70d544e commit dc3bd87
Show file tree
Hide file tree
Showing 167 changed files with 3,807 additions and 706 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/edge-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install lcov
run: sudo apt-get install -y lcov
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
Expand All @@ -34,4 +36,9 @@ jobs:
- name: Install library dependencies
run: pio lib -g install 1
- name: Run PlatformIO
run: cd ./edge && pio test
run: cd ./edge && pio test
- name: Check test coverage
uses: terencetcf/github-actions-lcov-minimum-coverage-checker@v1
with:
coverage-file: edge/filtered_lcov.info
minimum-coverage: 90
4 changes: 2 additions & 2 deletions auth-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth-service",
"version": "1.0.1",
"version": "1.0.2",
"description": "Server that handles the authorizations to use services in the Brittany environment",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions auth-service/src/routes/controllers/environment/get-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ async function listEnvironmentController(req, res){
if(stringUtil.isValidString(req.query.id)){
Environment.find({ id_greenhouse: new ObjectId(req.query.id) })
.select("-id_greenhouse -password -__v")
.then(async greenhouses => {
.then(async environments => {
res.status(200).json({
greenhouses: greenhouses
environments: environments
})
}).catch(err => {
res.status(500).json({err: err.toString()})
Expand Down
2 changes: 1 addition & 1 deletion auth-service/test/environment/get.list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test("Correct list", async () => {
}, token, 201, (res) => { /* does nothing */ })
await httpTest.get(server, "/environment/list",{
id: greenhouseId
}, token, 200, (res) => { expect(res.body.greenhouses[0].name).toBe(values.environmentName) })
}, token, 200, (res) => { expect(res.body.environments[0].name).toBe(values.environmentName) })
})

test("Wrong token", async () => {
Expand Down
3 changes: 3 additions & 0 deletions edge/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CMakeListsPrivate.txt
wifi_secret.h
cov/
lcov.info
filtered_lcov.info

# Created by https://www.toptal.com/developers/gitignore/api/c,c++,visualstudiocode,visualstudio,platformio,gradle,clion+all
# Edit at https://www.toptal.com/developers/gitignore?templates=c,c++,visualstudiocode,visualstudio,platformio,gradle,clion+all
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "DHT22SensorHw.h"

DHT22SensorHw::DHT22SensorHw(std::string id, uint8_t pin) : TempHumHwInterface(id, pin), dht(pin, DHT22) {
dht.begin();
}

std::optional<float> DHT22SensorHw::temperatureCelsius() {
float temp = dht.readTemperature();
return isnan(temp) ? std::nullopt : std::optional(temp);
}

std::optional<float> DHT22SensorHw::temperatureKelvin() {
std::optional<float> tempC = temperatureCelsius();
if(tempC.has_value()){
return std::optional(Temperature::fromCToK(tempC.value()));
}
return std::nullopt;
}

std::optional<float> DHT22SensorHw::temperatureFahrenheit() {
float temp = dht.readTemperature(true);
return isnan(temp) ? std::nullopt : std::optional(temp);
}

std::optional<float> DHT22SensorHw::humidity() {
float humidity = dht.readHumidity();
return isnan(humidity) ? std::nullopt : std::optional(humidity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BRITTANY_DHT22_SENSOR_HW_H
#define BRITTANY_DHT22_SENSOR_HW_H

#include "hw/interfaces/TempHumHwInterface.h"
#include <string>
#include <DHT.h>
#include <DHT_U.h>
#include <optional>
#include <Adafruit_Sensor.h>

/**
* @brief Concrete implementation of a DHT22 component.
*
*/
class DHT22SensorHw : public TempHumHwInterface {

public:

/**
* @brief Construct a new DHT22SensorHw object.
*
* @param id the hw id.
* @param pin the data pin of the DHT22.
*/
DHT22SensorHw(std::string id, uint8_t pin);

std::optional<float> temperatureCelsius();

std::optional<float> temperatureKelvin();

std::optional<float> temperatureFahrenheit();

std::optional<float> humidity();

private:

DHT dht;

};
#endif //BRITTANY_DHT22_SENSOR_HW_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef BRITTANY_DHT22_MODULE
#define BRITTANY_DHT22_MODULE

#include "modules/ComponentModule.h"
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h"
#include "temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h"
#include "temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h"
#include "util.h"

#define DHT22_GET_TEMPERATURE_HANDLER_NAME "temperature"
#define DHT22_GET_HUMIDITY_HANDLER_NAME "humidity"

class DHT22Module : public ComponentModule<DHT22SensorHw> {

public:

DHT22Module(std::string name, std::list<DHT22SensorHw*> components): ComponentModule<DHT22SensorHw>(name, components) {
_handlers.push_back(
new DHT22GetTemperatureHandler(
DHT22_GET_TEMPERATURE_HANDLER_NAME,
as_route(DHT22_GET_TEMPERATURE_HANDLER_NAME),
components
)
);
_handlers.push_back(
new DHT22GetHumidityHandler(
DHT22_GET_HUMIDITY_HANDLER_NAME,
as_route(DHT22_GET_HUMIDITY_HANDLER_NAME),
components
)
);
};

};

#endif //BRITTANY_DHT22_MODULE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "DHT22GetHumidityHandler.h"
#include "util.h"

DHT22GetHumidityHandler::DHT22GetHumidityHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
): DHT22Handler(name, path, components) {

}

std::optional<float> DHT22GetHumidityHandler::sub_operation(DHT22SensorHw* hw, Json::Value args) {
return hw -> humidity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef BRITTANY_DHT22_GET_HUMIDITY_HANDLER_H
#define BRITTANY_DHT22_GET_HUMIDITY_HANDLER_H

#include <string>
#include <list>
#include "DHT22Handler.h"
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h"

class DHT22GetHumidityHandler : public DHT22Handler {

public:

DHT22GetHumidityHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
);

private:

std::optional<float> sub_operation(DHT22SensorHw* hw, Json::Value args);

std::list<DHT22SensorHw*> _components;
};

#endif //BRITTANY_DHT22_GET_HUMIDITY_HANDLER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "DHT22GetTemperatureHandler.h"
#include "util.h"

DHT22GetTemperatureHandler::DHT22GetTemperatureHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
): DHT22Handler(name, path, components) {

}

std::optional<float> DHT22GetTemperatureHandler::sub_operation(DHT22SensorHw* hw, Json::Value args) {
if(args.isMember("unit")) {
if(args["unit"] == "C" || args["unit"] == "c") {
return hw -> temperatureCelsius();
} else if(args["unit"] == "K" || args["unit"] == "k") {
return hw -> temperatureKelvin();
} else if(args["unit"] == "F" || args["unit"] == "f") {
return hw -> temperatureFahrenheit();
}
return std::nullopt;
}
return hw -> temperatureCelsius();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H
#define BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H

#include <string>
#include <list>
#include "DHT22Handler.h"
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h"

class DHT22GetTemperatureHandler : public DHT22Handler {

public:

DHT22GetTemperatureHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
);

private:

std::optional<float> sub_operation(DHT22SensorHw* hw, Json::Value args);

std::list<DHT22SensorHw*> _components;
};

#endif //BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef BRITTANY_DHT22_HANDLER_H
#define BRITTANY_DHT22_HANDLER_H

#include <string>
#include <list>
#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h"
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h"

class DHT22Handler : public ValueReturnedAfterActionHandlerInterface<float> {

public:

DHT22Handler(std::string name, std::string path, std::list<DHT22SensorHw*> components)
: ValueReturnedAfterActionHandlerInterface<float> (name, path, OperationType::PROPERTY, Type::NUMBER) {
_components = components;
};

private:

std::optional<float> retrieveValue(Json::Value args) {
std::optional<DHT22SensorHw*> oc = find_by_id(_components, args["id"].asCString());
if(oc.has_value()) {
std::optional<float> opt_value = sub_operation(oc.value(), args);
if(opt_value.has_value()) {
return opt_value.value();
}
}
return std::nullopt;
}

virtual std::optional<float> sub_operation(DHT22SensorHw* hw, Json::Value args) = 0;

std::list<DHT22SensorHw*> _components;
};

#endif //BRITTANY_DHT22_HANDLER_H
Loading

0 comments on commit dc3bd87

Please sign in to comment.