nasrullah nasrullah / Mbed 2 deprecated Nucleo_printf

Dependencies:   mbed

main.cpp

Committer:
nasrullah
Date:
2015-12-27
Revision:
2:01696b00d551
Parent:
1:e9d1c42a73ae

File content as of revision 2:01696b00d551:

#include "mbed.h"
#include <string>

Serial pc(USBTX, USBRX);
Serial esp(PA_9,PA_10);


Timer t;
 
int  count,ended,timeout;
char buf[1024];
char snd[255];

void getreply(),SendCMD();

int main()
{

//int a=34;
//int cm=1;
//int mode=1;
//int port=333;

//char ssid[10]="reborn",psd[15]="sempakkoyak";
esp.baud(115200);
pc.baud(115200);
//pc.puts("Hi! this uses type anytihing\r\n");
//esp.printf("%s\r\n");
//esp.printf("AT+RST\r\n");
//wait(10);
//esp.printf("AT\r\n");
//wait(2);
//esp.printf("AT+CWMODE=3\r\n");
//wait(2);
//esp.printf("AT+CWJAP=%c%s%c,%c%s%c\r\n",a,ssid,a,a,psd,a);
//wait(10);
//esp.printf("AT+CIPMUX=%i\r\n",cm);
//wait(5);
//esp.printf("AT+CIPSERVER=%i,%i\r\n",mode,port);
//wait(10);
        strcpy(snd,"AT+CWLAP\r\n");
        SendCMD();
      
        //wait(5);
        //strcpy(snd,"AT+CWLAP\r\n");
       // SendCMD();
        //timeout=3;
        //wait(10);
       // getreply();  
       // pc.printf(buf);
while(1) 
{       
        
        
        timeout=3;
        getreply();  
        pc.printf(buf);
      
}
 
}

void SendCMD()
{    
    esp.printf("%s", snd);    
} 

void getreply()
{    
    memset(buf, '\0', sizeof(buf));
    t.start();
    ended=0;count=0;
    while(!ended) {
        if(esp.readable()) {
            buf[count] = esp.getc();count++;
            }
        if(t.read() > timeout) {
                ended = 1;t.stop();t.reset();
            }
        }   
}