feat: Test_IOT #40
@ -21,3 +21,5 @@ build_flags =
|
|||||||
|
|
||||||
-D EXAMPLE_NUMBER=69
|
-D EXAMPLE_NUMBER=69
|
||||||
|
|
||||||
|
-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]
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Ultrasonic.h>
|
#include <Ultrasonic.h>
|
||||||
|
#include "API.h"
|
||||||
|
|
||||||
class Program{
|
class Program{
|
||||||
public:
|
public:
|
||||||
@ -26,5 +27,11 @@ private:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Ultrasonic *ultrasonic;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#include "Program.h"
|
#include "Program.h"
|
||||||
|
|
||||||
|
|
||||||
int distance;
|
int distance;
|
||||||
|
|
||||||
|
|
||||||
Program::Program(){
|
Program::Program(){
|
||||||
|
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
||||||
|
Serial1.begin(MONITOR_SPEED);
|
||||||
|
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||||
|
|
||||||
Serial.begin(MONITOR_SPEED);
|
Serial.begin(MONITOR_SPEED);
|
||||||
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
|
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
|
||||||
}
|
}
|
||||||
@ -12,7 +15,8 @@ Program::Program(){
|
|||||||
void Program::loop(){
|
void Program::loop(){
|
||||||
distance = this->ultrasonic->read();
|
distance = this->ultrasonic->read();
|
||||||
|
|
||||||
|
this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false);
|
||||||
Serial.print("Distance in CM: ");
|
Serial.print("Distance in CM: ");
|
||||||
Serial.println(distance);
|
Serial.println(distance);
|
||||||
delay(1000);
|
delay(10000);
|
||||||
}
|
}
|
@ -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");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user