add test call
This commit is contained in:
parent
347e788680
commit
908ca96c39
@ -1,7 +1,11 @@
|
||||
#ifndef PROGRAM_H
|
||||
#define PROGRAM_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
#include "DiscordAPI.h"
|
||||
|
||||
|
||||
class Program {
|
||||
public:
|
||||
@ -14,6 +18,9 @@ public:
|
||||
* Program main loop
|
||||
*/
|
||||
void loop();
|
||||
|
||||
private:
|
||||
DiscordAPI* discord;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
37
lib/DiscordAPI/include/DiscordAPI.h
Normal file
37
lib/DiscordAPI/include/DiscordAPI.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef DISCORD_API_H
|
||||
#define DISCORD_API_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiClientSecureBearSSL.h>
|
||||
|
||||
class DiscordAPI{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Discord API object
|
||||
* @param hookUrl url of the discord webhook
|
||||
*/
|
||||
DiscordAPI(String hookUrl);
|
||||
|
||||
bool sendMessage(String message);
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief webhook URL
|
||||
*/
|
||||
String hookUrl;
|
||||
|
||||
/**
|
||||
* @brief http client
|
||||
*
|
||||
*/
|
||||
HTTPClient* httpClient;
|
||||
|
||||
//WiFiClient* wifiClient;
|
||||
|
||||
BearSSL::WiFiClientSecure* wifiClient;
|
||||
};
|
||||
|
||||
|
||||
#endif //DISCORD_API_H
|
28
lib/DiscordAPI/src/DiscordAPI.cpp
Normal file
28
lib/DiscordAPI/src/DiscordAPI.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "../include/DiscordAPI.h"
|
||||
|
||||
DiscordAPI::DiscordAPI(String hookUrl){
|
||||
this->hookUrl = hookUrl;
|
||||
|
||||
this->httpClient = new HTTPClient();
|
||||
this->wifiClient = new BearSSL::WiFiClientSecure;
|
||||
this->wifiClient->setInsecure();
|
||||
}
|
||||
|
||||
bool DiscordAPI::sendMessage(String message){
|
||||
bool sortie = true;
|
||||
|
||||
//TODO: faire test si le wifi est bien connecter
|
||||
|
||||
|
||||
this->httpClient->begin(*this->wifiClient, this->hookUrl);
|
||||
this->httpClient->addHeader("Content-Type", "application/json");
|
||||
|
||||
int resp = this->httpClient->POST("{\"content\":\""+ message +"\"}");
|
||||
if(resp != 204){
|
||||
sortie = false;
|
||||
Serial.print("sending message error code : ");
|
||||
Serial.println(resp);
|
||||
}
|
||||
this->httpClient->end();
|
||||
return sortie;
|
||||
}
|
@ -3,6 +3,27 @@
|
||||
Program::Program() {
|
||||
// Startup
|
||||
Serial.begin(MONITOR_SPEED);
|
||||
|
||||
WiFi.begin(WSSID, PASS);
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
Serial.print(WSSID); Serial.println(" ...");
|
||||
|
||||
int i = 0;
|
||||
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
|
||||
delay(1000);
|
||||
Serial.print(++i); Serial.print(' ');
|
||||
}
|
||||
|
||||
Serial.println('\n');
|
||||
Serial.println("Connection established!");
|
||||
Serial.print("IP address:\t");
|
||||
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
|
||||
|
||||
|
||||
|
||||
this->discord = new DiscordAPI(DISCORD_HOOK);
|
||||
Serial.println(this->discord->sendMessage("hello the world !!"));
|
||||
}
|
||||
|
||||
void Program::loop() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user