Merge branch 'master' into feat/DHT-11-humi-dans-temp-capteur

This commit is contained in:
2023-05-02 11:46:37 +02:00
272 changed files with 27442 additions and 23 deletions

18
IOT/config.cppcheck Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>.cppcheck-build</builddir>
<platform>Unspecified</platform>
<analyze-all-vs-configs>true</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>false</check-unused-templates>
<max-ctu-depth>10</max-ctu-depth>
<exclude>
<path name="./.pio/" />
</exclude>
<suppressions>
<suppression>noCopyConstructor</suppression>
<suppression>noExplicitConstructor</suppression>
<suppression>unusedFunction</suppression>
<suppression>noOperatorEq</suppression>
</suppressions>
</project>

View File

@ -14,8 +14,17 @@ build_flags =
-D MONITOR_SPEED=${config.monitor_speed}
; DO NOT TOUCH --- END
-D API_HOST=\"iot.epi.cb85.software\"
; DHT pin and type
-D DHTTYPE=\"DHT11\"
-D DHTPIN=2
; ULTRASON pin
-D ULTRA_SOUND_TRIGD=12
-D ULTRA_SOUND_ECHO=13
; API host url
-D API_HOST=\"iot.epi.cb85.software\"
; trash can ID
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"

2740
IOT/docs/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
@startuml Class Diagram
Class API {
- user: String
- password: String
- serveurHost: String
- https: bool
- client: WiFiEspClient*
- connect(): bool
+ API(user: String, password: String, host: String, https: bool = true)
+ wifiBegin(wifiId: String, wifiPass: String, espSerial: Stream*): bool
+ sendValue(val: String, pouvelleID: String, unit: String, full: bool): bool
}
Class Program {
+ Program()
+ setup()
}
@enduml

View File

@ -1,4 +1,10 @@
; Add additionnal environments in this file
; Debug environemnt
[env:test]
test_build_src = true
build_type = debug
build_flags = ${env.build_flags}
-D TESTING
; Default production environment
[env:prod]

View File

@ -1,7 +1,10 @@
#ifndef PROGRAM_H
#define PROGRAM_H
#include "DHT.h"
#include <DHT.h>
#include <Arduino.h>
#include <Ultrasonic.h>
#include "API.h"
class Program{
public:
@ -25,5 +28,17 @@ private:
*
*/
DHT *dht;
/**
* @brief capteur ultra son pour le niveau de remplissage de la poubelle
*
*/
Ultrasonic *ultrasonic;
/**
* @brief Réference de l'API pour les calls
*
*/
API *api;
};
#endif

View File

@ -21,28 +21,26 @@ public:
/**
* @brief Initialise la connection Wifi de l'esp
*
* @param wifiId nom du wifi
* @param wifiPass mot de passe du wifi
* @param espSerial port serie de l'esp (hard ou soft)
* @param[in] wifiId nom du wifi
* @param[in] wifiPass mot de passe du wifi
* @param[in] espSerial port serie de l'esp (hard ou soft)
* @return true la connexion a bien fonctionner
* @return false erreur a la connexion
*/
bool wifiBegin(String wifiId, String wifiPass, Stream* espSerial);
bool wifiBegin(String wifiID, String wifiPass, Stream* espSerial);
/**
* @brief envoie la valeur d'un capteur de poubelle à l'api
*
* @param val valeur du capteur
* @param poubelleID ID de la poubelle
* @param unit uniter de mesure du capteur *(ex: g, cm, degree,...)
* @param full poubelle est considéré comme pleine
* @param[in] val valeur du capteur
* @param[in] poubelleID ID de la poubelle
* @param[in] unit uniter de mesure du capteur *(ex: g, cm, degree,...)
* @param[in] full poubelle est considéré comme pleine
* @return true la valeur s'est bien envoyer
* @return false il y a une erreur durran l'envoie
*/
bool sendValute(String val, String poubelleID, String unit, bool full);
private:
bool sendValue(String val, String poubelleID, String unit, bool full);
/**
* @brief connect l'utilisateur a l'api et met a jour le token
*
@ -51,6 +49,11 @@ private:
*/
bool connect();
//TODO :: Check wifibegin avant
private:
/**
* @brief ID de l'utilisateur
*

View File

@ -59,7 +59,8 @@ bool API::connect(){
this->client->println();
while (!client->available()) {}
while (!client->available()) {
}
String responce = "";
while (client->available()) {
@ -77,11 +78,14 @@ bool API::connect(){
this->client->stop();
sortie = true;
if (JSONVar::stringify(JSONVar::parse(str)["code"]) == "400") {
Serial.println("Failed to authenticate");
return false;
}
return sortie;
}
bool API::sendValute(String val, String poubelleID, String valUnit, bool full){
bool API::sendValue(String val, String poubelleID, String valUnit, bool full){
JSONVar data;
data["value"] = val;
data["trash_id"] = poubelleID;

View File

@ -40,6 +40,7 @@ lib_deps =
arduino-libraries/Arduino_JSON@^0.2.0 ; gestion des json
adafruit/DHT sensor library@^1.4.4 ; DHT11 lib
adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11)
ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son
; example:
; erropix/ESP32 AnalogWrite@^0.2

View File

@ -1,20 +1,32 @@
#include "Program.h"
int distance;
Program::Program(){
Serial1.begin(MONITOR_SPEED);
Serial.begin(MONITOR_SPEED);
// INIT OBJ
this->dht = new DHT(DHTPIN, DHTTYPE);
Serial.begin(MONITOR_SPEED);
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
dht->begin();
}
void Program::loop(){
distance = this->ultrasonic->read();
//TODO: envoyer les infos des capteur par la suite
Serial.println("Temperature = " + String(dht->readTemperature())+" °C");
Serial.println("Humidite = " + String(dht->readHumidity())+" %");
delay(1000);
this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false);
Serial.print("Distance in CM: ");
Serial.println(distance);
delay(10000);
}

View File

@ -1,12 +1,16 @@
#ifndef TESTING
#include <Arduino.h>
#include "Program.h"
Program* program;
void setup() {
program = new Program();
program = new Program();
}
void loop() {
program->loop();
program->loop();
}
#endif

23
IOT/test/main.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <Arduino.h>
#include <unity.h>
#include "test.h"
void setup() {
delay(2000);
// start unit tests engine
UNITY_BEGIN();
Serial.begin(115200);
RUN_TEST(TestWifiBeginConnected);
RUN_TEST(TestWifiBeginNotConnected);
RUN_TEST(TestConnectAPI);
// RUN_TEST(TestConnectAPIFailed);
RUN_TEST(TestSendValue);
UNITY_END();
}
void loop() {
}

10
IOT/test/test.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef TEST_H
#define TEST_H
void TestWifiBeginConnected();
void TestWifiBeginNotConnected();
void TestConnectAPI();
void TestConnectAPIFailed();
void TestSendValue();
#endif

48
IOT/test/test_api.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "test.h"
#include <unity.h>
#include "API.h"
//Testing WifiBegin function
void TestWifiBeginConnected() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial1.begin(MONITOR_SPEED);
TEST_ASSERT_EQUAL_MESSAGE(true, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1), "Wifi not connected");
}
void TestWifiBeginNotConnected() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial2.begin(MONITOR_SPEED);
TEST_ASSERT_EQUAL_MESSAGE(false, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial2), "Wifi connected");
}
//Testing Connect function
void TestConnectAPI() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial1.begin(MONITOR_SPEED);
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
TEST_ASSERT_EQUAL_MESSAGE(true, api->connect(), "Not Connected");
}
//FIXME: boucle inf when connection failed
void TestConnectAPIFailed() {
API* api = new API("Carl", "toto", API_HOST);
Serial1.begin(MONITOR_SPEED);
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
TEST_ASSERT_EQUAL_MESSAGE(false, api->connect(), "Connected");
}
//Testing SendValue function
void TestSendValue() {
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
Serial1.begin(MONITOR_SPEED);
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
TEST_ASSERT_EQUAL_MESSAGE(true, api->sendValue("30", "gdnuxl0wlgurtj3", "W", true), "Not Connected to server");
}