diff --git a/lib/image/image.cpp b/lib/image/image.cpp index c7398fd..4a1fac9 100644 --- a/lib/image/image.cpp +++ b/lib/image/image.cpp @@ -10,19 +10,8 @@ int overlaysCount = 1; OverlayCallback overlays[] = { timeOverlay }; void timeOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { - String time(""); - - if( localIP == "Unconnected" or localIP == "10.1.1.1" ) { - unsigned long mscount = millis(); - unsigned long sec = mscount / 1000; - unsigned long mse = mscount / 100 - sec * 10; - time = (String)sec + "." + (String)mse; - } else { - time = ntpTime(); - } - display->setTextAlignment(TEXT_ALIGN_CENTER); - display->drawString(64, 54, time); + display->drawString(64, 54, ntpTime()); } // frames @@ -81,13 +70,7 @@ void oledOsFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int display->setTextAlignment(TEXT_ALIGN_LEFT); // Version - display->drawFastImage(0+x, 16+y, 16, 16, Board_Icon); - display->drawString(24+x, 18+y, boardVersion); - - // WiFi - if( localIP == "Unconnected") - display->drawFastImage(0+x, 34+y, 16, 16, Wifi_Unconnected_Icon); - else - display->drawFastImage(0+x, 34+y, 16, 16, Wifi_Connected_Icon); - display->drawString(24+x, 36+y, localIP); + display->drawString(0+x, 16+y, "Ver: " + Board.Version); + display->drawString(0+x, 30+y, "IP : " + Board.ip.toString()); + display->drawString(0+x, 44+y, "Mem: " + (String)(80.0-ESP.getFreeHeap()/1024) + "/80 kB"); } \ No newline at end of file diff --git a/lib/utils/utils.cpp b/lib/utils/utils.cpp index ed00c84..e4023d5 100644 --- a/lib/utils/utils.cpp +++ b/lib/utils/utils.cpp @@ -14,9 +14,6 @@ #include // Global Config -String boardVersion("v0.0.1"); -String localIP("Unconnected"); - IPConfig APStatic = { IPAddress(10, 1, 1, 1), IPAddress(10, 0, 1, 1), @@ -27,6 +24,10 @@ IPConfig STAStatic = { IPAddress(192,168,0,1), IPAddress(255, 255, 255, 0) }; +BoardInfo Board = { + "0.0.1", + WiFi.localIP() +}; // https://github.com/PaulStoffregen/Time/blob/master/examples/TimeNTP_ESP8266WiFi/TimeNTP_ESP8266WiFi.ino static const int timeZone = 8; @@ -110,19 +111,20 @@ String ntpTime() { return timeString; } + +long view = 0; +long likes = 0; +long follower = 0; +long dayView = 0; +long weekView = 0; +long monthView = 0; + static String UID = "450115492"; static String followerUrl = "https://api.bilibili.com/x/relation/stat?vmid=" + UID; static String viewAndLikesUrl = "https://api.bilibili.com/x/space/upstat?mid=" + UID; static String webViewerUrl = "https://api.foolishfox.cn/data/board.json"; -long follower = 0; -long view = 0; -long likes = 0; - -long dayView = 0; -long weekView = 0; -long monthView = 0; - +static bool clientFlag = false; static HTTPClient httpFllower; static HTTPClient httpViewAndLikes; static HTTPClient httpWebView; @@ -198,8 +200,11 @@ void getWebView() { httpWebView.end(); } -void initData() { - client.setInsecure(); +void getData() { + if( !clientFlag ) { + client.setInsecure(); + clientFlag = true; + } getWebView(); getFollower(); getViewAndLikes(); diff --git a/lib/utils/utils.h b/lib/utils/utils.h index c7820c1..010a5da 100644 --- a/lib/utils/utils.h +++ b/lib/utils/utils.h @@ -14,12 +14,16 @@ typedef struct IPConfig { IPAddress sn; } IPConfig; +typedef struct BoardInfo { + String Version; + IPAddress ip; +} BoardInfo; + // Global Variable -extern String boardVersion; -extern String localIP; extern IPConfig APStatic; extern IPConfig STAStatic; +extern BoardInfo Board; extern long follower; extern long view; @@ -32,7 +36,7 @@ extern long monthView; void initNtp(); String ntpTime(); -void initData(); +void getData(); void getFollower(); void getViewAndLikes(); void getWebView(); diff --git a/src/main.cpp b/src/main.cpp index fbc2a77..4c2c11f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,15 +15,15 @@ // Global arguments Ticker temp; Ticker task; -int minCount; +int minCount = 0; SSD1306Wire display(0x3c, SDA, SCL); // 128 * 64 display OLEDDisplayUi ui(&display); +void blink(); void initWiFi(); void configModeCallback(WiFiManager *config); void initOLED(); -void blink(); -// void minCountCallBack(); +void minCountCallBack(); void setup() { Serial.begin(115200); @@ -37,7 +37,8 @@ void setup() { temp.detach(); digitalWrite(LED_BUILTIN, LOW); - // task.attach(60, minCountCallBack); + minCountCallBack(); + task.attach(60, minCountCallBack); } void loop() { @@ -72,7 +73,7 @@ void initWiFi() { delay(1000); } - localIP = WiFi.localIP().toString(); + Board.ip = WiFi.localIP(); } void configModeCallback(WiFiManager *config) { @@ -103,3 +104,11 @@ void initOLED() { display.flipScreenVertically(); } + +void minCountCallBack() { + if( minCount%60 == 0 ) { + minCount = 0; + getData(); + } + minCount += 1; +} \ No newline at end of file