#include #include "features.h" #include #include #include #include //#include //#include #include #include #include #include #include #include #include #include #include #include #include "version.h" #include "geteph.h" #include "rs92gps.h" #if FEATURE_MQTT #include "mqtt.h" #endif #include "esp_heap_caps.h" //#define ESP_MEM_DEBUG 1 int e; enum MainState { ST_DECODER, ST_SPECTRUM, ST_WIFISCAN, ST_UPDATE, ST_TOUCHCALIB }; static MainState mainState = ST_WIFISCAN; // ST_WIFISCAN; const char *mainStateStr[5] = {"DECODER", "SPECTRUM", "WIFISCAN", "UPDATE", "TOUCHCALIB" }; AsyncWebServer server(80); AXP20X_Class axp; #define PMU_IRQ 35 SemaphoreHandle_t axpSemaphore; bool pmu_irq = false; String updateHost = "rdzsonde.mooo.com"; int updatePort = 80; String updateBinM = "/master/update.ino.bin"; String updateBinD = "/devel/update.ino.bin"; String *updateBin = &updateBinM; #define LOCALUDPPORT 9002 //Get real UTC time from NTP server const char* ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 0; //UTC const int daylightOffset_sec = 0; //UTC boolean connected = false; WiFiUDP udp; WiFiClient client; #if FEATURE_SONDEHUB #define SONDEHUB_STATION_UPDATE_TIME (60*60*1000) // 60 min #define SONDEHUB_MOBILE_STATION_UPDATE_TIME (30*1000) // 30 sec WiFiClient shclient; // Sondehub v2 unsigned long time_last_update = 0; /* SH_LOC_OFF: never send position information to SondeHub SH_LOC_FIXED: send fixed position (if specified in config) or GPS position (if there is a GPS fix) as fixed station position (no chase mode) to sondehub SH_LOC_CHASE: always activate chase mode and send GPS position (if available) SH_LOC_AUTO: if there is no valid GPS position, or GPS position < MIN_LOC_AUTO_DIST away from known fixed position: use FIXED mode otherwise, i.e. if there is a valid GPS position and (either no fixed position in config, or GPS position is far away from fixed position), use CHASE mode. */ enum { SH_LOC_OFF, SH_LOC_FIXED, SH_LOC_CHASE, SH_LOC_AUTO }; /* auto mode is chase if valid GPS position and (no fixed location entered OR valid GPS position and distance in lat/lon deg to fixed location > threshold) */ #define MIN_LOC_AUTO_DIST 200 /* meter */ #define SH_LOC_AUTO_IS_CHASE ( gpsPos.valid && ( (isnan(sonde.config.sondehub.lat) || isnan(sonde.config.sondehub.lon) ) || \ calcLatLonDist( gpsPos.lat, gpsPos.lon, sonde.config.sondehub.lat, sonde.config.sondehub.lon ) > MIN_LOC_AUTO_DIST ) ) #endif extern float calcLatLonDist(float lat1, float lon1, float lat2, float lon2); // KISS over TCP for communicating with APRSdroid WiFiServer tncserver(14580); WiFiClient tncclient; // JSON over TCP for communicating with my kotlin andoird test stuff WiFiServer rdzserver(14570); WiFiClient rdzclient; #if FEATURE_MQTT unsigned long lastMqttUptime = 0; boolean mqttEnabled; MQTT mqttclient; #endif boolean forceReloadScreenConfig = false; enum KeyPress { KP_NONE = 0, KP_SHORT, KP_DOUBLE, KP_MID, KP_LONG }; // "doublepress" is now also used to eliminate key glitch on TTGO T-Beam startup (SENSOR_VN/GPIO39) struct Button { uint8_t pin; uint32_t numberKeyPresses; KeyPress pressed; unsigned long keydownTime; int8_t doublepress; bool isTouched; }; Button button1 = {0, 0, KP_NONE, 0, -1, false}; Button button2 = {0, 0, KP_NONE, 0, -1, false}; static int lastDisplay = 1; static int currentDisplay = 1; // timestamp when spectrum display was activated static unsigned long specTimer; void enterMode(int mode); void WiFiEvent(WiFiEvent_t event); char buffer[85]; MicroNMEA nmea(buffer, sizeof(buffer)); // Read line from file, independent of line termination (LF or CR LF) String readLine(Stream &stream) { String s = stream.readStringUntil('\n'); int len = s.length(); if (len == 0) return s; if (s.charAt(len - 1) == '\r') s.remove(len - 1); return s; } // Read line from file, without using dynamic memory allocation (String class) // returns length line. int readLine(Stream &stream, char *buffer, int maxlen) { int n = stream.readBytesUntil('\n', buffer, maxlen); buffer[n] = 0; if (n <= 0) return 0; if (buffer[n - 1] == '\r') { buffer[n - 1] = 0; n--; } return n; } // Replaces placeholder with LED state value String processor(const String& var) { Serial.println(var); if (var == "VERSION_NAME") { return String(version_name); } if (var == "VERSION_ID") { return String(version_id); } if (var == "AUTODETECT_INFO") { char tmpstr[128]; const char *fpstr; int i = 0; while (fingerprintValue[i] != sonde.fingerprint && fingerprintValue[i] != -1) i++; if (fingerprintValue[i] == -1) { fpstr = "Unknown board"; } else { fpstr = fingerprintText[i]; } snprintf(tmpstr, 128, "Fingerprint %d (%s)", sonde.fingerprint, fpstr); return String(tmpstr); } return String(); } const String sondeTypeSelect(int activeType) { String sts = ""; for (int i = 0; i < NSondeTypes; i++) { sts += "