18 Commits

Author SHA1 Message Date
5b7f0f3d3e refacto: main 2023-05-02 10:45:12 +02:00
4cafc40d61 feat: création classe abstraite capteur 2023-05-02 10:40:02 +02:00
17b344732f Merge pull request 'feat: Test_IOT' (#40) from feat/Test_IOT into master
Reviewed-on: Epitech-T-DEV-811/T-DEV-811#40
Reviewed-by: nico <nicolas.sansd@gmail.com>
Reviewed-by: Clement <clement@jo85.com>
2023-04-25 10:54:13 +02:00
9b0b5bedd8 feat: add doc for secret 2023-04-24 16:52:08 +02:00
e088b4e304 Fix: remove useless file 2023-04-24 16:49:54 +02:00
b3da67f31e feat: Add end to end test for ultrasonic capteur 2023-04-24 16:05:50 +02:00
884169e745 feat: add Test for sendValue 2023-04-24 15:49:16 +02:00
36bdb86343 feat: Add Test for Connect API 2023-04-24 14:54:26 +02:00
5784e38fbb feat: add Test for WifiConnect API 2023-04-24 12:22:52 +02:00
9811022b76 Create Branche Test_IOT 2023-04-24 11:17:36 +02:00
a150d1c17f Merge pull request 'add cppcheck config' (#39) from feat--cppcheck into master
Reviewed-on: Epitech-T-DEV-811/T-DEV-811#39
2023-04-24 11:00:25 +02:00
96ebd89dd3 add cppcheck config 2023-04-24 10:59:32 +02:00
370a16441b Merge pull request 'feat: capteur-ultrason' (#27) from feat--capteur-ultrason into master
Reviewed-on: Epitech-T-DEV-811/T-DEV-811#27
Reviewed-by: 5OLE1L <mathis.ragot@epitech.eu>
Reviewed-by: nico <nicolas.sansd@gmail.com>
2023-04-24 10:47:13 +02:00
71a07cc552 Merge pull request 'feat/AR_Architecture' (#37) from feat/AR_Architecture into master
Reviewed-on: Epitech-T-DEV-811/T-DEV-811#37
Reviewed-by: 5OLE1L <mathis.ragot@epitech.eu>
Reviewed-by: Clement <clement@jo85.com>
2023-04-24 09:54:04 +02:00
b1787886c6 Merge branch 'master' into feat/AR_Architecture 2023-04-24 09:53:37 +02:00
8928ab9922 Merge pull request 'feat/AR_Architecture' (#33) from feat/AR_Architecture into master
Reviewed-on: https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811/pulls/33
Reviewed-by: Clement <clement@jo85.com>
2023-04-11 16:09:36 +02:00
7b5d4a071b feat: add ultrasonic sensor and exemple 2023-04-04 15:37:55 +02:00
2e4b24df10 feat: untra son config 2023-04-04 14:36:45 +02:00
14 changed files with 243 additions and 9 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

@ -16,5 +16,10 @@ build_flags =
-D API_HOST=\"iot.epi.cb85.software\"
-D ULTRA_SOUND_TRIGD=12
-D ULTRA_SOUND_ECHO=13
-D EXAMPLE_NUMBER=69
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"

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,6 +1,10 @@
#ifndef PROGRAM_H
#define PROGRAM_H
#include <Arduino.h>
#include <Ultrasonic.h>
#include "API.h"
class Program{
public:
/**
@ -17,5 +21,17 @@ public:
private:
/* data */
/**
* @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

@ -40,9 +40,7 @@ public:
* @return false il y a une erreur durran l'envoie
*/
bool sendValue(String val, String poubelleID, String unit, bool full);
private:
/**
* @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,7 +78,10 @@ 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;
}

View File

@ -0,0 +1,65 @@
#ifndef CAPTEUR_H
#define CAPTEUR_H
#include <Arduino.h>
class Capteur{
public:
/**
* @brief Construct a new Capteur object
*
* @param[in] type type de mesure lue (T/H, W, D,...)
* @param[in] fullVal valeur a la quel la poubelle est considéré comme pleine
*/
Capteur(String type, String fullVal);
/**
* @brief tar le capteur si il a besoins d'être tarré
*
* @param[in] val *opt* si le capteur a besoins d'une valeur de ref pour être tarré
* @return true si la tarre a bien réussi (ou si il n'a pas besoins de tarre)
* @return false erreur durrant la tar
*/
virtual bool tar(int val = 0);
/**
* @brief lit la valeur du capteur
*
* @return String retour la valeur avec l'unité
*/
virtual String read() = 0;
/**
* @brief revoie la valeur full
*
* @return true la poubelle est pleine
* @return false la poubelle n'est pas pleine
*/
bool isFull();
protected:
/**
* @brief la poubelle est pleinne
* est mis a jours par read()
*/
bool full;
/**
* @brief type de mesure lue (T/H, W, D,...)
*
*/
String type;
/**
* @brief valeur a la quel la poubelle est considéré comme pleine
*
*/
String fullVall;
};
#endif // CAPTEUR_H

View File

@ -0,0 +1,17 @@
#include "../include/Capteur.h"
Capteur::Capteur(String type, String fullVall){
this->type = type;
this->fullVall = fullVall;
}
bool Capteur::tar(int val){
return true;
}
bool Capteur::isFull(){
return this->full;
}

View File

@ -38,6 +38,7 @@ monitor_flags =
lib_deps =
bportaluri/WiFiEsp@^2.2.2 ; gestion des commande 'AT' de l'esp01
arduino-libraries/Arduino_JSON@^0.2.0 ; gestion des json
ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son
; example:
; erropix/ESP32 AnalogWrite@^0.2

View File

@ -2,9 +2,23 @@
Program::Program(){
////////SERIALS//////
Serial1.begin(MONITOR_SPEED);
Serial.begin(MONITOR_SPEED);
////////API///////
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
//////CAPTEUR/////
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
}
void Program::loop(){
int distance = this->ultrasonic->read();
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");
}