WiFiS3 incompatible with legacy Wifi libraries?

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
MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJ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N0yJV0ReFEQPaA1IwQvZW+cwdFD19Ae8zFnWSfda9J1
CZMRJCQUzym+5iPDuI9yP+kHyCREU3qzuWFloUwOxkgAyXVjBYdwRVKD05WdRerw
6DEdfgkfCv4+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"

Each board family has its own WiFi stack, and it is not surprising that libraries designed for ESP32 do not work on the Renesas.
This is not related to the fact that some libraries are old and others are new - the libraries simply depend on the architecture and therefore cannot be automatically transferred from one controller family to another.

Thank you for the quick reply. Yes, I guess "legacy" was the wrong word there. I'm new to the R4, it is not a new product.
I am beginning to understand how libraries are specific to different hardware and not universal to the IDE which is how I had been understanding what "arduino" is.

I have been unable to find equivalent libraries for the R4 of what is not working in the tutorial. Does this mean I am a bit out of luck? I am not well enough versed to know how to re-write the bits that arent working.

I tried the sketch you mentioned is the original. It compiles fine for an esp32 which it was designed for. If you want to change to an UNO R4 WiFi some changes are necessary.

Thank you, yes, that is why I am here. Do you know what changes might be necessary? I've found other threads here and on other websites discussing this issue, but no solutions.

The easiest solution is just to use the esp32 the sketch was designed for. If there is a compelling reason to switch to the Arduino R4 then you need to see what fails to compile and search through the available WiFi libraries for the right one. It's not something you need education or training for, it's simple legwork and cross checking. Spend a few hours or days yourself and if you can't sort it out come back. Do NOT look to the internet to give you a 'magic' solution, this is simply a case of doing the research.

Thanks for posting using <CODE/>. When there are separate files, please place them in their own block, and mention the file name, so that others may recreate the whole sketch more easily. In addition to the sketch .ino, it appears that there are three other files here

  • discord.h
  • discordCert.h
  • secrets.h

While the WiFi/HTTP stacks vary between boards, their concepts are broadly similar. I've never used WiFiMulti.h; I can guess from what little there is here, but it doesn't seem to buy you much when you use addAP just once. Many examples use plain WiFi.begin

There's a direct equivalent for TLS/SSL on R4, but no board-standard HTTP client. You can tell by looking at the examples, in the second section: "Examples for {your board}". ESP boards have both WiFi and HTTPClient categories; R4 has WiFiS3, which has WiFiWebClientSSL, exhibiting the equivalent header and client class. At the very top you'll see

  Board CA Root certificate bundle is embedded inside WiFi firmware:
  https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/main/certificates/cacrt_all.pem

If you follow that link, you'll see over 140 root certs. It turns out that the secure clients for both board platforms have a method named setCACert. But on R4, you often don't need to use it, including for discord.com. (That DISCORD_CERT is not a certificate in the current chain; and besides, it expired six weeks ago at the end of the year.)

For HTTP, I've had some success with ArduinoHttpClient. Looking just now, there's also a recent but limited one (GET and POST only) specifically for R4, R4HttpClient. You can examine their examples on GitHub. If you install both, you can instantiate those examples in the third Examples section: "Examples from Custom Libraries"

  • ArduinoHttpClient | PostWithHeaders
  • R4HttpClient | POST_request

The API for that second one is pretty close to ESP32 -- maybe intentionally. Never tried it, though.

I am asking about the R4 because that is what I have to work with. As I mentioned in my post, I have searched around and tried to pull this apart, but it is beyond my experience i this area to understand. I am continuing to read the documentation and learn, but I also know I am not the first person to encounter this issue and this forum often does have a "magic solution" which explains things very well. I am at a point where I dont know what I dont know and am looking for the direction of my next step. "[Just google it bro]" isn't a very useful reply and may be best left out of the conversation next time.

Thank you for this very helpful answer, I appreciate your time in replying to me. This gives me a lot to work with, a lot of phrases I never would have known to look for.

Ok, good luck.