acid-drop

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README | LICENSE

gotify.cpp (1267B)

      1 #include <ArduinoWebsockets.h>
      2 
      3 using namespace websockets;
      4 
      5 WebsocketsClient gotifyClient;
      6 
      7 const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration
      8 const char* gotify_token = "your_gotify_app_token";
      9 
     10 // Reconnection parameters
     11 unsigned long lastAttemptTime = 0;
     12 const unsigned long reconnectInterval = 60000; // 1 minute
     13 
     14 void onMessageCallback(WebsocketsMessage message) {
     15     Serial.println("Gotify Notification:");
     16     Serial.println(message.data());
     17 }
     18 
     19 void connectToGotify() {
     20     String url = String(gotify_server) + "?token=" + gotify_token;
     21     gotifyClient.onMessage(onMessageCallback);
     22     gotifyClient.connect(url);
     23 
     24     if (gotifyClient.available()) {
     25         Serial.println("Connected to Gotify WebSocket");
     26     } else {
     27         Serial.println("Failed to connect to Gotify WebSocket");
     28     }
     29 }
     30 
     31 void checkGotifyWebSocket() {
     32     if (!gotifyClient.available()) {
     33         unsigned long currentTime = millis();
     34         if (currentTime - lastAttemptTime > reconnectInterval) {
     35             Serial.println("Attempting to reconnect to Gotify WebSocket...");
     36             lastAttemptTime = currentTime;
     37             connectToGotify();
     38         }
     39     } else {
     40         gotifyClient.poll();
     41     }
     42 }