单片机/MCUwilliam hill官网
直播中

huang5hun

9年用户 83经验值
擅长:13503
私信 关注
[问答]

ESP8266WiFi模块的问题

各位大神们们,小弟刚刚入手ESP8266WiFi模块,想将ESP8266作为客户端连接服务器,发现用串口调试助手发送命令连接服务器就可以成功,但是用51单片机给WiFi模块发送数据就一直失败!请求大神们支支招!下面是我的51单片机代码:
#include
#include

typedef unsigned int    uint;
typedef unsigned char    uchar;

void delay(uint num){
    uint i,j;
    for( i=num; i>0; i--)
        for( j=110; j>0; j--);
}

void send_to_wifi(uchar *dat,uint len){
    uint i;
    for( i=0; i         SBUF = dat[i];
        while(!ti);
        TI = 0;
    }
}

void wifi_init(void){
    uchar *temp,*read = NULL;
    uint flag = 1;
    temp = "AT+RSTn";
   
    while(flag){
        if(RI){
            *read = SBUF;
            RI = 0;
            if(*read == 'k'){
                flag = 0;
            }
        }
    }
   
   delay(100);
    send_to_wifi(temp,strlen(temp));
    delay(5000);
   
    temp = "AT+CWJAP="ashome","bugaosuni"n";
    //printf("AT+CWJAP="ashome","bugaosuni"");
    send_to_wifi(temp,strlen(temp));
   
    while(flag){
        if(RI){
            *read = SBUF;
            RI = 0;
            if(*read == 'K'){
                flag = 0;
            }
        }
    }
    flag = 1;
   
    delay(2000);
    temp = "AT+CIPSTART="TCP","192.168.0.123",8086n";
    //printf("AT+CIPSTART="TCP","192.168.0.123",8086");
    send_to_wifi(temp,strlen(temp));
   
    while(flag){
        if(RI){
            *read = SBUF;
            RI = 0;
            if(*read == 'd'){
                flag = 0;
            }
        }
    }
    flag = 1;

    delay(2000);
    temp = "AT+CIPSEND=4n";
    //printf("AT+CIPSEND=4");
    send_to_wifi(temp,strlen(temp));
   
    delay(2000);
    temp = "timen";
    //printf("time");
    send_to_wifi(temp,strlen(temp));
}

int main(void){
    TMOD = 0x20;    //设置T1的工作方式为2,自动装载   
    TH1 = 0xfd;    //设置溢出率,使波特率为9600
    TL1 = 0xfd;
    TR1 = 1;
    REN = 1;    //开启串口通讯允许
    SM0 = 0;    //设置串口工作方式为1
    SM1 = 1;
   
    delay(2000);
    wifi_init();
    while(1);   
}

回帖(2)

Nee_than

2015-10-10 11:29:15
代码写完了吗?
举报

huang5hun

2015-10-10 22:12:45
引用: Nee_than 发表于 2015-10-10 11:29
代码写完了吗?

已经写完了!已经写完了!已经写完了!已经写完了!已经写完了!已经写完了!
举报

更多回帖

发帖
×
20
完善资料,
赚取积分