Hello, I am attempting to follow this tutorial using an Uno R4 Wifi: Send Messages to Discord from ESP32 with Discord Webhooks.
As far as I've been able to tell from searching around is that that the libraries used (WiFi.h, WiFiMulti.h, HTTPClient.h, WiFiClientSecure.h) are not compatible with the Renesas boards. The WiFiS3.h library doesn't sufficiently replace the libraries used in the tutorial.
(I know the WiFi.h library is used for the WiFi shield, but I'm including it here becuase it is in the tutorial. I replaced WiFi.h with WiFiS3.h and then WiFiMulti and HTTPClient or HttpClient became the issue.)
What is the work around here? Thank you for any advice.
Here is an example error message, with similar ones for the other libraries
In file included from /Users/XXXXXXXX/Documents/Arduino/discord/discord.ino:2:0:
/Users/xxxxxxxxx/Documents/Arduino/discord/discord.h:2:10: fatal error: WiFiMulti.h: No such file or directory
#include <WiFiMulti.h>
^~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: WiFiMulti.h: No such file or directory
Here is the complete code from the tutorial:
#include "secrets.h"
#include "discord.h"
String message = "This is a simple message!";
String embedJson = R"({
"author": {
"name": "Birdie♫",
"url": "https://www.reddit.com/r/cats/",
"icon_url": "https://picsum.photos/200"
},
"title": "Title lorem ipsum something very nice",
"url": "https://google.com/",
"description": "Text message. You can use Markdown here. *Italic* **bold** __underline__ ~~strikeout~~ [hyperlink](https://google.com) `code`",
"color": 15258703,
"fields": [
{
"name": "Text",
"value": "More text",
"inline": true
},
{
"name": "Even more text",
"value": "Yup",
"inline": true
},
{
"name": "Use `\"inline\": true` parameter, if you want to display fields in the same line.",
"value": "okay..."
},
{
"name": "Thanks!",
"value": "You're welcome :wink:"
}
],
"thumbnail": {
"url": "https://picsum.photos/600"
},
"image": {
"url": "https://picsum.photos/1200/600"
},
"footer": {
"text": "Woah! So cool! :smirk:",
"icon_url": "https://picsum.photos/200"
}
})";
void setup() {
Serial.begin(9600);
connectWIFI();
//sendDiscordMessage(message);
//sendDiscordEmbeds(embedJson);
sendDiscord(message, embedJson);
}
void loop() {
}
discord.h
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include "discordCert.h"
const char ssid[] = WIFI_SSID;
const char pass[] = WIFI_PASS;
const String discord_webhook = DISCORD_WEBHOOK;
const String discord_tts = DISCORD_TTS;
WiFiMulti WiFiMulti;
void connectWIFI() {
WiFiMulti.addAP(ssid, pass);
WiFi.mode(WIFI_STA);
while ((WiFiMulti.run() != WL_CONNECTED)) {
Serial.print(".");
}
Serial.println("WiFi Connected");
}
void sendDiscord(String content, String embedJson) {
WiFiClientSecure *client = new WiFiClientSecure;
if (client) {
client -> setCACert(DISCORD_CERT);
{
HTTPClient https;
if (https.begin(*client, discord_webhook)) {
https.addHeader("Content-Type", "application/json");
Serial.println("Before payload");
String jsonPayload = "{\"content\":\"" + content + "\",\"tts\":" + discord_tts + ",\"embeds\": [" + embedJson + "]}";
int httpCode = https.POST(jsonPayload);
Serial.println("after POST");
if (httpCode > 0) {
Serial.println(httpCode);
Serial.println(https.getString());
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.print("HTTP Response: ");
Serial.println(payload);
}
} else {
Serial.print("HTTP Post failed: ");
Serial.println(https.errorToString(httpCode).c_str());
}
https.end();
}
}
delete client;
}
}
void sendDiscordMessage(String content) {
sendDiscord(content, "");
}
void sendDiscordEmbeds(String embeds) {
sendDiscord("", embeds);
}
discordCert.h
/*
* Get current discordapp.com certificate:
* openssl s_client -showcerts -connect discordapp.com:443
*/
const char* DISCORD_CERT = R"(
-----BEGIN CERTIFICATE-----
MIIDzTCCArWgAwIBAgIQCjeHZF5ftIwiTv0b7RQMPDANBgkqhkiG9w0BAQsFADBa
MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl
clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTIw
MDEyNzEyNDgwOFoXDTI0MTIzMTIzNTk1OVowSjELMAkGA1UEB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kfCv4+3ao8XnTSrLE=
-----END CERTIFICATE-----
)";
secrets.h
#define WIFI_SSID "XXX"
#define WIFI_PASS "XXXX"
#define DISCORD_WEBHOOK "https://discord.com/api/webhooks/##############/"
#define DISCORD_TTS "false"