Introduction:
In the realm of digital input monitoring and notifications, precision and timeliness are paramount. Enter the ESP32-Based Digital Input Monitoring and Email Notification System. Seamlessly integrating advanced microcontroller capabilities with robust communication protocols, this system offers unparalleled efficiency in monitoring and alerting.
Components Used:
- ESP32: Microcontroller for handling the communication and logic.
- RS485 MAX: RS485 transceiver for serial communication.
- 4DI 4DO TO RS485 Module: Module for interfacing digital inputs and outputs with RS485 communication.
Pin Connections:
1. ESP32 to RS485 :
– GPIO19 to DE (Driver Enable)
– GPIO18 to RE (Receiver Enable)
– GPIO17 to DI (Data In)
– GPIO16 to RO (Receive Out)
– V5 to VCC
– GND to GND
2. RS485 to 4DI 4DO TO RS485 Module :
– A to A
– B to B
3. Digital Inputs to 4DI 4DO TO RS485 Module :
– Digital Input Power (+) to D1 (Digital Input 1)
– Digital Input Power (-) to C (Digital Input Common)
Exploring the Components :
The system leverages cutting-edge components including the ESP32 microcontroller, RS485 transceiver, and the 4DI 4DO TO RS485 Module. With each component meticulously selected for optimal performance, reliability is guaranteed.
Unraveling the Workflow :
From initialization to email transmission, the system orchestrates a fluid workflow. Through a series of meticulously crafted steps, it establishes WiFi connectivity, configures email settings, and diligently monitors digital input statuses.
Firmware :
#include <Arduino.h>
#include <ModbusMaster.h>
#include <WiFi.h>
#include <ESP_Mail_Client.h>
#include <WiFiClientSecure.h>
#define DE_PIN 19
#define RE_PIN 18
#define MODBUS_ID 1
void postTransmission()
{
digitalWrite(RE_PIN, LOW);
digitalWrite(DE_PIN, LOW);
}
void preTransmission()
{
digitalWrite(RE_PIN, HIGH);
digitalWrite(DE_PIN, HIGH);
}
#define WIFI_SSID “your_ssid”
#define WIFI_PASSWORD “your_password”
#define SMTP_server “smtp.gmail.com”
#define SMTP_Port 465
#define sender_email “your_mail”
#define sender_password “your_password”
#define Recipient_email “receiver_mail”
#define Recipient_name “receiver_name”
ModbusMaster node;
SMTPSession smtp;
ESP_Mail_Session session;
bool initialD1State = false;
bool initialEmailSent = false;
void setupWiFi();
void setupEmail();
void sendMail(const char* subject, const char* content);
void checkAndSendEmail();
void setup()
{
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1);
node.begin(MODBUS_ID, Serial2);
pinMode(DE_PIN, OUTPUT);
pinMode(RE_PIN, OUTPUT);
digitalWrite(RE_PIN, LOW);
digitalWrite(DE_PIN, LOW);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
setupWiFi();
setupEmail();
}
void loop()
{
checkAndSendEmail();
delay(1000);
}
void setupWiFi()
{
Serial.print(“Connecting to WiFi…”);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(“.”);
delay(200);
}
Serial.println(“\nWiFi connected.”);
}
void setupEmail()
{
smtp.debug(1);
session.server.host_name = SMTP_server;
session.server.port = SMTP_Port;
session.login.email = sender_email;
session.login.password = sender_password;
session.login.user_domain = “”;
}
void sendMail(const char* subject, const char* content)
{
SMTP_Message message;
message.sender.name = “ESP32”;
message.sender.email = sender_email;
message.subject = subject;
message.addRecipient(Recipient_name, Recipient_email);
message.text.content = content;
message.text.charSet = “us-ascii”;
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
if (!smtp.connect(&session))
{
Serial.println(“Failed to connect to SMTP server.”);
return;
}
if (!MailClient.sendMail(&smtp, &message))
{
Serial.println(“Error sending Email: ” + smtp.errorReason());
}
else
{
Serial.println(“Email sent successfully.”);
}
}
void checkAndSendEmail()
{
uint8_t result;
bool coilStatus;
static bool previousStatus = true;
Serial.println(“Reading…”);
result = node.readDiscreteInputs(1000, 1);
if (result == node.ku8MBSuccess)
{
coilStatus = node.getResponseBuffer(0);
if (!coilStatus && previousStatus)
{
Serial.println(“Digital input D1 is OFF. Sending email…”);
sendMail(“Alert”, “The digital input D1 is OFF. Please check the system.”);
previousStatus = false;
}
else if (coilStatus && !previousStatus)
{
Serial.println(“Digital input D1 is ON. Sending email…”);
sendMail(“Status Update”, “The digital input D1 is now ON.”);
previousStatus = true;
}
}
else
{
Serial.println(“Failed to read digital inputs”);
Serial.println(result, HEX);
}
}
Serial Monitor :
When Device(D1) is OFF :
………………
WiFi connected.
Reading…
Reading…
Digital input D1 is OFF. Sending email…
> C: ESP Mail Client v3.4.15
! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
> C: connecting to SMTP server
> C: Host > smtp.gmail.com
> C: Port > 465
> C: SMTP server connected, wait for greeting…
< S: 220 smtp.gmail.com ESMTP r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: send SMTP command, EHLO
< S: 250-smtp.gmail.com at your service, [106.198.84.63]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8
> C: send SMTP command, AUTH PLAIN
> C: akilans26224@gmail.com
> C: *******************
< S: 235 2.7.0 Accepted
! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
> C: send Email
> C: send message header
< S: 250 2.1.0 OK r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
< S: 250 2.1.5 OK r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: send message body
< S: 354 Go ahead r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: finishing the message sending
< S: 250 2.0.0 OK 1709275982 r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: terminate the SMTP session
< S: 221 2.0.0 closing connection r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: message sent successfully
Email sent successfully.
Reading…
Reading…
Reading…
Reading…
Reading…
> C: send SMTP command, AUTH PLAIN
> C: sender_mail@gmail.com
> C: *******************
< S: 235 2.7.0 Accepted
! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
> C: send Email
> C: send message header
< S: 250 2.1.0 OK r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
< S: 250 2.1.5 OK r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: send message body
< S: 354 Go ahead r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: finishing the message sending
< S: 250 2.0.0 OK 1709275982 r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: terminate the SMTP session
< S: 221 2.0.0 closing connection r15-20020a17090a0acf00b00299332505d7sm2764896pje.26 – gsmtp
> C: message sent successfully
Email sent successfully.
Reading…
Reading…
Reading…
When Device(D1) is ON :
Reading…
Reading…
Digital input D1 is ON. Sending email…
> C: ESP Mail Client v3.4.15
! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
> C: connecting to SMTP server
> C: Host > smtp.gmail.com
> C: Port > 465
> C: SMTP server connected, wait for greeting…
< S: 220 smtp.gmail.com ESMTP y6-20020a170902700600b001dcc2951c02sm2634468plk.286 – gsmtp
> C: send SMTP command, EHLO
< S: 250-smtp.gmail.com at your service, [106.198.84.63]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8
> C: send next Email
> C: sender_mail@gmail.com
> C: *******************
< S: 235 2.7.0 Accepted
! E: library or device time was not set, see examples/SMTP/Set_Time.ino for manually time setting
> C: send next Email
> C: send message header
< S: 250 2.1.0 OK y6-20020a170902700600b001dcc2951c02sm2634468plk.286 – gsmtp
< S: 250 2.1.5 OK y6-20020a170902700600b001dcc2951c02sm2634468plk.286 – gsmtp
> C: send message body
< S: 354 Go ahead y6-20020a170902700600b001dcc2951c02sm2634468plk.286 – gsmtp
> C: finishing the message sending
< S: 250 2.0.0 OK 1709276038 y6-20020a170902700600b001dcc2951c02sm2634468plk.286 – gsmtp
> C: terminate the SMTP session
< S: 221 2.0.0 closing connection y6-20020a170902700600b001dcc2951c02sm2634468plk.286 – gsmtp
> C: message sent successfully
Email sent successfully.
Reading…
Reading…
Reading…
Reading…
Received Mail :
Firmware Features :
– Uses Modbus protocol via RS485 for communication.
– Sets up WiFi connection for sending email notifications.
– Sends email notifications using SMTP protocol.
– Checks the status of D1 periodically and sends email notifications accordingly.
Setup :
Empowering users with unparalleled flexibility, the system allows for seamless configuration of WiFi and email server credentials. With a straightforward setup process, users can swiftly integrate the system into their workflow with ease.
Conclusion – Igniting a Revolution :
In a landscape defined by digital intricacies and constant connectivity, the ESP32-Based Digital Input Monitoring and Email Notification System emerges as a beacon of innovation. With its unparalleled efficiency, reliability, and adaptability, it redefines the standards of digital monitoring and notification systems. Embrace the future of monitoring. Embrace excellence.
For Potential Clients :
Are you looking for a comprehensive solution to manage digital inputs and receive timely notifications? Our ESP32-Based Digital Input Monitoring and Email Notification System offers unmatched precision and reliability. Whether you’re in industrial automation, home security, or any other field requiring real-time monitoring, our system ensures you stay informed and in control. Contact us today to learn more about how this innovative solution can revolutionize your operations.