acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Gotify.cpp (1306B)
1 #include "Gotify.h" 2 3 4 WebsocketsClient gotifyClient; 5 6 const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration 7 const char* gotify_token = "your_gotify_app_token"; 8 9 unsigned long lastAttemptTime = 0; 10 const unsigned long reconnectInterval = 60000; // 1 minute 11 12 13 void onMessageCallback(WebsocketsMessage message) { 14 Serial.println("Gotify Notification:"); 15 Serial.println(message.data()); 16 playNotificationSound(); 17 } 18 19 20 void connectToGotify() { 21 String url = String(gotify_server) + "?token=" + gotify_token; 22 gotifyClient.onMessage(onMessageCallback); 23 gotifyClient.connect(url); 24 25 if (gotifyClient.available()) 26 Serial.println("Connected to Gotify WebSocket"); 27 else 28 Serial.println("Failed to connect to Gotify WebSocket"); 29 } 30 31 32 void loopGotifyWebSocket() { 33 while (true) { 34 if (!gotifyClient.available()) { 35 unsigned long currentTime = millis(); 36 if (currentTime - lastAttemptTime > reconnectInterval) { 37 Serial.println("Attempting to reconnect to Gotify WebSocket..."); 38 lastAttemptTime = currentTime; 39 connectToGotify(); 40 } 41 } else { 42 gotifyClient.poll(); 43 } 44 45 delay(10); 46 } 47 }