Hi, I want to send a Pushover notification, I have a Nano 33 IoT device.
With the following code the notification is sent successfully:
// Libraries
#include <ArduinoHttpClient.h>
#include <ArduinoJson.h>
#include <WiFiNINA.h>
// Objects
WiFiSSLClient wifiSSL;
HttpClient client = HttpClient(wifiSSL, "api.pushover.net", 443);
// Setup
void setup() {
int wifi_status = WL_IDLE_STATUS;
wifi_status = WiFi.begin("ssid", "passphrase");
delay(10000); // wait 10 seconds for connection
if (wifi_status != WL_CONNECTED) {
while (true); // not continue
}
// Send notification
StaticJsonDocument<512> notification;
notification["token"] = "pushoverToken";
notification["user"] = "pushoverUser";
notification["message"] = "Notification";
String jsonStringNotification;
serializeJson(notification, jsonStringNotification);
client.post("/1/messages.json", "application/json", jsonStringNotification);
int statusCode = client.responseStatusCode();
String response = client.responseBody();
}
// Loop
void loop() {
}
The "client.post" comand is blocking for about 1,5 seconds, while the "client.responseBody()" takes about 1 second. These delays are important for a microcontroller (but still acceptable for my application), but the real issue is what happens if something goes wrong, for example if the server doesn't respond: in this scenario "client.post" takes about 10 seconds, and "client.responseBody()" takes about 30 seconds.
I attemped using the "Fetch" library, but it uses the transport WiFiClientSecure and not the WiFiSSLClient, so I can't compile the sketch.
I would rather use the ArduinoHttpClient library, I wonder if there is a way to use it in a non-blocking mode.
Any help or suggestion are welcome, thank you.