本期為您推送一個非常實用的迪文開發者論壇獲獎開源案例——基于T5L的smtp郵件發送器。工程師采用T5L智能屏,通過WiFi模塊訪問smtp服務器,實現了發送郵件給管理員的功能,操作時在屏幕上輸入收件人郵箱、郵件標題、郵件內容等信息即可。值得注意的是,郵件內容還支持純文本、組態控件、設置文本顏色等編輯方式。
方案簡介
方案架構
T5L智能屏通過串口5控制WiFi模塊與smtp服務器交互,實現郵件發送功能。
界面開發
DGUS軟件通過圖層疊加來完成顯示和觸控功能開發,用戶只需要把準備好的圖片素材加載到DGUS軟件,設置好顯示和觸控功能即可。
C51軟件設計
T5L智能屏串口5與WiFi模塊通訊,完成與smtp服務器交互。完整代碼請參考源碼工程,部分主要代碼如下:
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
{
SBUF3_TX = bytes;
while(!(SCON3T&0x01));
SCON3T &= 0xfe;
}
}
void get_input(u8 * val,u8 len)
{
u8 i;
for(i=0;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,"Click
value='good'>\0\0",30);
else if(btn_val2==3)
sys_write_vp(0x3060,"
Bold
Red
\0\0",30);
old_val = btn_val2;}
-
服務器
+關注
關注
12文章
9160瀏覽量
85421 -
開源
+關注
關注
3文章
3349瀏覽量
42500 -
發送器
+關注
關注
1文章
259瀏覽量
26822
發布評論請先 登錄
相關推薦
評論