36 Commits

Author SHA1 Message Date
9b6c1beb8d Merge remote-tracking branch 'origin/master' into feat/balance 2023-04-11 14:07:49 +02:00
9a77d3163f Merge pull request 'docs: Doxy-API-et-diagramme-API' (#25) from docs/Doxy-API-et-diagramme-API into master
Reviewed-on: https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811/pulls/25
Reviewed-by: nico <nicolas.sansd@gmail.com>
Reviewed-by: Guska <gildas.gonzalez@epitech.eu>
2023-04-11 13:53:42 +02:00
2fefc9f96d feat: test capteur poids OK 2023-04-11 12:54:53 +02:00
d63eff681e add Balance lib 2023-04-11 12:35:25 +02:00
ca61a66ca6 feat/ add lib HX711 2023-04-11 12:33:05 +02:00
3a37f93ef7 feat/add config 2023-04-11 12:32:49 +02:00
b921edd04b typo 2023-04-04 10:57:46 +02:00
62651ca606 docs(iot): create diagram class 2023-04-04 10:56:27 +02:00
aba69c8181 fix: doc and typo 2023-04-04 10:55:39 +02:00
ab94d9fbf3 fix: typo 2023-04-04 10:45:44 +02:00
70f18faee5 feat: doxyfile 2023-04-04 10:41:45 +02:00
a6abcd4fe1 Merge pull request 'feat(IOT): LibAPI' (#21) from feat/LibAPI into master
Reviewed-on: https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811/pulls/21
Reviewed-by: nico <nicolas.sansd@gmail.com>
2023-04-03 16:55:12 +02:00
4bde578c35 update config 2023-04-03 16:30:44 +02:00
60bb2911f4 remove(iot): test in main programme 2023-04-03 16:30:34 +02:00
97ae6c6977 docs(iot): documentation de la lib api client 2023-04-03 16:23:59 +02:00
789cab74a9 refactor(iot): change type of connect on api 2023-04-03 16:19:32 +02:00
59728b9694 feat(iot): API Client OK 2023-04-03 16:07:57 +02:00
7861cfae51 feat: connection OK 2023-04-03 12:06:39 +02:00
3208c2ff6b feat(WIP): test main API lib 2023-04-03 11:10:12 +02:00
89ecb3bf17 feat: commentaire 2023-04-03 11:09:44 +02:00
c57225c1f3 feat(iot): connection wifi and API *UNTESTED* 2023-03-28 17:28:55 +02:00
98e0342fe1 feat(iot): constructeur API 2023-03-28 16:05:36 +02:00
bcfe0a07f8 Merge pull request 'feat: CAO link in readme' (#22) from clement-patch-1 into master
Reviewed-on: https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811/pulls/22
2023-03-28 07:39:17 +00:00
ad524cfc68 feat: CAO link in readme 2023-03-28 07:38:39 +00:00
e8ebe48128 feat: init api lib 2023-03-27 17:42:17 +02:00
31dfa751a3 feat: add deps 2023-03-27 17:41:53 +02:00
e56b92aa7b Merge pull request 'docs/diagram-API' (#10) from docs/diagram-API into master
Reviewed-on: https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811/pulls/10
Reviewed-by: MDeghaud <michel.deghaud@epitech.eu>
Reviewed-by: nico <nicolas.sansd@gmail.com>
2023-03-21 11:03:46 +00:00
d2a89b5a2c fix: rm useless field 2023-03-21 12:02:15 +01:00
c5576c2c63 fix: rename iot folder to IOT 2023-03-21 11:58:57 +01:00
ab70befc0c fix little issue on API diagram 2023-03-21 11:42:48 +01:00
2e40495cc1 class data 2023-03-21 09:56:42 +01:00
2b91951a27 docs: mouve api diagram to rigt place 2023-03-20 12:57:41 +01:00
d6c473982e folders api/docs 2023-03-20 12:11:46 +01:00
25c5dd0b82 relation 2023-03-20 11:56:10 +01:00
94aad21613 relation and primary key 2023-03-20 11:06:45 +01:00
65b0befcc0 implémentation du diagramme de séquence 2023-03-20 10:03:46 +01:00
14 changed files with 3209 additions and 10 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
IOT/docs/doxygen output/*

29
API/docs/diagram.wsd Normal file
View File

@ -0,0 +1,29 @@
@startuml diagram
class users {
id: text
username: text
email: email
name: text
image: file
created: date
updated: date
}
class trashs{
id: text
value: text
author: users
created: date
updated: date
}
class data {
id: text
value: number
poubelle_id: trashs
unit: text
status: bool
created: date
updated: date
}
users "1" <-- trashs
trashs "1" <-- data
@enduml

6
IOT/README.md Normal file
View File

@ -0,0 +1,6 @@
#IOT:
## setup :
rename `secrets.ini.example` to `secrets.ini`

View File

@ -14,6 +14,8 @@ build_flags =
-D MONITOR_SPEED=${config.monitor_speed} -D MONITOR_SPEED=${config.monitor_speed}
; DO NOT TOUCH --- END ; DO NOT TOUCH --- END
-D EXAMPLE_NUMBER=69 -D API_HOST=\"iot.epi.cb85.software\"
-D MOYENNE_CALIBRATION=20
-D EXAMPLE_STRING=\"Pouet\"

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

94
IOT/lib/API/include/API.h Normal file
View File

@ -0,0 +1,94 @@
#ifndef API_H
#define API_H
#include <Arduino_JSON.h>
#include <WiFiEsp.h>
class API {
public:
/**
* @brief Construit un nouvelle objet API
*
* @param[in] user nom de l'utilisateur de l'API
* @param[in] password mot de passe de l'utilisateur
* @param[in] host address de l'api
* @param[in] https l'address de l'api est en https *(defaut `true`)*
*/
API(String user, String password, String host, bool https = true);
/**
* @brief Initialise la connection Wifi de l'esp
*
* @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);
/**
* @brief envoie la valeur d'un capteur de poubelle à l'api
*
* @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 sendValue(String val, String poubelleID, String unit, bool full);
private:
/**
* @brief connect l'utilisateur a l'api et met a jour le token
*
* @return true l'utilisateur est bien connecter
* @return false erreur lors de la connexion de l'utilisateur
*/
bool connect();
/**
* @brief ID de l'utilisateur
*
*/
String user;
/**
* @brief mdp de l'utilisateur
*
*/
String password;
/**
* @brief adresse du serveur API
*
*/
String serveurHost;
/**
* @brief true = serveur en https (443)
*
*/
bool https;
/**
* @brief client http
*
*/
WiFiEspClient* client;
/**
* @brief token de connexion du client (vide = deconnecter)
*
*/
String token;
};
#endif

120
IOT/lib/API/src/API.cpp Normal file
View File

@ -0,0 +1,120 @@
#include "../include/API.h"
API::API(String user, String password, String host, bool https){
this->user = user;
this->password = password;
this->serveurHost = host;
this->https = https;
this->token = "";
this->client = new WiFiEspClient();
}
bool API::wifiBegin(String wifiId, String wifiPass, Stream* espSerial){
WiFi.init(espSerial);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present"); // FIXME: rm debug
return false;
}
// attempt to connect to WiFi network
int status = WL_IDLE_STATUS; // the Wifi radio's status
while (status != WL_CONNECTED) {
status = WiFi.begin(wifiId.c_str(), wifiPass.c_str());
}
return true;
}
bool API::connect(){
this->client->stop();
bool sortie = false;
JSONVar data;
data["identity"] = this->user;
data["password"] = this->password;
String strData = JSONVar::stringify(data);
if(this->https){
if (!this->client->connectSSL(this->serveurHost.c_str(), 443)) {
Serial.println("NOT Connected to server");
return sortie;
}
}else{
if (!this->client->connectSSL(("http://" + this->serveurHost).c_str(), 80)) {
Serial.println("NOT Connected to server");
return sortie;
}
}
this->client->println("POST /api/collections/users/auth-with-password HTTP/1.1");
this->client->println("Host: " + this->serveurHost);
this->client->println("Content-Type: application/json");
this->client->println("Content-Length: " + String(strData.length()));
this->client->println();
this->client->println(strData);
this->client->println("Connection: close");
this->client->println();
while (!client->available()) {}
String responce = "";
while (client->available()) {
responce += (char)client->read();
}
String str = responce.substring(responce.indexOf("{"),responce.lastIndexOf("}")+1);
JSONVar jsonRes = new JSONVar(JSONVar::parse(str));
this->token = JSONVar::stringify(jsonRes["token"]);
this->token = this->token.substring(1,this->token.length()-1);
this->client->stop();
sortie = true;
return sortie;
}
bool API::sendValue(String val, String poubelleID, String valUnit, bool full){
JSONVar data;
data["value"] = val;
data["trash_id"] = poubelleID;
data["unit"] = valUnit;
data["status"] = full;
String strData = JSONVar::stringify(data);
if(this->token == ""){
bool connected = this->connect();
if(!connected)return false;
}
if(this->https){
if (!this->client->connectSSL(("https://" + this->serveurHost).c_str(), 443)) {
Serial.println("NOT Connected to server");
return false;
}
}else{
if (!this->client->connectSSL(("http://" + this->serveurHost).c_str(), 80)) {
Serial.println("NOT Connected to server");
return false;
}
}
this->client->println("POST /api/collections/data/records HTTP/1.1");
this->client->println("Host: " + this->serveurHost);
this->client->println("Content-Type: application/json");
this->client->println("Content-Length: " + String(strData.length()));
this->client->println("Authorization: Bearer " + this->token);
this->client->println();
this->client->print(strData);
this->client->println("Connection: close");
this->client->println();
this->token = "";//XXX: on rm le token a chaque fois car on sais pas si la requet a bien aboutie et donc si il y est encore bon
return true;
}

View 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

View 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);
}

View File

@ -36,6 +36,9 @@ monitor_flags =
; librairies ; librairies
lib_deps = lib_deps =
bportaluri/WiFiEsp@^2.2.2 ; gestion des commande 'AT' de l'esp01
arduino-libraries/Arduino_JSON@^0.2.0 ; gestion des json
bogde/HX711@0.7.5 ; lib pour la balance
; example: ; example:
; erropix/ESP32 AnalogWrite@^0.2 ; erropix/ESP32 AnalogWrite@^0.2

View File

@ -3,4 +3,10 @@
; To be able to reproduce it ; To be able to reproduce it
[secrets] [secrets]
build_flags = build_flags =
-D WIFI_SSID=\"...\"
-D WIFI_PASSWORD=\"...\"4
-D USER_NAME=\"...\"
-D USER_PASSWORD=\"...\"

View File

@ -1,12 +1,41 @@
#include <Arduino.h> #include <Arduino.h>
#include "Program.h" // #include "Program.h"
Program* program; // 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();
} }
void loop() { void loop(){
program->loop(); // delay(500);
Serial.println(balance->getValue());
} }

View File

@ -1,4 +1,7 @@
# Depot IOT VR # Depot IOT VR
Lien du Gitea : (depot principale + gestion de projet) Lien du Gitea : (depot principale + gestion de projet)
https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811 https://gitea.cb85.software/Epitech-T-DEV-811/T-DEV-811
Lien de la CAO : https://cad.onshape.com/documents/d370ee863400195afb23d026/w/1a94981b6a6f71d70b075e30/e/d0feb75fc5a122c54598349b?renderMode=0&uiState=6422993bab4d903a51186392