This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mega_ESP8266Shield.ino
142 lines (117 loc) · 4.29 KB
/
Mega_ESP8266Shield.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/****************************************************************************************************************************
Mega_ESP8266Shield.ino
For AVR or Generic boards using ESP8266 AT WiFi Shields, using much less code to support boards with smaller memory
ESP_AT_WM_Lite is a library for the Mega, Teensy, SAM DUE, SAMD and STM32 boards (https://github.com/khoih-prog/ESP_AT_WM_Lite)
to enable store Credentials in EEPROM to easy configuration/reconfiguration and autoconnect/autoreconnect of WiFi and other services
without Hardcoding.
Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite
Licensed under MIT license
Version: 1.3.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 09/03/2020 Initial coding
1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch
1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars.
Permit to input special chars such as !,@,#,$,%,^,&,* into data fields.
1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc.
Add DRD support. Add MultiWiFi support
1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic.
Enhance MultiWiFi connection logic. Fix WiFi Status bug.
1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials
1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
1.3.0 K Hoang 12/05/2021 Add support to RP2040-based boards, such as RASPBERRY_PI_PICO
*****************************************************************************************************************************/
#include "defines.h"
#include "Credentials.h"
#include "dynamicParams.h"
ESP_AT_WiFiManager_Lite* ESP_AT_WiFiManager;
void heartBeatPrint()
{
static int num = 1;
if (WiFi.status() == WL_CONNECTED)
Serial.print(F("H")); // H means connected to WiFi
else
Serial.print(F("F")); // F means not connected to WiFi
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
//KH
#define HEARTBEAT_INTERVAL 20000L
// Print hearbeat every HEARTBEAT_INTERVAL (20) seconds.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
heartBeatPrint();
checkstatus_timeout = millis() + HEARTBEAT_INTERVAL;
}
}
void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial);
//delay(1000);
Serial.print(F("\nStart Mega_ESP8266Shield on "));
Serial.println(BOARD_NAME);
Serial.println(ESP_AT_WM_LITE_VERSION);
Serial.print("Debug Level = ");
Serial.println(_ESP_AT_WM_LOGLEVEL_);
// initialize serial for ESP module
EspSerial.begin(115200);
ESP_AT_WiFiManager = new ESP_AT_WiFiManager_Lite(&EspSerial, ESP8266_BAUD);
// Optional to change default AP IP(192.168.4.1)
//ESP_AT_WiFiManager->setConfigPortalIP(IPAddress(192, 168, 120, 1));
// Use channel(0) for random AP WiFi channel
ESP_AT_WiFiManager->setConfigPortalChannel(0);
// Personalized portal_ssid and password
//ESP_AT_WiFiManager->setConfigPortal(portal_ssid, portal_password);
ESP_AT_WiFiManager->begin();
}
#if USE_DYNAMIC_PARAMETERS
void displayCredentials()
{
Serial.println("\nStored Dynamic Params:");
for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++)
{
Serial.print(myMenuItems[i].displayName);
Serial.print(" = ");
Serial.println(myMenuItems[i].pdata);
}
}
void displayCredentialsOnce()
{
static bool displayedCredentials = false;
if (!displayedCredentials)
{
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
{
if (!strlen(myMenuItems[i].pdata))
{
break;
}
if ( i == (NUM_MENU_ITEMS - 1) )
{
displayedCredentials = true;
displayCredentials();
}
}
}
}
#endif
void loop()
{
ESP_AT_WiFiManager->run();
check_status();
#if (USE_DYNAMIC_PARAMETERS)
displayCredentialsOnce();
#endif
}