Networking and communications

Assignments of the Week

    Group assignment:

    Individual assignments:

      1.design, build, and connect wired or wireless node(s) with network or bus addresses.

    Group Assignment:

      Group assignment

    Individual assignments:

      "I controlled the ESP-32 to send an email to my own mailbox. In the video, the email sending is triggered by a pressure sensor. The email is sent only when I press the pressure sensor."

        Description of image

        I didn't use a pcb I made myself, I used an off-the-shelf ESP-32.

        What is ESP32?

        ESP32 is created by Espressif Systems with a series of SoC (System on a Chip) and modules which are low cost with low power consumption.

        This new ESP32 is the successor to the well-known ESP8266(became very popular with its inbuilt WiFi). ESP32 not only has Built in WiFi but also has Bluetooth and Bluetooth Low Energy. In other words we can define ESP32 as “ESP8266 on Steroids”.

        ESP32 chip ESP32-D0WDQ6 is based on a Tensilica Xtensa LX6 dual core microprocessor with an operating frequency of up to 240 MHz.

        The small ESP32 package has a high level of integrations such as:

          a. Antenna switches

          b. Balun to control RF

          c. Power amplifier

          d. Low noise reception amplifier

          e. Filters and power management modules

        On top of all that, it achieves very low power consumption through power saving features including clock synchronization and multiple modes of operation. The ESP32 chip’s quiescent current is less than 5 μA which makes it the ideal tool for your battery powered projects or IoT applications .

        Here are the differences between ESP32 and ESP8266.

        Description of image

          1.1 Below is my code and usage guidelines. If you want to use it, please refer to the following two steps.

          1.2 First, I need to add the ESP-32 runtime environment in the Arduino IDE.(https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json)

          Description of image

          1.3 Download the runtime library for ESP-32.

          Description of image

        code:

              
               #include 
                #if defined(ESP32)
                    #include 
                  #elif defined(ESP8266)
                    #include 
                  #endif
                  #include 
                  
                  #define WIFI_SSID "111"
                  #define WIFI_PASSWORD "111"
                  
                  #define SMTP_HOST "111"
                  #define SMTP_PORT 111
                  
                  #define AUTHOR_EMAIL "111"
                  #define AUTHOR_PASSWORD "111"
                  
                  #define RECIPIENT_EMAIL "111"
                  
                  SMTPSession smtp;
                  
                  void smtpCallback(SMTP_Status status);
                  
                  void setup(){
                   Serial.begin(115200);
                    Serial.println();
                    Serial.print("Connecting to AP");
                    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
                    while (WiFi.status() != WL_CONNECTED){
                    Serial.print(".");
                    Serial.println("");
                    delay(200);
                  
                    Serial.println("");
                    Serial.println("WiFi connected.");
                    Serial.println("IP address: ");
                    Serial.println(WiFi.localIP());
                    Serial.println();
                    }
                  }
                  
                  void loop(){
                    int sensorValue = analogRead(A0);
                    float voltage = sensorValue * (5.0 / 1023.0);
                    Serial.println(voltage);
                    delay(100);
                  
                    smtp.debug(1);
                    smtp.callback(smtpCallback);
                  
                    ESP_Mail_Session session;
                  
                    session.server.host_name = SMTP_HOST;
                    session.server.port = SMTP_PORT;
                    session.login.email = AUTHOR_EMAIL;
                    session.login.password = AUTHOR_PASSWORD;
                    session.login.user_domain = "";
                  
                    SMTP_Message message;
                  
                    message.sender.name = "ESP";
                    message.sender.email = AUTHOR_EMAIL;
                    message.subject = "ESP Test Email";
                    message.addRecipient("Sara", RECIPIENT_EMAIL);
                  
                  if (sensorValue > 1 ) {
                    // Send email
                      (If you want to use this code, please replace the {} symbols in the following sentence with <>, it follows the logic of web programming.)String htmlMsg = "{div style=\"color:#2f4468;\"}{h1}哈哈哈{/h1}{p}- Sent from ESP board{/p }{/div}";
                    message.html.content = htmlMsg.c_str();
                    message.html.content = htmlMsg.c_str();
                    message.text.charSet = "us-ascii";
                    message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
                    }
        
                    if (!smtp.connect(&session))
                      return;
                  
                    if (!MailClient.sendMail(&smtp, &message))
                      Serial.println("Error sending Email, " + smtp.errorReason());
                  
                  }
                  
                  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 failled: %d\n", status.failedCount());
                      Serial.println("----------------\n");
                      struct tm dt;
                  
                      for (size_t i = 0; i < smtp.sendingResult.size(); i++){
                    
                        SMTP_Result result = smtp.sendingResult.getItem(i);
                        time_t ts = (time_t)result.timestamp;
                        localtime_r(&ts, &dt);
                  
                        ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
                        ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
                        ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
                        ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients.c_str());
                        ESP_MAIL_PRINTF("Subject: %s\n", result.subject.c_str());
                      }
                      Serial.println("----------------\n");
                    }
                  }
                
            

        Downlod Links

        code

    Code introduction

      1.The necessary library to use if you want to send emails.

      Description of image

      2.WiFi network name and password.

      Description of image

      3.Configure the SMTP server.

      Description of image

      4.Set your email address and password.

      Description of image

      5.Set the recipient's email address.

      Description of image

      6.Fill in the information you want to send to the recipient.

      Description of image

      7.Wiring diagram

      7.1 There are two pins for pressure, one is connected to AO (a 10K resistor needs to be added in the middle), and the other end is connected to GND.

      Description of image

      8.The tutorial I used

      https://randomnerdtutorials.com/esp32-cam-send-photos-email/

    Error encountered

      1.Using a third-party service to send emails may result in the freezing of the email account.

    problem solving

      1.1.If you find that the email is not received, log in to the email account used in the program to unfreeze it.