1
-
1
+ #include < esp_wifi.h>
2
+ #include < WiFi.h>
3
+ #include < WiFiClient.h>
4
+ // SPI is used by WiFi library
2
5
#include < SPI.h>
3
- #define ENABLE_GxEPD2_GFX 1
4
6
7
+ // Define must come before GxEPD2 includes
8
+ #define ENABLE_GxEPD2_GFX 1
5
9
#include < GxEPD2_BW.h>
6
10
#include < GxEPD2_3C.h>
7
11
#include < Fonts/FreeMonoBold9pt7b.h>
12
+ // 264x176
8
13
14
+ void initDisplay (GxEPD2_GFX& display);
9
15
void helloWorld (GxEPD2_GFX& display, const char *msg);
10
16
GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display (GxEPD2_270c(/* CS=5*/ SS, /* DC=*/ 17 , /* RST=*/ 16 , /* BUSY=*/ 4 ));
11
17
@@ -14,25 +20,21 @@ char *ip_to_char(uint32_t ip);
14
20
#define COLORED 0
15
21
#define UNCOLORED 1
16
22
17
- #include < esp_wifi.h>
18
- #include < WiFi.h>
19
- #include < WiFiClient.h>
20
-
21
23
#define ESP_getChipId () ((uint32_t )ESP.getEfuseMac())
22
24
23
25
#define LED_ON LOW
24
26
#define LED_OFF HIGH
25
27
26
28
// SSID and PW for Config Portal
27
29
String ssid = " ESP_" + String(ESP_getChipId(), HEX);
28
- const char * password = " your_password " ;
30
+ const char * password = " setup " ;
29
31
30
32
// SSID and PW for your Router
31
33
String Router_SSID;
32
34
String Router_Pass;
33
35
36
+ // Define must come before EPS_WiFiManager include
34
37
#define USE_AVAILABLE_PAGES true
35
-
36
38
#include < ESP_WiFiManager.h>
37
39
38
40
const int PIN_LED = 22 ;
@@ -71,26 +73,25 @@ void check_status()
71
73
}
72
74
}
73
75
76
+ char textBuffer[80 ];
77
+
74
78
void setup () {
75
79
pinMode (PIN_LED, OUTPUT);
76
80
digitalWrite (PIN_LED, LED_ON);
77
81
78
82
// put your setup code here, to run once:
79
83
Serial.begin (115200 );
80
84
81
- unsigned long startedAt = millis ( );
85
+ initDisplay (display );
82
86
83
- Serial. println ( " Hello world " );
87
+ unsigned long startedAt = millis ( );
84
88
85
- delay (100 );
86
- display.init (115200 );
87
- // first update should be full refresh
88
- helloWorld (display, " Waiting for Network" );
89
+ strcpy (textBuffer, " Hello " );
90
+ strcat (textBuffer, ssid.c_str ());
91
+ helloWorld (display, textBuffer);
89
92
90
93
delay (1000 );
91
94
92
- digitalWrite (PIN_LED, LED_OFF); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
93
-
94
95
ESP_WiFiManager ESP_wifiManager;
95
96
ESP_wifiManager.setMinimumSignalQuality (-1 );
96
97
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
@@ -109,7 +110,6 @@ void setup() {
109
110
// Check if there is stored WiFi router/password credentials.
110
111
// If not found, device will remain in configuration mode until switched off via webserver.
111
112
Serial.print (" Opening configuration portal." );
112
- digitalWrite (PIN_LED, LED_ON);
113
113
114
114
if (Router_SSID != " " )
115
115
{
@@ -122,6 +122,10 @@ void setup() {
122
122
// SSID to uppercase
123
123
ssid.toUpperCase ();
124
124
125
+ strcpy (textBuffer, " Start AP " );
126
+ strcat (textBuffer, ssid.c_str ());
127
+ helloWorld (display, textBuffer);
128
+
125
129
// it starts an access point
126
130
// and goes into a blocking loop awaiting configuration
127
131
if (!ESP_wifiManager.startConfigPortal ((const char *) ssid.c_str (), password))
@@ -137,8 +141,9 @@ void setup() {
137
141
#define WHILE_LOOP_DELAY 200L
138
142
#define WHILE_LOOP_STEPS (WIFI_CONNECT_TIMEOUT / ( 3 * WHILE_LOOP_DELAY ))
139
143
140
- startedAt = millis ( );
144
+ helloWorld (display, " Waiting for Network " );
141
145
146
+ startedAt = millis ();
142
147
while ( (WiFi.status () != WL_CONNECTED) && (millis () - startedAt < WIFI_CONNECT_TIMEOUT ) )
143
148
{
144
149
WiFi.mode (WIFI_STA);
@@ -174,6 +179,7 @@ void setup() {
174
179
void loop () {
175
180
// put your main code here, to run repeatedly:
176
181
check_status ();
182
+ delay (5000 );
177
183
}
178
184
179
185
static char ipCstring[16 ]; // size the char array large enough to hold 4 x 3 digit numbers + 3 x dot + null terminator
@@ -188,23 +194,26 @@ char *ip_to_char(const uint32_t ip) {
188
194
}
189
195
return ipCstring;
190
196
}
191
- void helloWorld (GxEPD2_GFX& display, const char * msg)
192
- {
197
+
198
+ void initDisplay (GxEPD2_GFX& display) {
199
+ display.init (115200 );
193
200
display.setRotation (1 );
194
201
display.setFont (&FreeMonoBold9pt7b);
195
202
display.setTextColor (GxEPD_BLACK);
203
+ display.setFullWindow ();
204
+ display.fillScreen (GxEPD_WHITE);
205
+ display.display (false );
206
+ }
207
+
208
+ void helloWorld (GxEPD2_GFX& display, const char * msg)
209
+ {
196
210
int16_t tbx, tby; uint16_t tbw, tbh;
197
211
display.getTextBounds (msg, 0 , 0 , &tbx, &tby, &tbw, &tbh);
198
212
// center bounding box by transposition of origin:
199
213
uint16_t x = ((display.width () - tbw) / 2 ) - tbx;
200
214
uint16_t y = ((display.height () - tbh) / 2 ) - tby;
201
- display.setFullWindow ();
202
- display.firstPage ();
203
- do
204
- {
205
- display.fillScreen (GxEPD_WHITE);
206
- display.setCursor (x, y);
207
- display.print (msg);
208
- }
209
- while (display.nextPage ());
215
+ display.fillScreen (GxEPD_WHITE);
216
+ display.setCursor (x, y);
217
+ display.print (msg);
218
+ display.display (false );
210
219
}
0 commit comments