Compare commits
33 Commits
AR_Michel
...
c89b6d1479
Author | SHA1 | Date | |
---|---|---|---|
c89b6d1479 | |||
d67e4a9da8 | |||
cc583d0947 | |||
60ec85a572 | |||
b26a27dc5b | |||
fa6662e885 | |||
a47ec78e1c | |||
7b0d866d6f | |||
db3ce5025b | |||
f01844bed8 | |||
e002adacdd | |||
a533973e9c | |||
aed8706921 | |||
e8b420f3f7 | |||
5b7f0f3d3e | |||
4cafc40d61 | |||
17b344732f | |||
9b0b5bedd8 | |||
e088b4e304 | |||
b3da67f31e | |||
884169e745 | |||
36bdb86343 | |||
5784e38fbb | |||
9811022b76 | |||
a150d1c17f | |||
96ebd89dd3 | |||
370a16441b | |||
71a07cc552 | |||
b1787886c6 | |||
8928ab9922 | |||
7b5d4a071b | |||
2e4b24df10 | |||
b1728b0509 |
18
IOT/config.cppcheck
Normal file
18
IOT/config.cppcheck
Normal 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>
|
@ -14,7 +14,19 @@ build_flags =
|
|||||||
-D MONITOR_SPEED=${config.monitor_speed}
|
-D MONITOR_SPEED=${config.monitor_speed}
|
||||||
; DO NOT TOUCH --- END
|
; DO NOT TOUCH --- END
|
||||||
|
|
||||||
|
; DHT pin and type
|
||||||
|
; 5v
|
||||||
|
-D DHTTYPE=\"DHT11\"
|
||||||
|
-D DHTPIN=2
|
||||||
|
|
||||||
|
; ULTRASON pin
|
||||||
|
; 5v
|
||||||
|
-D ULTRA_SOUND_TRIGD=12
|
||||||
|
-D ULTRA_SOUND_ECHO=13
|
||||||
|
|
||||||
|
; API host url
|
||||||
-D API_HOST=\"iot.epi.cb85.software\"
|
-D API_HOST=\"iot.epi.cb85.software\"
|
||||||
|
|
||||||
-D EXAMPLE_NUMBER=69
|
; trash can ID
|
||||||
|
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
|
||||||
|
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
; Add additionnal environments in this file
|
; 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
|
; Default production environment
|
||||||
[env:prod]
|
[env:prod]
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
#ifndef PROGRAM_H
|
#ifndef PROGRAM_H
|
||||||
#define PROGRAM_H
|
#define PROGRAM_H
|
||||||
|
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Ultrasonic.h>
|
||||||
|
#include "API.h"
|
||||||
|
#include "Capteur.h"
|
||||||
|
#include "Ultrason.h"
|
||||||
|
|
||||||
class Program{
|
class Program{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -17,5 +24,23 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/* data */
|
/* data */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief capteur humi/temp
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
DHT *dht;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief capteur ultra son pour le niveau de remplissage de la poubelle
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Capteur *ultrasonic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Réference de l'API pour les calls
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
API *api;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@ -41,8 +41,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool sendValue(String val, String poubelleID, String unit, bool full);
|
bool sendValue(String val, String poubelleID, String unit, bool full);
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
/**
|
||||||
* @brief connect l'utilisateur a l'api et met a jour le token
|
* @brief connect l'utilisateur a l'api et met a jour le token
|
||||||
*
|
*
|
||||||
@ -51,6 +49,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool connect();
|
bool connect();
|
||||||
|
|
||||||
|
//TODO :: Check wifibegin avant
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ID de l'utilisateur
|
* @brief ID de l'utilisateur
|
||||||
*
|
*
|
||||||
|
@ -59,7 +59,8 @@ bool API::connect(){
|
|||||||
this->client->println();
|
this->client->println();
|
||||||
|
|
||||||
|
|
||||||
while (!client->available()) {}
|
while (!client->available()) {
|
||||||
|
}
|
||||||
|
|
||||||
String responce = "";
|
String responce = "";
|
||||||
while (client->available()) {
|
while (client->available()) {
|
||||||
@ -77,7 +78,10 @@ bool API::connect(){
|
|||||||
this->client->stop();
|
this->client->stop();
|
||||||
|
|
||||||
sortie = true;
|
sortie = true;
|
||||||
|
if (JSONVar::stringify(JSONVar::parse(str)["code"]) == "400") {
|
||||||
|
Serial.println("Failed to authenticate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return sortie;
|
return sortie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
67
IOT/lib/Capteur/include/Capteur.h
Normal file
67
IOT/lib/Capteur/include/Capteur.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#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
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
|
||||||
|
String getValType();
|
||||||
|
|
||||||
|
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
|
34
IOT/lib/Capteur/include/HumiTemp.h
Normal file
34
IOT/lib/Capteur/include/HumiTemp.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef HUMI_TEMP_H
|
||||||
|
#define HUMI_TEMP_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include "Capteur.h"
|
||||||
|
|
||||||
|
class HumiTemp : public Capteur{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Humi Temp object
|
||||||
|
*
|
||||||
|
* @param pin pin du capteur dht
|
||||||
|
* @param type type de capteur dht (11,22,...)
|
||||||
|
* @param fullVal valeur au quel la poubelle est considéré comme pleinne
|
||||||
|
*/
|
||||||
|
HumiTemp(int pin, String type, String fullVall);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief lit le capteur d'humi/temp
|
||||||
|
*
|
||||||
|
* @return String valeur format "XX/YY" X% et Y°C
|
||||||
|
*/
|
||||||
|
String read();
|
||||||
|
private:
|
||||||
|
|
||||||
|
DHT* capteur;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //HUMI_TEMP_H
|
38
IOT/lib/Capteur/include/Ultrason.h
Normal file
38
IOT/lib/Capteur/include/Ultrason.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef ULTRASON_H
|
||||||
|
#define ULTRASON_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Ultrasonic.h>
|
||||||
|
|
||||||
|
#include "Capteur.h"
|
||||||
|
|
||||||
|
class Ultrason: public Capteur{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Ultrason object
|
||||||
|
*
|
||||||
|
* @param trigeur pin trigeur du capteur ultra son
|
||||||
|
* @param echo pin echo du capteur ultra son
|
||||||
|
* @param fullVall valeur a la quel la poubelle est pleine
|
||||||
|
*/
|
||||||
|
Ultrason(int trigeur, int echo, String fullVall);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief lit la valeur du capteur ultra son
|
||||||
|
*
|
||||||
|
* @return String retour la valeur
|
||||||
|
*/
|
||||||
|
String read();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief capteur utiliser ultrason utiliser pour la mesure
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Ultrasonic* capteur;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ULTRASON_H
|
22
IOT/lib/Capteur/src/Capteur.cpp
Normal file
22
IOT/lib/Capteur/src/Capteur.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String Capteur::getValType(){
|
||||||
|
return this->type;
|
||||||
|
}
|
27
IOT/lib/Capteur/src/HumiTemp.cpp
Normal file
27
IOT/lib/Capteur/src/HumiTemp.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "../include/HumiTemp.h"
|
||||||
|
|
||||||
|
|
||||||
|
HumiTemp::HumiTemp(int pin, String type, String fullVall):
|
||||||
|
Capteur("H/T",fullVall){
|
||||||
|
this->capteur = new DHT(pin,type);
|
||||||
|
this->capteur->begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
String HumiTemp::read(){
|
||||||
|
String sortie = "";
|
||||||
|
int hum = this->capteur->readHumidity(true);
|
||||||
|
int temp = this->capteur->readTemperature(false,true);
|
||||||
|
|
||||||
|
//valeur pour un élevage d'astico de pèche selon chatGPT
|
||||||
|
if((temp > 20 && temp < 30) && (hum > 60 && hum < 80)){
|
||||||
|
this->full = true;
|
||||||
|
}else{
|
||||||
|
this->full = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sortie += String(hum);
|
||||||
|
sortie += "/";
|
||||||
|
sortie += String(temp);
|
||||||
|
return sortie;
|
||||||
|
}
|
||||||
|
//TODO: faire en soirte qu'il y ai un nombre de cycle pour l'aparition d'asticots (entre 1 et 3 jours)
|
19
IOT/lib/Capteur/src/Ultrason.cpp
Normal file
19
IOT/lib/Capteur/src/Ultrason.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "../include/Ultrason.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ultrason::Ultrason(int trigeur, int echo, String fullVall):
|
||||||
|
Capteur("D",fullVall){
|
||||||
|
this->capteur = new Ultrasonic(trigeur, echo);
|
||||||
|
}
|
||||||
|
|
||||||
|
String Ultrason::read(){
|
||||||
|
int sortie = this->capteur->read();
|
||||||
|
if (sortie < this->fullVall.toInt())
|
||||||
|
{
|
||||||
|
this->full = true;
|
||||||
|
}else{
|
||||||
|
this->full = false;
|
||||||
|
}
|
||||||
|
return String(sortie);
|
||||||
|
}//TODO: faire en sorte que full se reset avec une autre val
|
@ -38,6 +38,9 @@ monitor_flags =
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
bportaluri/WiFiEsp@^2.2.2 ; gestion des commande 'AT' de l'esp01
|
bportaluri/WiFiEsp@^2.2.2 ; gestion des commande 'AT' de l'esp01
|
||||||
arduino-libraries/Arduino_JSON@^0.2.0 ; gestion des json
|
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:
|
; example:
|
||||||
; erropix/ESP32 AnalogWrite@^0.2
|
; erropix/ESP32 AnalogWrite@^0.2
|
||||||
|
|
||||||
|
@ -2,9 +2,33 @@
|
|||||||
|
|
||||||
|
|
||||||
Program::Program(){
|
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->dht = new DHT(DHTPIN, DHTTYPE);
|
||||||
|
dht->begin();
|
||||||
|
this->ultrasonic = new Ultrason(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO, String(10));//TODO: mettre la valeur en config
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::loop(){
|
void Program::loop(){
|
||||||
|
String 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())+" %");
|
||||||
|
|
||||||
|
//this->api->sendValue(distance, TRASHCAN_ONE, this->ultrasonic->getValType(), this->ultrasonic->isFull());
|
||||||
|
Serial.print("Distance in CM: ");
|
||||||
|
Serial.print(distance);
|
||||||
|
Serial.println(this->ultrasonic->isFull()?" true":" false");
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
#ifndef TESTING
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "Program.h"
|
#include "Program.h"
|
||||||
|
|
||||||
@ -10,3 +12,5 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
program->loop();
|
program->loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
23
IOT/test/main.cpp
Normal file
23
IOT/test/main.cpp
Normal 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
10
IOT/test/test.h
Normal 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
48
IOT/test/test_api.cpp
Normal 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");
|
||||||
|
}
|
Reference in New Issue
Block a user