Arduino ESP8266 ESP32 PHP E-mail (Mailer) Event

Email event notifier


Event notifier sends emails via php page to your mail in case of critical or important information. The system can be used to send emails for situations:
  • Motion at night around the PIR sensor - suitable for premises, halls
  • Heating sensor - suitable for laundry, flats
  • Temperature sensors - Minus temperature message - Suitable for kits
  • Humidity, air pressure overheating - suitable for weather stations
  • Engine Speed ​​Overrun - Hall Magnet Sensor
  • Overvoltage / current overcurrent
  • and other measurable variables
  • The notifiers task is therefore to provide a brief report on the status of the household / room / workplace and to inform about the defaults immediately. Due to the low data rate (a few bytes), it is also possible to use a 3G router with a data rate to connect the ESP or Arduino and to send additional information, such as the current temperature, etc.

    Motion sensor for night-time security - silent alarm:

                

    Temperature sensor - use in set:

    Flooding:

    Action on flooding event


    Arduino + Ethernet W5100


    #include <SPI.h>
    #include <Ethernet.h>
    #define Hostname "Arduino"   
    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};    
    char server[] = "www.mywebsite.com";      
    IPAddress ip(192, 168, 1, 254); //IP adresa zo subnet rozsahu
    EthernetClient client;   
    void setup() {
     Serial.begin(9600);
    }
     
    void loop() {
       if (Ethernet.begin(mac) == 0) {    
        Serial.println("Chyba konfiguracie DHCP, nastavim manualnu IPv4"); 
        Ethernet.begin(mac, ip);                       
      }  
    
    
    if (client.connect(server, 80)) { 
        Serial.println("Pripojenie na webserver prebehlo uspesne.."); 
        client.print("GET /email.php");   //umiestnenie php scriptu na webserveri  
        client.println(" HTTP/1.1");              
        client.println("Host: www.mywebsite.com");
        client.println("Connection: close");    
        client.println();                       
     client.stop();    
     Serial.println("E-mail uspesne odoslany!"); 
      } else {                                          
        Serial.println("Pripojenie neuspesne"); 
      }  
    delay(10000);
    }
    			

    Arduino + Ethernet W5200-W5500


    #include <SPI.h>
    #include <Ethernet2.h>
    #define Hostname "Arduino"   
    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};    
    char server[] = "www.mywebsite.com";      
    IPAddress ip(192, 168, 1, 254); //IP adresa zo subnet rozsahu
    EthernetClient client;   
    void setup() {
     Serial.begin(9600);
    }
     
    void loop() {
       if (Ethernet.begin(mac) == 0) {    
        Serial.println("Chyba konfiguracie DHCP, nastavim manualnu IPv4"); 
        Ethernet.begin(mac, ip);                       
      }  
    
    
    if (client.connect(server, 80)) { 
        Serial.println("Pripojenie na webserver prebehlo uspesne.."); 
        client.print("GET /email.php");   //umiestnenie php scriptu na webserveri  
        client.println(" HTTP/1.1");              
        client.println("Host: www.mywebsite.com");
        client.println("Connection: close");    
        client.println();                       
     client.stop();    
     Serial.println("E-mail uspesne odoslany!"); 
      } else {                                          
        Serial.println("Pripojenie neuspesne"); 
      }  
    delay(10000);
    }
    			

    NodeMCU - ESP8266


    #include <ESP8266WiFi.h>
    #include <WiFiClientSecure.h>
    
    const char* ssid = "wifimeno";
    const char* password = "wifiheslo";
    
    const char* host = "mojweb.xxx";
    const int httpsPort = 443;
    const char fingerprint[] PROGMEM = "b0 6d 7f 8c 98 78 8e 6e 0a 57 a8 2f 7e d1 40 2a 1e 3f 48 f7";
    
    void setup() {
      Serial.begin(9600);
      Serial.println();
      Serial.print("connecting to ");
      Serial.println(ssid);
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    }
    
    void loop() {
      WiFiClientSecure client;
      Serial.printf("Using fingerprint '%s'\n", fingerprint);
      client.setFingerprint(fingerprint);
      Serial.print("connecting to ");
      Serial.println(host);
      if (client.connect(host, httpsPort)) {
        String url = "/email.php";
        Serial.print("requesting URL: ");
        Serial.println(url);
        client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                     "Host: " + host + "\r\n" +
                     "User-Agent: BuildFailureDetectorESP8266\r\n" +
                     "Connection: close\r\n\r\n");
      }
      delay(10000);
    }
    

    PHP e-mail sender


       <?php
    $sprava= "Ahoj svet!";
    $sprava= wordwrap($msg,70);
    mail("adresaprijimatela@jehomail.com","Hello",$sprava);
    ?>