Compare commits
24 Commits
feat/AR_Ar
...
69bd4f57e3
Author | SHA1 | Date | |
---|---|---|---|
69bd4f57e3 | |||
c40be321fb | |||
90b9ca279c | |||
17b344732f | |||
9b0b5bedd8 | |||
e088b4e304 | |||
b3da67f31e | |||
884169e745 | |||
36bdb86343 | |||
5784e38fbb | |||
9811022b76 | |||
a150d1c17f | |||
96ebd89dd3 | |||
370a16441b | |||
71a07cc552 | |||
b1787886c6 | |||
8928ab9922 | |||
9b6c1beb8d | |||
2fefc9f96d | |||
d63eff681e | |||
ca61a66ca6 | |||
3a37f93ef7 | |||
7b5d4a071b | |||
2e4b24df10 |
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>
|
@ -16,5 +16,16 @@ build_flags =
|
||||
|
||||
-D API_HOST=\"iot.epi.cb85.software\"
|
||||
|
||||
-D EXAMPLE_NUMBER=69
|
||||
-D ULTRA_SOUND_TRIGD=12
|
||||
-D ULTRA_SOUND_ECHO=13
|
||||
|
||||
-D POID_DOUT=14
|
||||
-D POID_SCK=15
|
||||
|
||||
-D MOYENNE_CALIBRATION=20
|
||||
|
||||
|
||||
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
|
||||
-D TRASHCAN_TWO=\"4brip5fwm001bs9\"
|
||||
|
||||
|
||||
|
@ -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]
|
||||
|
@ -1,6 +1,12 @@
|
||||
#ifndef PROGRAM_H
|
||||
#define PROGRAM_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Ultrasonic.h>
|
||||
|
||||
#include "API.h"
|
||||
#include "Balance.h"
|
||||
|
||||
class Program{
|
||||
public:
|
||||
/**
|
||||
@ -17,5 +23,24 @@ public:
|
||||
|
||||
private:
|
||||
/* data */
|
||||
|
||||
/**
|
||||
* @brief capteur ultra son pour le niveau de remplissage de la poubelle
|
||||
*
|
||||
*/
|
||||
Ultrasonic *ultrasonic;
|
||||
|
||||
/**
|
||||
* @brief capteur poid pour le niveau de remplissage de la poubelle
|
||||
*
|
||||
*/
|
||||
Balance *balance;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Réference de l'API pour les calls
|
||||
*
|
||||
*/
|
||||
API *api;
|
||||
};
|
||||
#endif
|
@ -41,8 +41,6 @@ public:
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
80
IOT/lib/Balance/include/Balance.h
Normal file
80
IOT/lib/Balance/include/Balance.h
Normal file
@ -0,0 +1,80 @@
|
||||
#ifndef BALANCE_H
|
||||
#define BALANCE_H
|
||||
#include <Arduino.h>
|
||||
#include <HX711.h>
|
||||
|
||||
class Balance {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief constructeur
|
||||
*
|
||||
* @param doutPin : pin DOUT du module HX711
|
||||
*
|
||||
* @param sckPin : pin horloge du module HX711
|
||||
*
|
||||
* @param poidsRef : valeur de poids posée sur la balance ref en grammes
|
||||
*/
|
||||
Balance(int doutPin, int sckPin);
|
||||
|
||||
/**
|
||||
* @brief determine le poids
|
||||
*
|
||||
* @return poids (double)
|
||||
*/
|
||||
double getValue();
|
||||
|
||||
/**
|
||||
* @brief determine la moyenne poids
|
||||
*
|
||||
* @param nbMesure : nombre de mesure effectues pour la moyenne
|
||||
*
|
||||
* @return moyenne poids (double)
|
||||
*/
|
||||
double getAverage(int nbMesure);
|
||||
|
||||
/**
|
||||
* @brief tare et scale a 0, et recuperation de la valeur brut du plateau
|
||||
*/
|
||||
boolean initCalibration();
|
||||
|
||||
/**
|
||||
* @brief initialisation du calibrage
|
||||
*
|
||||
* @param[in] poidsRef : poid de reférence pour la calibration
|
||||
* @param[in] moyenne_calibration : nombre de valeurs a lire pour une mesure
|
||||
*
|
||||
* @return renvoi un true si calibration bien effectue
|
||||
*/
|
||||
boolean calibration(int poidsRef,int moyenne_calibration);
|
||||
|
||||
//TODO: faire doc setCalibration fact
|
||||
void setCalibrationFact(int caliFact);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief true = calibration et false = erreur
|
||||
*/
|
||||
boolean initialized;
|
||||
|
||||
/**
|
||||
* @brief Facteur de calibration obtenu par : (val brute poids ref - val brute poids plexiglas)/ poids ref
|
||||
*/
|
||||
int calibrationFact;
|
||||
|
||||
/**
|
||||
* @brief Variable issue de la librairie HX711 qui permet d'utiliser les fonctions de celle-ci
|
||||
*/
|
||||
HX711 scale;
|
||||
|
||||
/**
|
||||
* @brief Valeur moyenne brute du poids sans rien sur la balance juste le plexiglas
|
||||
*/
|
||||
long initialVal;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
62
IOT/lib/Balance/src/Balance.cpp
Normal file
62
IOT/lib/Balance/src/Balance.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "../include/Balance.h"
|
||||
|
||||
Balance::Balance(int doutPin, int sckPin) {
|
||||
|
||||
scale.begin(doutPin, sckPin);
|
||||
this->initialized = false;
|
||||
scale.set_scale();
|
||||
scale.tare();
|
||||
this->initialVal = 0;
|
||||
this->calibrationFact = 0;
|
||||
}
|
||||
|
||||
boolean Balance::initCalibration() {
|
||||
|
||||
scale.set_scale();
|
||||
scale.tare();
|
||||
this->initialVal = scale.read_average(20);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean Balance::calibration(int poidsRef,int moyenne_calibration) {
|
||||
|
||||
int rawValref = 0; // Valeur brute de plexiglas et poids réf
|
||||
int tempPoids = 0; // C'est la valeur du poids en grammes calculée grâce au facteur de calibration
|
||||
|
||||
rawValref = scale.read_average(moyenne_calibration);
|
||||
this->calibrationFact = (rawValref - this->initialVal) / poidsRef;
|
||||
do {
|
||||
scale.set_scale(calibrationFact);
|
||||
tempPoids = scale.get_units(5);
|
||||
if (tempPoids < poidsRef) {
|
||||
calibrationFact -= 1;
|
||||
} else if (tempPoids > poidsRef) {
|
||||
calibrationFact += 1;
|
||||
}
|
||||
} while (tempPoids != poidsRef);
|
||||
return initialized = true;
|
||||
}
|
||||
|
||||
double Balance::getAverage(int nbMesure) {
|
||||
|
||||
if (initialized == true) {
|
||||
return scale.get_units(nbMesure);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
double Balance::getValue() {
|
||||
|
||||
if (initialized == true) {
|
||||
return scale.get_units();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Balance::setCalibrationFact(int caliFact){
|
||||
this->initialized = true;
|
||||
this->calibrationFact = caliFact;
|
||||
scale.set_scale(caliFact);
|
||||
}
|
@ -38,6 +38,8 @@ 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
|
||||
bogde/HX711@0.7.5 ; lib pour la balance
|
||||
; example:
|
||||
; erropix/ESP32 AnalogWrite@^0.2
|
||||
|
||||
|
@ -1,10 +1,34 @@
|
||||
#include "Program.h"
|
||||
|
||||
int distance;
|
||||
|
||||
|
||||
Program::Program(){
|
||||
Serial.begin(MONITOR_SPEED); //motitor pour debug
|
||||
Serial1.begin(MONITOR_SPEED); //port serie pour l'esp
|
||||
|
||||
///////INITIALISATION OBJ//////
|
||||
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
||||
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
|
||||
this->balance = new Balance(POID_DOUT,POID_SCK);
|
||||
///////INITIALISATION OK//////
|
||||
|
||||
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||
|
||||
Serial.print("start calibr : ");
|
||||
this->balance->initCalibration();
|
||||
Serial.println("OK");
|
||||
|
||||
this->balance->setCalibrationFact(1077);
|
||||
}
|
||||
|
||||
void Program::loop(){
|
||||
distance = this->ultrasonic->read();
|
||||
|
||||
|
||||
//this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false); //TODO: faire estimation poubelle plenne
|
||||
this->api->sendValue(this->balance->getValue(), TRASHCAN_TWO, ,false)
|
||||
Serial.print("Distance in CM: ");
|
||||
Serial.println(distance);
|
||||
delay(10000);
|
||||
}
|
@ -1,12 +1,47 @@
|
||||
#include <Arduino.h>
|
||||
#include "Program.h"
|
||||
#ifndef TESTING
|
||||
|
||||
Program* program;
|
||||
#include <Arduino.h>
|
||||
// #include "Program.h"
|
||||
|
||||
// Program* program;
|
||||
|
||||
// void setup() {
|
||||
// program = new Program();
|
||||
// }
|
||||
|
||||
// void loop() {
|
||||
// program->loop();
|
||||
// }
|
||||
|
||||
|
||||
#include "Balance.h"
|
||||
|
||||
Balance *balance;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(MONITOR_SPEED);
|
||||
balance = new Balance(14,15);
|
||||
|
||||
Serial.print("start calibr : ");
|
||||
balance->initCalibration();
|
||||
|
||||
Serial.println("OK");
|
||||
|
||||
// Serial.print("posé poids");
|
||||
// delay(5000);
|
||||
// Serial.println("OK");
|
||||
// balance->calibration(500, MOYENNE_CALIBRATION);
|
||||
// Serial.println("END calibration");
|
||||
|
||||
balance->setCalibrationFact(1077);
|
||||
|
||||
void setup() {
|
||||
program = new Program();
|
||||
program = new Program();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
program->loop();
|
||||
void loop(){
|
||||
// delay(500);
|
||||
Serial.println(balance->getValue());
|
||||
}
|
||||
|
||||
#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