refactor: function and variable name;add: oledWebFrame, oledBilibiliFrame, ntptime;

This commit is contained in:
liuyihui 2022-01-09 01:19:45 +08:00
parent 0276c35750
commit 5e4ee26588
9 changed files with 330 additions and 193 deletions

1
.gitignore vendored
View File

@ -4,5 +4,6 @@
.vscode/launch.json
.vscode/ipch
*.back
*.code-workspace
tool.py

0
README.md Normal file
View File

View File

@ -5,14 +5,11 @@
#include <font.h>
#include <utils.h>
extern String ver;
extern String localIP;
// Overlays are statically drawn on top of a frame
// Overlays
int overlaysCount = 1;
OverlayCallback overlays[] = { msOverlay };
OverlayCallback overlays[] = { timeOverlay };
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
void timeOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
String time("");
if( localIP == "Unconnected" ) {
@ -20,57 +17,90 @@ void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
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, 50, time);
display->drawString(64, 54, time);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}
// frames
// int frameCount = 4;
// FrameCallback frames[] = { oled_web_page, oled_mqtt_page, oled_bilibili_page, oled_os_page };
int frameCount = 1;
FrameCallback frames[] = { oled_os_page };
int frameCount = 3;
FrameCallback frames[] = { oledWebFrame, oledBilibiliFrame, oledOsFrame };
static void oled_title(OLEDDisplay *display) {
static void oledTitle(OLEDDisplay *display, String s) {
// Title
display->setFont(Roboto_Mono_13);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(0, 0, "INFO BOARD");
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(64, 0, s);
display->setFont(Roboto_Mono_10);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}
void oled_web_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
}
void oled_mqtt_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
}
void oled_bilibili_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
}
void oled_os_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
void oledWebFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
// Title
oled_title(display);
oledTitle(display, "Fox Home");
// Day View
display->drawString(0, 16, "Today");
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120, 16, (String)dayView);
display->setTextAlignment(TEXT_ALIGN_LEFT);
// Week View
display->drawString(0, 30, "Last Week");
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120, 30, (String)weekView);
display->setTextAlignment(TEXT_ALIGN_LEFT);
// Month View
display->drawString(0, 44, "Last Month");
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120, 44, (String)monthView);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}
void oledMQTTFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
}
void oledBilibiliFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
// Title
oledTitle(display, "BiliBili");
// Follower
display->drawString(0, 16, "Follower");
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120, 16, (String)follower);
display->setTextAlignment(TEXT_ALIGN_LEFT);
// View
display->drawString(0, 30, "View");
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120, 30, (String)view);
display->setTextAlignment(TEXT_ALIGN_LEFT);
// Likes
display->drawString(0, 44, "Likes");
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(120, 44, (String)likes);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}
void oledOsFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
// Title
oledTitle(display, "INFO BOARD");
// Version
display->drawFastImage(0, 16, 16, 16, board_icon);
display->drawFastImage(0, 16, 16, 16, Board_Icon);
display->drawString(24, 18, ver);
// WiFi
if( localIP == "Unconnected")
display->drawFastImage(0, 34, 16, 16, wifi_unconnected_icon);
display->drawFastImage(0, 34, 16, 16, Wifi_Unconnected_Icon);
else
display->drawFastImage(0, 34, 16, 16, wifi_connected_icon);
display->drawFastImage(0, 34, 16, 16, Wifi_Connected_Icon);
display->drawString(24, 36, localIP);
//
display->display();
}

View File

@ -6,28 +6,28 @@
#include <OLEDDisplayUi.h>
// wifi已连接图标 16*16
const unsigned char wifi_connected_icon[] PROGMEM = {
const unsigned char Wifi_Connected_Icon[] PROGMEM = {
0x18,0x00,0x0c,0x00,0x8c,0x01,0x86,0x01,0xc6,0x00,0xc3,0x18,0x63,0x18,0x63,0xcc,
0x63,0xcc,0x63,0x18,0xc3,0x18,0xc6,0x00,0x86,0x01,0x8c,0x01,0x0c,0x00,0x18,0x00
};
// wifi未连接图标 16*16
const unsigned char wifi_unconnected_icon[] PROGMEM = {
const unsigned char Wifi_Unconnected_Icon[] PROGMEM = {
0x18,0xc0,0x0c,0xe0,0x8c,0x71,0x86,0x39,0xc6,0x1c,0xc3,0x1e,0x63,0x1f,0xe3,0xcf,
0xe3,0xcd,0xe3,0x18,0xf3,0x18,0xfe,0x00,0x9e,0x01,0x8e,0x01,0x0f,0x00,0x1b,0x00
};
// 路由器图标 16*16
const unsigned char router_icon[] PROGMEM = {
const unsigned char Router_Icon[] PROGMEM = {
0x38,0xfc,0x70,0x84,0xe0,0xb4,0xc0,0xa5,0x80,0xa7,0x00,0xa7,0x00,0x86,0x00,0x84,
0x00,0x84,0x00,0x86,0x00,0x87,0x80,0xb7,0xc0,0xb5,0xe0,0x84,0x70,0x84,0x38,0xfc,
};
// 板子图标 16*16
const unsigned char board_icon[] PROGMEM = {
const unsigned char Board_Icon[] PROGMEM = {
0xff,0xff,0x01,0x80,0x3f,0x80,0x23,0x80,0x23,0x80,0x3f,0x80,0x01,0x80,0xff,0xff,
0x00,0x00,0x30,0x0c,0xe0,0x07,0x06,0x60,0x1c,0x38,0xf0,0x0f,0x00,0x00,0x00,0x00
};
// bilibili 24*24
const unsigned char bilibilitv_icon[] PROGMEM = {
const unsigned char Bilibilitv_Icon[] PROGMEM = {
0x00,0x00,0x02,0x00,0x00,0x03,0x30,0x00,0x01,0xe0,0x80,0x01,
0x80,0xc3,0x00,0x00,0xef,0x00,0xff,0xff,0xff,0x03,0x00,0xc0,
0xf9,0xff,0xdf,0x09,0x00,0xd0,0x09,0x00,0xd0,0x89,0xc1,0xd1,
@ -36,7 +36,36 @@ const unsigned char bilibilitv_icon[] PROGMEM = {
0x03,0x00,0xc0,0xff,0xff,0xff,0x78,0x00,0x1e,0x30,0x00,0x0c
};
const uint8_t active_symbol_icon[] PROGMEM = {
#define WiFi_Logo_width 60
#define WiFi_Logo_height 36
const uint8_t WiFi_Logo_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const uint8_t Active_Symbol_Icon[] PROGMEM = {
B00000000,
B00000000,
B00011000,
@ -47,7 +76,7 @@ const uint8_t active_symbol_icon[] PROGMEM = {
B00011000
};
const uint8_t inactive_symbol_icon[] PROGMEM = {
const uint8_t Inactive_Symbol_Icon[] PROGMEM = {
B00000000,
B00000000,
B00000000,
@ -58,15 +87,15 @@ const uint8_t inactive_symbol_icon[] PROGMEM = {
B00000000
};
void oled_web_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oled_mqtt_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oled_bilibili_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oled_os_page(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oledWebFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oledMQTTFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oledBilibiliFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
void oledOsFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
extern int frameCount;
extern FrameCallback frames[];
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state);
void timeOverlay(OLEDDisplay *display, OLEDDisplayUiState* state);
extern int overlaysCount;
extern OverlayCallback overlays[];

View File

@ -6,50 +6,189 @@
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <TimeLib.h>
#include <WiFiUdp.h>
String ver("v0.0.1");
String localIP("Unconnected");
String NAME = "仙女小可"; //改成自己的名字
static String UID = "450115492"; //改成自己的UID
static String followerUrl = "http://api.bilibili.com/x/relation/stat?vmid=" + UID; // 粉丝数
static String viewAndLikesUrl = "http://api.bilibili.com/x/space/upstat?mid=" + UID; // 播放数、点赞数
// https://github.com/PaulStoffregen/Time/blob/master/examples/TimeNTP_ESP8266WiFi/TimeNTP_ESP8266WiFi.ino
static const int timeZone = 8;
static const int NTP_PACKET_SIZE = 48;
static byte packetBuffer[NTP_PACKET_SIZE];
static IPAddress ntpServerIP(203, 107, 6, 88);
// static const char ntpServerName[] = "ntp.aliyun.com";
long follower_hist = 0; // 历史粉丝数
long follower = 0; // 粉丝数
long view = 0; // 播放数
long likes = 0; // 获赞数
static bool isNTPConnected = false;
static WiFiUDP ntpUDP;
static unsigned int localPort = 2390;
static DynamicJsonDocument jsonBuffer(256);
static void sendNTPpacket(IPAddress& address)
{
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
ntpUDP.beginPacket(address, 123);
ntpUDP.write(packetBuffer, NTP_PACKET_SIZE);
ntpUDP.endPacket();
}
void getFollower(String url) {
HTTPClient http;
http.begin(url);
static time_t getNtpTime() {
byte tmp[1];
while( ntpUDP.parsePacket() > 0 ) ntpUDP.read(tmp, 1);
int res_code = http.GET();
if( res_code == 200 ) {
String res = http.getString();
DeserializationError error = deserializeJson(jsonBuffer, res);
sendNTPpacket(ntpServerIP);
uint32_t beginWait = millis();
while( millis() - beginWait < 1500 )
{
int size = ntpUDP.parsePacket();
if( size >= NTP_PACKET_SIZE )
{
isNTPConnected = true;
ntpUDP.read(packetBuffer, NTP_PACKET_SIZE);
// 将从位置40开始的四个字节转换为长整型只取前32位整数部分
unsigned long secsSince1900;
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
}
}
isNTPConnected = false;
return 0;
}
void initNtp() {
ntpUDP.begin(localPort);
setSyncProvider(getNtpTime);
setSyncInterval(300);
}
static String formatDigits(int digits)
{
if( digits < 10 )
return "0" + (String)digits;
return (String)digits;
}
String ntpTime() {
String timeString("");
timeString = (String)year() + '-'
+ formatDigits(month()) + '-'
+ formatDigits(day()) + ' '
+ formatDigits(hour()) + ':'
+ formatDigits(minute()) + ':'
+ formatDigits(second());
return timeString;
}
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 HTTPClient httpFllower;
static HTTPClient httpViewAndLikes;
static HTTPClient httpWebView;
static WiFiClientSecure client;
StaticJsonDocument<512> jsonBuffer;
void getFollower() {
httpFllower.begin(client, followerUrl);
int resCode = httpFllower.GET();
if( resCode == 200 ) {
String resBuffer = httpFllower.getString();
DeserializationError error = deserializeJson(jsonBuffer, resBuffer);
if( error ) {
Serial.print(F("deserializeJson() failed: "));
Serial.print(F("deserializeJson(Follower) failed: "));
Serial.println(error.f_str());
return;
}
follower_hist = follower;
follower = jsonBuffer["data"]["follower"];
} else {
Serial.printf("[HTTP] GET... failed, error: %d\n", res_code);
Serial.printf("[HTTP] GET Follower failed, error: %d\n", resCode);
}
http.end();
httpFllower.end();
}
void getViewAndLikes(String url) {
void getViewAndLikes() {
httpViewAndLikes.begin(client, viewAndLikesUrl);
int resCode = httpViewAndLikes.GET();
if( resCode == 200 ) {
String resBuffer = httpViewAndLikes.getString();
DeserializationError error = deserializeJson(jsonBuffer, resBuffer);
if( error ) {
Serial.print(F("deserializeJson(View & Likes) failed: "));
Serial.println(error.f_str());
return;
}
likes = jsonBuffer["data"]["likes"];
view = jsonBuffer["data"]["archive"]["view"];
} else {
Serial.printf("[HTTP] GET View & Likes failed, error: %d\n", resCode);
}
httpViewAndLikes.end();
}
void getWebView() {
httpWebView.begin(client, webViewerUrl + "?time=" + ntpTime());
int resCode = httpWebView.GET();
if( resCode == 200 ) {
String resBuffer = httpWebView.getString();
DeserializationError error = deserializeJson(jsonBuffer, resBuffer);
if( error ) {
Serial.print(F("deserializeJson(Web View) failed: "));
Serial.println(error.f_str());
return;
}
dayView = jsonBuffer["day"];
weekView = jsonBuffer["week"];
monthView = jsonBuffer["month"];
} else {
Serial.printf("[HTTP] GET Web View failed, error: %d\n", resCode);
}
httpWebView.end();
}
void initData() {
client.setInsecure();
getWebView();
getFollower();
getViewAndLikes();
}

View File

@ -6,13 +6,20 @@
extern String ver;
extern String localIP;
extern String NAME;
extern long follower_hist;
extern long follower;
extern long view;
extern long likes;
void getFollower(String url);
void getViewAndLikes(String url);
extern long dayView;
extern long weekView;
extern long monthView;
void initNtp();
String ntpTime();
void initData();
void getFollower();
void getViewAndLikes();
void getWebView();
#endif

View File

@ -18,5 +18,5 @@ monitor_speed = 115200
lib_deps =
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.1
tzapu/WiFiManager@^0.16.0
arduino-libraries/NTPClient@^3.1.0
bblanchon/ArduinoJson@^6.18.5
paulstoffregen/Time@^1.6.1

View File

@ -1,81 +0,0 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <font.h>
#include <SSD1306Wire.h>
#include <icon.h>
#include <Ticker.h>
// Global arguments
Ticker tick;
// 128 * 64 display
SSD1306Wire display(0x3c, 4, 5);
void init_system();
void init_OLED();
void init_WiFi();
void configModeCallback(WiFiManager *config);
void blink();
void setup() {
init_system();
init_OLED();
// init_WiFi();
// tick.detach();
// digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
}
void init_system() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
tick.attach(1, blink);
}
void init_OLED() {
display.init();
display.flipScreenVertically();
display.setContrast(255);
display.setFont(Roboto_Mono_13);
oled_page1(display, "Unconnected");
}
void init_WiFi() {
WiFiManager manager;
manager.setDebugOutput(true);
manager.setRemoveDuplicateAPs(true);
manager.setMinimumSignalQuality(40);
manager.setAPCallback(configModeCallback);
manager.setAPStaticIPConfig(
IPAddress(10, 1, 1, 1),
IPAddress(10, 0, 1, 1),
IPAddress(255, 255, 255, 0)
);
if( !manager.autoConnect("Info Board", "cj160217") ) {
ESP.reset();
delay(1000);
}
oled_page1(display, WiFi.localIP().toString());
}
void configModeCallback(WiFiManager *config) {
tick.attach(0.1, blink);
}
void blink() {
int state = digitalRead(LED_BUILTIN);
digitalWrite(LED_BUILTIN, !state);
}

View File

@ -8,28 +8,33 @@
#include <SSD1306Wire.h>
#include <OLEDDisplayUi.h>
#include <utils.h>
#include <Ticker.h>
// Global arguments
Ticker tick;
Ticker temp;
Ticker task;
// 128 * 64 display
SSD1306Wire display(0x3c, 4, 5);
OLEDDisplayUi ui(&display);
void init_system();
void init_OLED();
void init_WiFi();
void initSystem();
void initWiFi();
void configModeCallback(WiFiManager *config);
void initOLED();
void blink();
void setup() {
init_system();
init_OLED();
// init_WiFi();
initSystem();
initWiFi();
initNtp();
initOLED();
initData();
// tick.detach();
temp.detach();
// digitalWrite(LED_BUILTIN, LOW);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
@ -43,32 +48,18 @@ void loop() {
}
}
void init_system() {
void initSystem() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
tick.attach(1, blink);
temp.attach(1, blink);
}
void init_OLED() {
display.init();
display.setContrast(255);
display.setFont(Roboto_Mono_10);
ui.setTargetFPS(15);
ui.setActiveSymbol(active_symbol_icon);
ui.setInactiveSymbol(inactive_symbol_icon);
ui.setIndicatorPosition(RIGHT);
ui.setIndicatorDirection(LEFT_RIGHT);
ui.setFrameAnimation(SLIDE_LEFT);
ui.setFrames(frames, frameCount);
ui.setOverlays(overlays, overlaysCount);
ui.init();
display.flipScreenVertically();
void blink() {
int state = digitalRead(LED_BUILTIN);
digitalWrite(LED_BUILTIN, !state);
}
void init_WiFi() {
void initWiFi() {
WiFiManager manager;
manager.setDebugOutput(true);
@ -81,18 +72,39 @@ void init_WiFi() {
IPAddress(10, 0, 1, 1),
IPAddress(255, 255, 255, 0)
);
manager.setSTAStaticIPConfig(
IPAddress(192, 168, 43, 141),
IPAddress(192,168,0,1),
IPAddress(255, 255, 255, 0)
);
if( !manager.autoConnect("Info Board", "cj160217") ) {
ESP.reset();
delay(1000);
}
localIP = WiFi.localIP().toString();
}
void configModeCallback(WiFiManager *config) {
tick.attach(0.1, blink);
temp.attach(0.1, blink);
}
void blink() {
int state = digitalRead(LED_BUILTIN);
digitalWrite(LED_BUILTIN, !state);
}
void initOLED() {
display.init();
display.setContrast(255);
display.setFont(Roboto_Mono_10);
ui.setTargetFPS(1);
ui.setActiveSymbol(Active_Symbol_Icon);
ui.setInactiveSymbol(Inactive_Symbol_Icon);
ui.setIndicatorPosition(RIGHT);
ui.setIndicatorDirection(LEFT_RIGHT);
ui.setFrameAnimation(SLIDE_UP);
ui.setFrames(frames, frameCount);
ui.setOverlays(overlays, overlaysCount);
ui.init();
display.flipScreenVertically();
}