Compare commits
No commits in common. "17b344732fd3c83bb7ac6ec7f0bf6f6bfccd545e" and "a150d1c17f6ab4c72a0e5f5c2b09260e05d4f74b" have entirely different histories.
17b344732f
...
a150d1c17f
@ -21,5 +21,3 @@ build_flags =
|
|||||||
|
|
||||||
-D EXAMPLE_NUMBER=69
|
-D EXAMPLE_NUMBER=69
|
||||||
|
|
||||||
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
|
|
||||||
|
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
; 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,7 +3,6 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Ultrasonic.h>
|
#include <Ultrasonic.h>
|
||||||
#include "API.h"
|
|
||||||
|
|
||||||
class Program{
|
class Program{
|
||||||
public:
|
public:
|
||||||
@ -27,11 +26,5 @@ private:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Ultrasonic *ultrasonic;
|
Ultrasonic *ultrasonic;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Réference de l'API pour les calls
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
API *api;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@ -41,6 +41,8 @@ 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
|
||||||
*
|
*
|
||||||
@ -49,11 +51,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool connect();
|
bool connect();
|
||||||
|
|
||||||
//TODO :: Check wifibegin avant
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ID de l'utilisateur
|
* @brief ID de l'utilisateur
|
||||||
*
|
*
|
||||||
|
@ -59,8 +59,7 @@ 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()) {
|
||||||
@ -78,10 +77,7 @@ 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,13 +1,10 @@
|
|||||||
#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);
|
||||||
}
|
}
|
||||||
@ -15,8 +12,7 @@ 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(10000);
|
delay(1000);
|
||||||
}
|
}
|
@ -1,16 +1,12 @@
|
|||||||
#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
|
|
@ -1,23 +0,0 @@
|
|||||||
#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() {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
#ifndef TEST_H
|
|
||||||
#define TEST_H
|
|
||||||
|
|
||||||
void TestWifiBeginConnected();
|
|
||||||
void TestWifiBeginNotConnected();
|
|
||||||
void TestConnectAPI();
|
|
||||||
void TestConnectAPIFailed();
|
|
||||||
void TestSendValue();
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,48 +0,0 @@
|
|||||||
#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