#include "features.h" #include "version.h" #include "core.h" #define TAG "RX_FSK" #include "src/logger.h" #include #include #include #include #include #include #include #include #include #include "esp_heap_caps.h" //#include //#include "soc/timer_group_struct.h" //#include "soc/timer_group_reg.h" #include "src/SX1278FSK.h" #include "src/Sonde.h" #include "src/Display.h" #include "src/Scanner.h" #if FEATURE_RS92 #include "src/geteph.h" #include "src/rs92gps.h" #endif #include "src/ShFreqImport.h" #include "src/RS41.h" #include "src/DFM.h" #include "src/json.h" #include "src/posinfo.h" #include "src/pmu.h" #include "src/user.h" /* Data exchange connectors */ #if FEATURE_CHASEMAPPER #include "src/conn-chasemapper.h" #endif #if FEATURE_MQTT #include "src/conn-mqtt.h" #endif #if FEATURE_SDCARD #include "src/conn-sdcard.h" #endif #if FEATURE_APRS #include "src/conn-aprs.h" #endif #if FEATURE_SONDEHUB #include "src/conn-sondehub.h" #endif #include "src/conn-system.h" Conn *connectors[] = { &connSystem, &connGPS, #if FEATURE_APRS &connAPRS, #endif #if FEATURE_SONDEHUB &connSondehub, #endif #if FEATURE_CHASEMAPPER &connChasemapper, #endif #if FEATURE_MQTT &connMQTT, #endif #if FEATURE_SDCARD &connSDCard, #endif NULL }; //#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); PMU *pmu = NULL; SemaphoreHandle_t axpSemaphore; extern uint8_t pmu_irq; const char *updateHost = "rdzsonde.mooo.com"; int updatePort = 80; const char *updatePrefixM = "/main/"; const char *updatePrefixD = "/dev2/"; const char *updatePrefix = updatePrefixM; const char *updateFs = "update.fs.bin"; const char *updateIno = "update.ino.bin"; #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; /* Sonde.h: enum SondeType { STYPE_DFM,, STYPE_RS41, STYPE_RS92, STYPE_M10M20, STYPE_M10, STYPE_M20, STYPE_MP3H }; */ const char *sondeTypeStrSH[NSondeTypes] = { "DFM", "RS41", "RS92", "Mxx"/*never sent*/, "M10", "M20", "MRZ" }; // moved to connSondehub.cpp //#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 //int shImportInterval = 0; //char shImport = 0; //unsigned long time_last_update = 0; //#endif // JSON over TCP for communicating with the rdzSonde (rdzwx-go) Android app WiFiServer rdzserver(14570); WiFiClient rdzclient; // If a file "localupd.txt" exists, firmware can be updated from a custom IP address read from this file, stored in localUpdates. // By default (localUpdates==NULL) this is disabled to prevent abuse // Note: by enabling this, someone with access to the web interface can replace the firmware arbitrarily! // Make sure that only trustworthy persons have access to the web interface... char *localUpdates = NULL; 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); // Possibly we will need more fine grained permissions in the future... // For now, disallow arbitrary firmware updates on standard installations // development installations can add a file "localupd.txt" which enables updates from arbitrary locations int checkAllowed(const char *filename) { if(!localUpdates && (strstr(filename, "localupd.txt") != NULL)) return 0; return 1; } // 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) { LOG_D(TAG, "%s\n", var.c_str()); if (var == "MAPCENTER") { #if 0 double lat, lon; if (gpsPos.valid) { lat = gpsPos.lat; lon = gpsPos.lon; } else { lat = sonde.config.rxlat; lon = sonde.config.rxlon; } //if ( !isnan(lat) && !isnan(lon) ) { #endif if ( posInfo.valid ) { char p[40]; snprintf(p, 40, "%g,%g", posInfo.lat, posInfo.lon); return String(p); } else { return String("48,13"); } } if (var == "VERSION_NAME") { return String(version_name); } if (var == "VERSION_ID") { return String(version_id); } if (var == "FULLNAMEID") { char tmp[128]; snprintf(tmp, 128, "%s-%c%d", version_id, FS_MAJOR + 'A' - 1, FS_MINOR); return String(tmp); } 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); } if (var == "EPHSTATE") { #if FEATURE_RS92 return String(ephtxt[ephstate]); #else return String("Not supported"); #endif } if (var == "LOCAL_UPDATES") { if(localUpdates) return String(localUpdates); else return String(); } if (var == "PREAUTH") { char preauth[COOKIE_SIZE]; generateRandomCookie("preauth",preauth); storeCookie(preauth, -1); // preauth value return String(preauth); } return String(); } const String sondeTypeSelect(int activeType) { String sts = ""; for (int i = 0; i < NSondeTypes; i++) { sts += "