-
Notifications
You must be signed in to change notification settings - Fork 0
/
R4-WiFi-Matrix-NTP-GMail_send.ino
314 lines (298 loc) · 7.51 KB
/
R4-WiFi-Matrix-NTP-GMail_send.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include <WiFiS3.h>
#include <ESP_Mail_Client.h>
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"
#include <NTPClient.h>
#include <WiFiUdp.h>
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 465
#define AUTHOR_EMAIL "*********@gmail.com"
#define AUTHOR_PASSWORD "************"
#define RECIPIENT_EMAIL "****************"
SMTPSession smtp;
char ssid[] = "**************";
char pass[] = "***************";
int status = WL_IDLE_STATUS;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "be.pool.ntp.org");
char* weekday[7] = { "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" };
ArduinoLEDMatrix matrix;
const uint32_t heart[] = {
0x3184a444,
0x44042081,
0x100a0040
};
uint8_t frame[8][12] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
void leftEye(){
frame[1][3] = 1;
frame[1][4] = 1;
frame[2][3] = 1;
frame[2][4] = 1;
}
void wink(){
frame[1][3] = 0;
frame[1][4] = 0;
frame[2][3] = 1;
frame[2][4] = 1;
}
void wink2(){
frame[1][8] = 0;
frame[1][9] = 0;
frame[2][8] = 1;
frame[2][9] = 1;
}
void rightEye(){
frame[1][8] = 1;
frame[1][9] = 1;
frame[2][8] = 1;
frame[2][9] = 1;
}
void nose(){
frame[3][6] = 1;
frame[4][5] = 1;
frame[4][6] = 1;
frame[4][7] = 1;
}
void mouth(){
frame[5][3] = 1;
frame[5][9] = 1;
frame[6][3] = 1;
frame[6][4] = 1;
frame[6][5] = 1;
frame[6][6] = 1;
frame[6][7] = 1;
frame[6][8] = 1;
frame[6][9] = 1;
}
void mouth2(){
frame[5][3] = 0;
frame[5][9] = 0;
frame[6][3] = 1;
frame[6][4] = 1;
frame[6][5] = 1;
frame[6][6] = 1;
frame[6][7] = 1;
frame[6][8] = 1;
frame[6][9] = 1;
frame[7][6] = 0;
}
void mouth3(){
frame[5][3] = 0;
frame[5][9] = 0;
frame[6][3] = 1;
frame[6][4] = 1;
frame[6][5] = 1;
frame[6][6] = 1;
frame[6][7] = 1;
frame[6][8] = 1;
frame[6][9] = 1;
frame[7][6] = 1;
}
void timebot(){
timeClient.update();
time_t epochTime2 = timeClient.getEpochTime();
unsigned long epochTime = timeClient.getEpochTime();
while (epochTime < 1707219755) {
epochTime = timeClient.getEpochTime();
delay(25);
}
struct tm *ptm = gmtime ((time_t *)&epochTime2);
int monthDay = ptm->tm_mday;
int aday = timeClient.getDay();
int ahoure = timeClient.getHours();
int aMinute = timeClient.getMinutes();
char timestamp[19];
if(ahoure < 10){
if(aMinute < 10){
snprintf(timestamp, 25, " %s %d - 0%d:0%d", weekday[aday], monthDay,
ahoure, aMinute);
}
else if(ahoure < 10 && aMinute >= 10) {
snprintf(timestamp, 25, " %s %d - 0%d:%d", weekday[aday], monthDay,
ahoure, aMinute);
}else {
snprintf(timestamp, 25, " %s %d - %d:%d", weekday[aday], monthDay,
ahoure, aMinute);
}}
else {
if(aMinute < 10){
snprintf(timestamp, 25, " %s %d - %d:0%d", weekday[aday], monthDay,
ahoure, aMinute);
}
else {
snprintf(timestamp, 25, " %s %d - %d:%d", weekday[aday], monthDay,
ahoure, aMinute);
}}
matrix.beginDraw();
matrix.stroke(0xFFFFFFFF);
matrix.textScrollSpeed(70);
matrix.textFont(Font_5x7);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(timestamp);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
if(ahoure >= 0 && ahoure < 8){
wink();
wink2();
nose();
mouth2();
matrix.renderBitmap(frame, 8, 12);
delay(1000);
mouth3();
matrix.renderBitmap(frame, 8, 12);
delay(1000);
mouth2();
matrix.renderBitmap(frame, 8, 12);
delay(500);
}
else {
leftEye();
rightEye();
nose();
mouth();
matrix.renderBitmap(frame, 8, 12);
delay(1000);
wink();
matrix.renderBitmap(frame, 8, 12);
delay(1000);
leftEye();
matrix.renderBitmap(frame, 8, 12);
delay(500);
}}
void setupwelcome(){
matrix.loadFrame(heart);
delay(1000);
matrix.loadFrame(LEDMATRIX_LIKE);
delay(1000);
matrix.beginDraw();
matrix.stroke(0xFFFFFFFF);
matrix.textScrollSpeed(50);
const char text0[] = " Super Nico ";
matrix.textFont(Font_4x6);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text0);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
leftEye();
rightEye();
nose();
mouth();
matrix.renderBitmap(frame, 8, 12);
delay(1000);
wink();
matrix.renderBitmap(frame, 8, 12);
delay(1000);
leftEye();
matrix.renderBitmap(frame, 8, 12);
delay(500);
}
void smtpCallback(SMTP_Status status);
void smtpCallback(SMTP_Status status){
Serial.println(status.info());
if (status.success()){
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failed: %d\n", status.failedCount());
Serial.println("----------------\n");
for (size_t i = 0; i < smtp.sendingResult.size(); i++){
SMTP_Result result = smtp.sendingResult.getItem(i);
ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
ESP_MAIL_PRINTF("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str());
ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients.c_str());
ESP_MAIL_PRINTF("Subject: %s\n", result.subject.c_str());
}
Serial.println("----------------\n");
smtp.sendingResult.clear();
}}
void sendstartmail(){
MailClient.networkReconnect(true);
smtp.debug(1);
smtp.callback(smtpCallback);
Session_Config config;
config.server.host_name = SMTP_HOST;
config.server.port = SMTP_PORT;
config.login.email = AUTHOR_EMAIL;
config.login.password = AUTHOR_PASSWORD;
config.login.user_domain = "";
config.time.ntp_server = F("be.pool.ntp.org");
config.time.gmt_offset = 3;
config.time.day_light_offset = 0;
SMTP_Message message;
message.sender.name = F("Arduino");
message.sender.email = AUTHOR_EMAIL;
message.subject = F("Arduino start Email");
message.addRecipient(F(" "), RECIPIENT_EMAIL);
String textMsg = "Bonne journée, je m'appelle Arduino.Je suis un Bot automatique";
message.text.content = textMsg.c_str();
message.text.charSet = "us-ascii";
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
if (!smtp.connect(&config)){
ESP_MAIL_PRINTF("Connection error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
return;
}
if (!smtp.isLoggedIn()){
Serial.println("\nNot yet logged in.");
}
else{
if (smtp.isAuthenticated())
Serial.println("\nSuccessfully logged in.");
else
Serial.println("\nConnected with no Auth.");
}
if (!MailClient.sendMail(&smtp, &message))
ESP_MAIL_PRINTF("Error, Status Code: %d, Error Code: %d, Reason: %s", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
}
void setup() {
Serial.begin(115200);
matrix.begin();
matrix.beginDraw();
matrix.stroke(0xFFFFFFFF);
matrix.textScrollSpeed(50);
const char text1[] = " Connexion **********";
matrix.textFont(Font_4x6);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text1);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
Serial.println("Connecting to: " + String(ssid));
int connectionCounter = 0;
while (status != WL_CONNECTED) {
Serial.print(".");
status = WiFi.begin(ssid, pass);
delay(250);
if ((connectionCounter % 10) == 0) {
Serial.println();
}
connectionCounter++;
}
matrix.beginDraw();
matrix.stroke(0xFFFFFFFF);
matrix.textScrollSpeed(50);
const char text2[] = " WiFi connecte";
matrix.textFont(Font_4x6);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text2);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
IPAddress ip = WiFi.localIP();
Serial.println("IP Address: " + ip.toString());
timeClient.begin();
timeClient.setTimeOffset(7200);
setupwelcome();
sendstartmail();
}
void loop(){
timebot();
}