Compare commits
20 Commits
AR_Michel
...
b26a27dc5b
Author | SHA1 | Date | |
---|---|---|---|
b26a27dc5b | |||
fa6662e885 | |||
a47ec78e1c | |||
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,11 @@
|
|||||||
#ifndef PROGRAM_H
|
#ifndef PROGRAM_H
|
||||||
#define PROGRAM_H
|
#define PROGRAM_H
|
||||||
|
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Ultrasonic.h>
|
||||||
|
#include "API.h"
|
||||||
|
|
||||||
class Program{
|
class Program{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -17,5 +22,23 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/* data */
|
/* data */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief capteur humi/temp
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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
|
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -1,10 +1,31 @@
|
|||||||
#include "Program.h"
|
#include "Program.h"
|
||||||
|
|
||||||
|
int distance;
|
||||||
|
|
||||||
|
|
||||||
Program::Program(){
|
Program::Program(){
|
||||||
|
Serial1.begin(MONITOR_SPEED);
|
||||||
|
Serial.begin(MONITOR_SPEED);
|
||||||
|
|
||||||
|
// INIT OBJ
|
||||||
|
this->dht = new DHT(DHTPIN, DHTTYPE);
|
||||||
|
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(){
|
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())+" %");
|
||||||
|
|
||||||
|
//this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false);
|
||||||
|
Serial.print("Distance in CM: ");
|
||||||
|
Serial.println(distance);
|
||||||
|
delay(1000);
|
||||||
}
|
}
|
@ -1,12 +1,16 @@
|
|||||||
|
#ifndef TESTING
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "Program.h"
|
#include "Program.h"
|
||||||
|
|
||||||
Program* program;
|
Program* program;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
program = new Program();
|
program = new Program();
|
||||||
}
|
}
|
||||||
|
|
||||||
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