add test call

This commit is contained in:
2023-08-05 11:55:21 +02:00
parent 347e788680
commit 908ca96c39
4 changed files with 94 additions and 1 deletions

View 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

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