-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOriginal_Test.ino
275 lines (240 loc) · 8.07 KB
/
Original_Test.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* @Description: 出厂测试程序,重复连接WIFI,串口打印电池电压数据
* @version: V1.0.0
* @Author: LILYGO_L
* @Date: 2023-08-16 15:19:01
* @LastEditors: LILYGO_L
* @LastEditTime: 2024-05-27 17:30:44
* @License: GPL 3.0
*/
#include "Arduino.h"
#include "WiFi.h"
#include <HTTPClient.h>
#include "pin_config.h"
#define WIFI_SSID "xinyuandianzi"
#define WIFI_PASSWORD "AA15994823428"
// #define WIFI_SSID "LilyGo-AABB"
// #define WIFI_PASSWORD "xinyuandianzi"
#define WIFI_CONNECT_WAIT_MAX 5000
#define NTP_SERVER1 "pool.ntp.org"
#define NTP_SERVER2 "time.nist.gov"
#define GMT_OFFSET_SEC 8 * 3600 // 时区设置函数,东八区(UTC/GMT+8:00)写成8*3600
#define DAY_LIGHT_OFFSET_SEC 0 // 夏令时填写3600,否则填0
static bool Wifi_Connection_Flag = false;
static bool IO_Level = 0;
static size_t CycleTime = 0;
static size_t CycleTime_2 = 0;
void Wifi_STA_Test(void)
{
String text;
int wifi_num = 0;
Serial.printf("\nScanning wifi");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
wifi_num = WiFi.scanNetworks();
if (wifi_num == 0)
{
text = "\nWiFi scan complete !\nNo wifi discovered.\n";
}
else
{
text = "\nWiFi scan complete !\n";
text += wifi_num;
text += " wifi discovered.\n\n";
for (int i = 0; i < wifi_num; i++)
{
text += (i + 1);
text += ": ";
text += WiFi.SSID(i);
text += " (";
text += WiFi.RSSI(i);
text += ")";
text += (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " \n" : "*\n";
delay(10);
}
}
Serial.println(text);
delay(3000);
text.clear();
text = "Connecting to ";
Serial.print("Connecting to ");
text += WIFI_SSID;
text += "\n";
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
uint32_t last_tick = millis();
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
text += ".";
delay(100);
if (millis() - last_tick > WIFI_CONNECT_WAIT_MAX)
{
Wifi_Connection_Flag = false;
break;
}
else
{
Wifi_Connection_Flag = true;
}
}
if (Wifi_Connection_Flag == true)
{
text += "\nThe connection was successful ! \nTakes ";
Serial.print("\nThe connection was successful ! \nTakes ");
text += millis() - last_tick;
Serial.print(millis() - last_tick);
text += " ms\n";
Serial.println(" ms\n");
}
else
{
Serial.printf("\nWifi test error!\n");
}
}
void WIFI_STA_Test_Loop(void)
{
if (Wifi_Connection_Flag == false)
{
Serial.printf("Not connected to the network\n");
Wifi_STA_Test();
delay(2000);
}
else
{
// Obtain and set the time from the network time server
// After successful acquisition, the chip will use the RTC clock to update the holding time
configTime(GMT_OFFSET_SEC, DAY_LIGHT_OFFSET_SEC, NTP_SERVER1, NTP_SERVER2);
// delay(3000);
struct tm timeinfo;
if (!getLocalTime(&timeinfo, 10000))
{
Serial.println("Failed to obtain time\n");
Wifi_Connection_Flag = false;
return;
}
Serial.println("Get time success");
Serial.println(&timeinfo, "%A,%B %d %Y %H:%M:%S\n"); // Format Output
}
}
void setup()
{
Serial.begin(115200);
Serial.println("Ciallo");
// pinMode(GPIO_NUM_37, OUTPUT);
// pinMode(GPIO_NUM_35, OUTPUT);
// pinMode(GPIO_NUM_36, OUTPUT);
// pinMode(GPIO_NUM_45, OUTPUT);
// pinMode(GPIO_NUM_48, OUTPUT);
// pinMode(GPIO_NUM_47, OUTPUT);
// pinMode(GPIO_NUM_21, OUTPUT);
// pinMode(GPIO_NUM_14, OUTPUT);
// pinMode(GPIO_NUM_13, OUTPUT);
// pinMode(GPIO_NUM_12, OUTPUT);
// pinMode(GPIO_NUM_11, OUTPUT);
// pinMode(GPIO_NUM_10, OUTPUT);
// pinMode(GPIO_NUM_9, OUTPUT);
// pinMode(GPIO_NUM_46, OUTPUT);
// pinMode(GPIO_NUM_3, OUTPUT);
// pinMode(GPIO_NUM_38, OUTPUT);
// pinMode(GPIO_NUM_39, OUTPUT);
// pinMode(GPIO_NUM_40, OUTPUT);
// pinMode(GPIO_NUM_41, OUTPUT);
// pinMode(GPIO_NUM_8, OUTPUT);
// pinMode(GPIO_NUM_0, OUTPUT);
// pinMode(GPIO_NUM_18, OUTPUT);
// pinMode(GPIO_NUM_17, OUTPUT);
// pinMode(GPIO_NUM_7, OUTPUT);
// pinMode(GPIO_NUM_6, OUTPUT);
// pinMode(GPIO_NUM_5, OUTPUT);
// pinMode(GPIO_NUM_4, OUTPUT);
// pinMode(GPIO_NUM_42, OUTPUT);
// pinMode(GPIO_NUM_2, OUTPUT);
// pinMode(GPIO_NUM_1, OUTPUT);
// pinMode(GPIO_NUM_43, OUTPUT);
// pinMode(GPIO_NUM_44, OUTPUT);
// digitalWrite(GPIO_NUM_37, IO_Level);
// digitalWrite(GPIO_NUM_35, IO_Level);
// digitalWrite(GPIO_NUM_36, IO_Level);
// digitalWrite(GPIO_NUM_45, IO_Level);
// digitalWrite(GPIO_NUM_48, IO_Level);
// digitalWrite(GPIO_NUM_47, IO_Level);
// digitalWrite(GPIO_NUM_21, IO_Level);
// digitalWrite(GPIO_NUM_14, IO_Level);
// digitalWrite(GPIO_NUM_13, IO_Level);
// digitalWrite(GPIO_NUM_12, IO_Level);
// digitalWrite(GPIO_NUM_11, IO_Level);
// digitalWrite(GPIO_NUM_10, IO_Level);
// digitalWrite(GPIO_NUM_9, IO_Level);
// digitalWrite(GPIO_NUM_46, IO_Level);
// digitalWrite(GPIO_NUM_3, IO_Level);
// digitalWrite(GPIO_NUM_38, IO_Level);
// digitalWrite(GPIO_NUM_39, IO_Level);
// digitalWrite(GPIO_NUM_40, IO_Level);
// digitalWrite(GPIO_NUM_41, IO_Level);
// digitalWrite(GPIO_NUM_8, IO_Level);
// digitalWrite(GPIO_NUM_0, IO_Level);
// digitalWrite(GPIO_NUM_18, IO_Level);
// digitalWrite(GPIO_NUM_17, IO_Level);
// digitalWrite(GPIO_NUM_7, IO_Level);
// digitalWrite(GPIO_NUM_6, IO_Level);
// digitalWrite(GPIO_NUM_5, IO_Level);
// digitalWrite(GPIO_NUM_4, IO_Level);
// digitalWrite(GPIO_NUM_42, IO_Level);
// digitalWrite(GPIO_NUM_2, IO_Level);
// digitalWrite(GPIO_NUM_1, IO_Level);
// digitalWrite(GPIO_NUM_43, IO_Level);
// digitalWrite(GPIO_NUM_44, IO_Level);
pinMode(BATTERY_VOLTAGE_DATA, INPUT_PULLDOWN);
analogReadResolution(12);
analogSetPinAttenuation(BATTERY_VOLTAGE_DATA, ADC_ATTENDB_MAX);
adcAttachPin(BATTERY_VOLTAGE_DATA);
Wifi_STA_Test();
}
void loop()
{
if (millis() > CycleTime)
{
Serial.printf("Battery Voltage Data: %d mV\n\n", analogReadMilliVolts(BATTERY_VOLTAGE_DATA) * 2);
WIFI_STA_Test_Loop();
CycleTime = millis() + 3000; // 3000ms
}
// if (millis() > CycleTime_2)
// {
// digitalWrite(GPIO_NUM_37, IO_Level);
// digitalWrite(GPIO_NUM_35, IO_Level);
// digitalWrite(GPIO_NUM_36, IO_Level);
// digitalWrite(GPIO_NUM_45, IO_Level);
// digitalWrite(GPIO_NUM_48, IO_Level);
// digitalWrite(GPIO_NUM_47, IO_Level);
// digitalWrite(GPIO_NUM_21, IO_Level);
// digitalWrite(GPIO_NUM_14, IO_Level);
// digitalWrite(GPIO_NUM_13, IO_Level);
// digitalWrite(GPIO_NUM_12, IO_Level);
// digitalWrite(GPIO_NUM_11, IO_Level);
// digitalWrite(GPIO_NUM_10, IO_Level);
// digitalWrite(GPIO_NUM_9, IO_Level);
// digitalWrite(GPIO_NUM_46, IO_Level);
// digitalWrite(GPIO_NUM_3, IO_Level);
// digitalWrite(GPIO_NUM_38, IO_Level);
// digitalWrite(GPIO_NUM_39, IO_Level);
// digitalWrite(GPIO_NUM_40, IO_Level);
// digitalWrite(GPIO_NUM_41, IO_Level);
// digitalWrite(GPIO_NUM_8, IO_Level);
// digitalWrite(GPIO_NUM_0, IO_Level);
// digitalWrite(GPIO_NUM_18, IO_Level);
// digitalWrite(GPIO_NUM_17, IO_Level);
// digitalWrite(GPIO_NUM_7, IO_Level);
// digitalWrite(GPIO_NUM_6, IO_Level);
// digitalWrite(GPIO_NUM_5, IO_Level);
// digitalWrite(GPIO_NUM_4, IO_Level);
// digitalWrite(GPIO_NUM_42, IO_Level);
// digitalWrite(GPIO_NUM_2, IO_Level);
// digitalWrite(GPIO_NUM_1, IO_Level);
// digitalWrite(GPIO_NUM_43, IO_Level);
// digitalWrite(GPIO_NUM_44, IO_Level);
// IO_Level = !IO_Level;
// CycleTime_2 = millis() + 1000; // 1000ms
// }
}