Skip to content

Commit 944dba7

Browse files
committed
Initial commit add wifimanager and feedback led
0 parents  commit 944dba7

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed

data/config.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"mqtt_server": "",
3+
"mqtt_port": "",
4+
"mqtt_sub": "",
5+
"mqtt_pup": ""
6+
}

include/image.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#define logo_width 128
2+
#define logo_height 32
3+
const uint8_t PROGMEM logo_data[] = {
4+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
5+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
6+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00011000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
7+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
8+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000011,B11100000,B00000001,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
9+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000100,B10010000,B11100010,B00100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
10+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001101,B00010000,B10000111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
11+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010101,B00010000,B01111001,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
12+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00011001,B10010000,B00000001,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
13+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000010,B01100000,B00000000,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
14+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000011,B11100000,B00001110,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
15+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000100,B00110000,B00011010,B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
16+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01100100,B00110000,B00101010,B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
17+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01001000,B00011000,B00101110,B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
18+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00001000,B00110000,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
19+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000100,B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
20+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
21+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B10001101,B00010000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
22+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B00110000,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
23+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
24+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
25+
B00001100,B00000000,B00000000,B00000100,B10000000,B00011000,B00000110,B00000000,B00000000,B00000001,B00000000,B00001100,B00000000,B00000100,B00000000,B00000000,
26+
B00000100,B00100100,B00000000,B00001001,B00000010,B01001000,B00000010,B00000000,B00000000,B00000010,B00000000,B00000100,B00000000,B00000100,B00000100,B00000000,
27+
B00000100,B00100100,B00000000,B00001001,B00000000,B01001000,B00000010,B00000000,B00000000,B00000010,B00000000,B00000100,B00000000,B00000100,B00000000,B00000000,
28+
B00000111,B01111111,B11101110,B00001001,B11110110,B11101110,B11010011,B10001110,B11101111,B11000011,B11111101,B10100111,B01111011,B11011100,B11111101,B11000000,
29+
B00000101,B00100100,B10101010,B01010010,B10100010,B01001010,B01010010,B10001010,B10100101,B01000100,B10010100,B10100101,B01010001,B01010100,B01000101,B01000000,
30+
B00000101,B00100100,B10100100,B00010010,B10100010,B01001010,B01010010,B10001000,B10100101,B01000100,B10001000,B10100101,B01010001,B01010100,B01000101,B01000000,
31+
B00000101,B00100100,B10101010,B00100100,B10100010,B01001010,B01010010,B10001010,B10100101,B01001000,B10010100,B10100101,B01010001,B01010100,B01000101,B01000000,
32+
B00001101,B10110110,B11101110,B01100100,B11100111,B01111011,B01111111,B10011110,B11101101,B01101001,B11011100,B11111111,B01111011,B01111110,B11101111,B11000000,
33+
B00000000,B00000000,B10000000,B00100100,B00100000,B00000000,B00000000,B00000000,B00000000,B00001000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
34+
B00000000,B00000001,B10000000,B00000000,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
35+
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
36+
};

platformio.ini

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[platformio]
12+
default_envs = nodemcuv2
13+
14+
[common_env_data]
15+
monitor_speed = 115200
16+
17+
[env:nodemcuv2]
18+
platform = espressif8266
19+
board = nodemcuv2
20+
framework = arduino
21+
upload_speed = 512000
22+
monitor_speed = 115200
23+
; lib_deps =
24+
; Adafruit GFX Library
25+
; Adafruit SSD1306
26+
27+
[env:esp32doit-devkit-v1]
28+
platform = espressif32
29+
board = esp32doit-devkit-v1
30+
framework = arduino
31+
upload_speed = 921600
32+
monitor_speed = 115200
33+

src/main.cpp

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <Arduino.h>
2+
#include <ESP8266WiFi.h>
3+
#include <ESPAsyncWebServer.h>
4+
#include <ESPAsyncWiFiManager.h>
5+
#include <FS.h>
6+
#include <ArduinoJson.h>
7+
#include <Ticker.h>
8+
9+
#define LED 2
10+
11+
struct Config
12+
{
13+
char mqtt_server[40];
14+
char mqtt_port[6];
15+
char mqtt_sub[16];
16+
char mqtt_pub[16];
17+
};
18+
19+
Config conf;
20+
21+
Ticker ticker;
22+
// Ticker conn;
23+
24+
void ledToggle()
25+
{
26+
bool state = digitalRead(LED);
27+
digitalWrite(LED, !state);
28+
}
29+
30+
void chkConn()
31+
{
32+
if (WiFi.status() != WL_CONNECTED)
33+
{
34+
ESP.reset();
35+
}
36+
}
37+
38+
void configModeCallback(AsyncWiFiManager *myWiFiManager)
39+
{
40+
ticker.attach(0.2, ledToggle);
41+
Serial.println(F("Entered config mode"));
42+
Serial.print(F("SSID: "));
43+
Serial.println(myWiFiManager->getConfigPortalSSID());
44+
Serial.print(F("APIP: "));
45+
Serial.println(WiFi.softAPIP());
46+
}
47+
48+
AsyncWebServer server(80);
49+
DNSServer dns;
50+
AsyncWiFiManager wifiManager(&server, &dns);
51+
52+
void setup()
53+
{
54+
Serial.begin(115200);
55+
pinMode(LED, OUTPUT);
56+
ticker.attach(0.5, ledToggle);
57+
58+
// wifiManager.resetSettings();
59+
60+
wifiManager.setAPCallback(configModeCallback);
61+
62+
if (!wifiManager.autoConnect())
63+
{
64+
Serial.println(F("failed to connect and timed out"));
65+
// delay(500);
66+
ESP.reset();
67+
delay(1000);
68+
}
69+
70+
// kalau sampai sini berarti udah konek
71+
Serial.println(F("connected...yeay!!"));
72+
73+
Serial.print(F("local ip: "));
74+
Serial.println(WiFi.localIP());
75+
Serial.print(F("gateway: "));
76+
Serial.println(WiFi.gatewayIP());
77+
Serial.print(F("subnetmask: "));
78+
Serial.println(WiFi.subnetMask());
79+
80+
// mulai servernya
81+
server.begin();
82+
83+
// tidak usah kedipkan led kalau dah konek
84+
ticker.detach();
85+
digitalWrite(LED, 0);
86+
87+
// periksa koneksi setiap menit
88+
ticker.attach(60, chkConn);
89+
90+
server.onNotFound([](AsyncWebServerRequest *request) {
91+
if (request->method() == HTTP_OPTIONS)
92+
{
93+
request->send(200);
94+
}
95+
else
96+
{
97+
request->send(404);
98+
}
99+
});
100+
101+
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
102+
request->send(200, "text/plain", "Hello, world");
103+
});
104+
105+
server.on("/wifireset", HTTP_GET, [](AsyncWebServerRequest *request) {
106+
// request->redirect("http://" + WiFi.softAPIP().toString());
107+
wifiManager.resetSettings();
108+
ESP.reset();
109+
request->redirect("/");
110+
});
111+
}
112+
113+
void loop()
114+
{
115+
}

0 commit comments

Comments
 (0)