Open source T5L-based SMTP Mailer

This issue for you to push a very practical Diwen Developer Forum award-winning open source case - T5L-based smtp mail sender , engineers use the T5L smart screen , through the WiFi module to access the smtp server , to achieve the function of sending emails to the administrator , the operation of the screen to enter the recipient's email address , email title, email content and other information can be input on the screen. It is worth noting that the email content also supports plain text, configuration controls, setting text colour and other editing methods.

1.Programme Architecture

T5L smart screen controls the WiFi module to interact with smtp server through serial port 5 to achieve the function of email sending.

ava (1)

2.Interface Development

DGUS software completes the development of display and touch functions through the superposition of layers. Users only need to load the prepared picture materials into DGUS software and set up the display and touch functions.

ava (2)

1. C51 Software Design

T5L smart screen serial port 5 communicates with WiFi module to complete the interaction with smtp server. Part of the main code is as follows:

void uart5_init(u32 baud)

{

SCON3T = 0x80;

SCON3R = 0x80;

baud = (u32)((double)(FOSC/8.0)/baud);

BODE3_DIV_H = (baud>>8)&0xff;

BODE3_DIV_L = baud&0xff;

ES3R = 0;

ES3T = 0;

}

void u5_send_byte(u8 byte)

{

SBUF3_TX = byte;

while(!(SCON3T&0x01));

SCON3T &= 0xfe;

}

void u5_send_bytes(u8 *bytes,u16 len)

{

u16 i;

for(i=0;i<len;i++)

{

SBUF3_TX = bytes;

while(!(SCON3T&0x01));

SCON3T &= 0xfe;

}

}

void get_input(u8 * val,u8 len)

{

u8 i;

for(i=0;i<len;i++)

{

if(val==0xff)

{

val = 0x00;

val[i+1] = 0x00;

return;

}

}

}

u8 esp8266_send_cmd(u8 *cmd,u8 *ack,u16 waittime,u8 clearBuffer)

{

u8 res=0;

rx_sta=0;

if(ack&&waittime&&cmd)

{

while(--waittime)

{

sys_delay_ms(10);

if(rx_sta&0X8000)

{

if(esp8266_check_respond(ack))

break;

}

}

if(waittime==0)res=1;

if(clearBuffer==1)rx_sta=0;

}

return res;

}

typedef struct{

u8 cmd;

u8 email[20];

u8 name[20];

u8 title[20];

u8 msg[60];

}EMAIL_INFO;

EMAIL_INFO email_info;

u8 respond[80];

u8 wifi_name[30];

u8 wifi_passwd[30];

u8 server[30];

u8 port[30];

u8 username[30];

u8 auth_code[30];

u8 rx_sta;

sys_read_vp(0x1000,(u8*)&btn_val,1);

if(btn_val)

{

if(btn_val==1)

{

sys_read_vp(0x3000,email_info.name,10);

sys_read_vp(0x3020,email_info.email,10);

sys_read_vp(0x3040,email_info.title,10);

sys_read_vp(0x3060,email_info.msg,30);

get_input(email_info.name,20);

get_input(email_info.email,20);

get_input(email_info.title,20);

get_input(email_info.msg,60);

send_packet((u8*)&email_info,sizeof(EMAIL_INFO));

if(rx_sta)

send_mail(email_info.email,email_info.title,email_info.msg);

}else if(btn_val==2)

{

sys_read_vp(0x3100,wifi_name,15);

sys_read_vp(0x3120,wifi_passwd,15);

get_input(wifi_name,30);

get_input(wifi_passwd,30);

}else if(btn_val==3)

{

sys_read_vp(0x3200,server,15);

sys_read_vp(0x3220,port,15);

sys_read_vp(0x3240,username,15);

sys_read_vp(0x3260,auth_code,15);

get_input(server,30);

get_input(port,30);

get_input(username,30);

get_input(auth_code,30);

}

 

btn_val = 0;

sys_write_vp(0x1000,(u8*)&btn_val,1);

}

sys_read_vp(0x2050,(u8*)&btn_val2,1);

if(btn_val2!=old_val)

{

if(btn_val2==1)

sys_write_vp(0x3060,"This is a email from T5L!\0\0",30);

else if(btn_val2==2)

sys_write_vp(0x3060,"<button>Click</button><br><br><input value='good'>\0\0",30);

else if(btn_val2==3)

sys_write_vp(0x3060,"<h3>Bold</h3><h1 style='color:red;'>Red</h1>\0\0",30);

old_val = btn_val2;

}


Post time: Oct-31-2023