— . . - , , esp8266
,
, , . , - , , -, , , , ? .
, , , , . . (- e-mail).
, .
, esp8266
, , . esp8266, , , , . 3-5 . WI- FI .
#include <ESP8266WiFi.h>
#include "Gsender.h"
#pragma region Globals
const char* ssid = "HomeWIFI"; //
const char* password = ""; //
const char* letter_message = "! , "
"2 "
" ==== 19 . . ====== +7909=====";
uint8_t connection_state = 0;
uint16_t reconnect_interval = 10000; // - 10
#pragma endregion Globals
uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
{
static uint16_t attempt = 0;
Serial.print("Connecting to ");
if(nSSID) {
WiFi.begin(nSSID, nPassword);
Serial.println(nSSID);
} else {
WiFi.begin(ssid, password);
Serial.println(ssid);
}
uint8_t i = 0;
while(WiFi.status()!= WL_CONNECTED && i++ < 50)
{
delay(200);
Serial.print(".");
}
++attempt;
Serial.println("");
if(i == 51) {
Serial.print("Connection: TIMEOUT on attempt: ");
Serial.println(attempt);
if(attempt % 2 == 0)
Serial.println("Check if access point available or SSID and Password\r\n");
return false;
}
Serial.println("Connection: ESTABLISHED");
Serial.print("Got IP address: ");
Serial.println(WiFi.localIP());
return true;
}
void Awaits()
{
uint32_t ts = millis();
while(!connection_state)
{
delay(50);
if(millis() > (ts + reconnect_interval) && !connection_state){
connection_state = WiFiConnect();
ts = millis();
}
}
}
void setup()
{
pinMode(5, OUTPUT);
Serial.begin(115200);
connection_state = WiFiConnect();
if(!connection_state) // if not connected to WIFI
Awaits(); // constantly trying to connect
Gsender *gsender = Gsender::Instance(); // Getting pointer to class instance
String subject = " ";
if(gsender->Subject(subject)->Send("water*****@mail.ru", letter_message)) {
Serial.println("Message send.");
digitalWrite(5, HIGH); // -
} else {
Serial.print("Error sending message: ");
Serial.println(gsender->getError());
}
}
void loop(){}
. ,
.
Gsender.h,
. , gmail, . , base64 . , ,
. - .
const char* EMAILBASE64_LOGIN = "Y29zbWkxMTExMUBnbWFpbC5jb20=";<br>const char* EMAILBASE64_PASSWORD = "TGFzZGFzZDEyMzI=";
, GMAIL . .
. .
1000 , .. 10. , , , .
, -. , , , «» . — - . . , ,
IFTTT.
!