Fixed QUIT messages not displaying, started mainlining gotify code

This commit is contained in:
Dionysus 2024-06-06 16:50:21 -04:00
parent 995529af02
commit a5e208755e
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
3 changed files with 43 additions and 52 deletions

View File

@ -1,34 +1,36 @@
#include <ArduinoWebsockets.h> #include "Gotify.h"
using namespace websockets;
WebsocketsClient gotifyClient; WebsocketsClient gotifyClient;
const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration
const char* gotify_token = "your_gotify_app_token"; const char* gotify_token = "your_gotify_app_token";
// Reconnection parameters
unsigned long lastAttemptTime = 0; unsigned long lastAttemptTime = 0;
const unsigned long reconnectInterval = 60000; // 1 minute const unsigned long reconnectInterval = 60000; // 1 minute
void onMessageCallback(WebsocketsMessage message) { void onMessageCallback(WebsocketsMessage message) {
Serial.println("Gotify Notification:"); Serial.println("Gotify Notification:");
Serial.println(message.data()); Serial.println(message.data());
playNotificationSound();
} }
void connectToGotify() { void connectToGotify() {
String url = String(gotify_server) + "?token=" + gotify_token; String url = String(gotify_server) + "?token=" + gotify_token;
gotifyClient.onMessage(onMessageCallback); gotifyClient.onMessage(onMessageCallback);
gotifyClient.connect(url); gotifyClient.connect(url);
if (gotifyClient.available()) { if (gotifyClient.available())
Serial.println("Connected to Gotify WebSocket"); Serial.println("Connected to Gotify WebSocket");
} else { else
Serial.println("Failed to connect to Gotify WebSocket"); Serial.println("Failed to connect to Gotify WebSocket");
}
} }
void checkGotifyWebSocket() {
void loopGotifyWebSocket() {
while (true) {
if (!gotifyClient.available()) { if (!gotifyClient.available()) {
unsigned long currentTime = millis(); unsigned long currentTime = millis();
if (currentTime - lastAttemptTime > reconnectInterval) { if (currentTime - lastAttemptTime > reconnectInterval) {
@ -39,4 +41,7 @@ void checkGotifyWebSocket() {
} else { } else {
gotifyClient.poll(); gotifyClient.poll();
} }
delay(10);
}
} }

17
src/Gotify.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <ArduinoWebsockets.h>
#include "Speaker.h"
using namespace websockets;
extern WebsocketsClient gotifyClient;
extern const char* gotify_server;
extern const char* gotify_token;
extern unsigned long lastAttemptTime;
extern const unsigned long reconnectInterval;
void onMessageCallback(WebsocketsMessage message);
void connectToGotify();
void loopGotifyWebSocket();

View File

@ -48,9 +48,6 @@ std::map<String, uint32_t> nickColors;
std::vector<String> lines; // Possible rename to bufferLines ? std::vector<String> lines; // Possible rename to bufferLines ?
std::vector<bool> mentions; std::vector<bool> mentions;
std::vector<WiFiNetwork> wifiNetworks; std::vector<WiFiNetwork> wifiNetworks;
// Global variables to cache preferences and buffers
String inputBuffer = ""; String inputBuffer = "";
// Leftover crack variables (will be removed when preferences are done) // Leftover crack variables (will be removed when preferences are done)
@ -232,7 +229,7 @@ void loop() {
if (readyToJoinChannel && millis() >= joinChannelTime) { if (readyToJoinChannel && millis() >= joinChannelTime) {
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
updateStatusBar(); updateStatusBar();
sendIRC("JOIN " + String(channel)); sendIRC("JOIN " + String(irc_channel));
readyToJoinChannel = false; readyToJoinChannel = false;
} }
@ -244,11 +241,10 @@ void loop() {
} }
// Handle inactivity timeout // Handle inactivity timeout
if (screenOn && millis() - lastActivityTime > INACTIVITY_TIMEOUT) { if (screenOn && millis() - lastActivityTime > INACTIVITY_TIMEOUT)
turnOffScreen(); turnOffScreen();
} }
} }
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -1169,7 +1165,7 @@ void parseAndDisplay(String line) {
} else if (command == "PART" && line.indexOf(channel) != -1) { } else if (command == "PART" && line.indexOf(channel) != -1) {
String senderNick = line.substring(1, line.indexOf('!')); String senderNick = line.substring(1, line.indexOf('!'));
addLine(senderNick, " has EMO-QUIT " + String(channel), "part"); addLine(senderNick, " has EMO-QUIT " + String(channel), "part");
} else if (command == "QUIT" && line.indexOf(channel) != -1) { } else if (command == "QUIT") {
String senderNick = line.substring(1, line.indexOf('!')); String senderNick = line.substring(1, line.indexOf('!'));
addLine(senderNick, "", "quit"); addLine(senderNick, "", "quit");
} else if (command == "NICK") { } else if (command == "NICK") {
@ -1287,7 +1283,6 @@ void updateStatusBar() {
uint16_t darkerGrey = tft.color565(25, 25, 25); uint16_t darkerGrey = tft.color565(25, 25, 25);
tft.fillRect(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT, darkerGrey); tft.fillRect(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT, darkerGrey);
// Display the time // Display the time
struct tm timeinfo; struct tm timeinfo;
char timeStr[9]; char timeStr[9];
@ -1415,30 +1410,4 @@ void printDeviceInfo() {
Serial.println(" Local IP: " + wifiLocalIP); Serial.println(" Local IP: " + wifiLocalIP);
Serial.println(" Gateway IP: " + wifiGatewayIP); Serial.println(" Gateway IP: " + wifiGatewayIP);
} }
// Display on TFT
tft.fillScreen(TFT_BLACK);
int line = 0;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("Chip ID: "); tft.setTextColor(TFT_WHITE); tft.println(String(chipId, HEX)); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("MAC Address: "); tft.setTextColor(TFT_WHITE); tft.println(macAddress); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print("Chip Info: "); tft.setTextColor(TFT_WHITE); tft.println(chipInfo); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("Battery: "); tft.setTextColor(TFT_WHITE); tft.println(""); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Pin Value: "); tft.setTextColor(TFT_WHITE); tft.println(analogRead(34)); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Avg Pin Val: "); tft.setTextColor(TFT_WHITE); tft.println(BL.pinRead()); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Volts: "); tft.setTextColor(TFT_WHITE); tft.println(BL.getBatteryVolts()); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Charge Level:"); tft.setTextColor(TFT_WHITE); tft.println(BL.getBatteryChargeLevel() + "%"); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("Memory: "); tft.setTextColor(TFT_WHITE); tft.println(""); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Flash: "); tft.setTextColor(TFT_WHITE); tft.println(flashInfo); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" PSRAM: "); tft.setTextColor(TFT_WHITE); tft.println(psramInfo); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Heap: "); tft.setTextColor(TFT_WHITE); tft.println(heapInfo); line++;
if (WiFi.status() == WL_CONNECTED) {
tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("WiFi Info: "); tft.setTextColor(TFT_WHITE); tft.println(""); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" SSID: "); tft.setTextColor(TFT_WHITE); tft.println(wifiSSID); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Channel: "); tft.setTextColor(TFT_WHITE); tft.println(wifiChannel); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Signal: "); tft.setTextColor(TFT_WHITE); tft.println(wifiSignal); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Local IP: "); tft.setTextColor(TFT_WHITE); tft.println(wifiLocalIP); line++;
tft.setCursor(0, line * 16); tft.setTextColor(TFT_YELLOW); tft.print(" Gateway IP: "); tft.setTextColor(TFT_WHITE); tft.println(wifiGatewayIP); line++;
} else {
tft.setCursor(0, line * 16); tft.setTextColor(TFT_CYAN); tft.print("WiFi Info: "); tft.setTextColor(TFT_WHITE); tft.println("Not connected"); line++;
}
} }