This repository was archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRP2040_ESP8266Shield.ino
185 lines (150 loc) · 4.94 KB
/
RP2040_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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/****************************************************************************************************************************
RP2040_ESP8266Shield.ino
For RP2040 boards using ESP8266 WiFi Shield
Blynk_Esp8266AT_WM is a library for the Mega, Teensy, SAM DUE and SAMD boards (https://github.com/khoih-prog/Blynk_Esp8266AT_WM)
to enable easy configuration/reconfiguration and autoconnect/autoreconnect of WiFi/Blynk
Based on and Modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Esp8266AT_WM
Licensed under MIT license
*****************************************************************************************************************************/
/****************************************************************************************************************************
Important notes:
1) Tested OK with SAMD, Mega, nRF52, SAM DUE, RP2040
a) ESP8266-AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
b) ESP8266-AT version:1.7.4.0(May 11 2020 19:13:04)
SDK version:3.0.4(9532ceb)
compile time:May 27 2020 10:12:22
Bin version(Wroom 02):1.7.4
2) These versions don't work on SAMD, but work on Mega (hanging when connect to Blynk, WiFi OK)
To find bug and fix in Blynk ESP8266_Lib or Blynk library
*****************************************************************************************************************************/
#include "defines.h"
#if USE_BLYNK_WM
#include "Credentials.h"
#include "dynamicParams.h"
#define BLYNK_PIN_FORCED_CONFIG V10
#define BLYNK_PIN_FORCED_PERS_CONFIG V20
// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal
BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG)
{
if (param.asInt())
{
Serial.println( F("\nCP Button Hit. Rebooting") );
// This will keep CP once, clear after reset, even you didn't enter CP at all.
Blynk.resetAndEnterConfigPortal();
}
}
// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal
BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG)
{
if (param.asInt())
{
Serial.println( F("\nPersistent CP Button Hit. Rebooting") );
// This will keep CP forever, until you successfully enter CP, and Save data to clear the flag.
Blynk.resetAndEnterConfigPortalPersistent();
}
}
#endif
ESP8266 wifi(&EspSerial);
void heartBeatPrint()
{
static int num = 1;
if (Blynk.connected())
{
Serial.print(F("B"));
}
else
{
Serial.print(F("F"));
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
#define STATUS_CHECK_INTERVAL 15000L
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
// report status to Blynk
heartBeatPrint();
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}
void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print(F("\nStart RP2040_ESP8266Shield on ")); Serial.println(BOARD_NAME);
Serial.println(BLYNK_ESP8266AT_WM_VERSION);
Serial.println(ESP_AT_LIB_VERSION);
// initialize serial for ESP module
EspSerial.begin(ESP8266_BAUD);
#if USE_BLYNK_WM
Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION);
Serial.println(F("Start Blynk_ESP8266AT_WM"));
// Optional to change default AP IP(192.168.4.1) and channel(10)
//Blynk.setConfigPortalIP(IPAddress(192, 168, 152, 1));
// Personalized portal_ssid and password
Blynk.setConfigPortal(portal_ssid, portal_password);
//Blynk.setConfigPortal("RP2040_WM", "MyRP2040_PW");
Blynk.setConfigPortalChannel(0);
Blynk.begin(wifi);
#else
Serial.print(F("Start Blynk no WM with BlynkServer = "));
Serial.print(BlynkServer);
Serial.print(F(" and Token = "));
Serial.println(auth);
Blynk.begin(auth, wifi, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
#endif
}
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
void displayCredentials()
{
Serial.println("\nYour stored Credentials :");
for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++)
{
Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata);
}
}
void displayCredentialsInLoop()
{
static bool displayedCredentials = false;
if (!displayedCredentials)
{
for (uint8_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()
{
Blynk.run();
check_status();
#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
displayCredentialsInLoop();
#endif
}