——来自迪文开发者论坛
本期为您推送一个非常实用的迪文开发者论坛获奖开源案例——基于T5L的smtp邮件发送器,工程师采用T5L,通过WiFi模块访问smtp服务器,实现了发送邮件给管理员的功能,操作时在屏幕上输入收件人邮箱、邮件标题、邮件内容等信息即可。值得注意的是,邮件内容还支持纯文本、组态控件、设置文本颜色等编辑方式。
【演示视频】
完整开发资料含迪文屏DGUS工程资料与代码,可前往迪文开发者论坛获取:/index.html/forum.php?mod=viewthread&tid=8932
1.方案架构
T5L智能屏通过串口5控制WiFi模块与smtp服务器交互,实现邮件发送功能。
2.界面开发
DGUS软件通过图层叠加来完成显示和触控功能开发,用户只需要把准备好的图片素材加载到DGUS软件,设置好显示和触控功能即可。
3.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<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;
}
上一篇:【开源获奖案例】水泥多量测定仪