Close

Adding WiFi

A project log for Mbed IoT testing

HW created for testing ESP8266 and ThingSpeak channels.

marko-dragoslavicMarko Dragoslavic 05/17/2016 at 16:400 Comments

ESP8266 is used to update ThingSpeak.

Sample of code to test is ESP is connected and have correct IP adrress.


Serial esp(PA_11,PA_12); 
esp.baud(115200); 
// Resetuj WiFi modul    
    pc.printf("\nReset ESP8266\n");
    esp.printf("AT+RST\r\n");
    esp_read();
    wait(1);
    pc.printf(esp_str);
// Povezi se na AP
    pc.printf("\nConnecting to AP");        
    strcpy(povezi_ap, "AT+CWJAP=\"");
    strcat(povezi_ap, ssid);
    strcat(povezi_ap, "\",\"");
    strcat(povezi_ap, pwd);
    strcat(povezi_ap, "\"\r\n"); 
    esp.printf(povezi_ap);
    esp_read();
    pc.printf(esp_str);
    wait(1);  
// Povezi se na AP        
    pc.printf("\nIP");    
    esp.printf("AT+CIFSR\r\n");
    esp_read();
    pc.printf(esp_str);
// Proveri da li se WiFi modul povezao i dobio IP adresu    
    char *datax;
    datax=strstr(esp_str, "192.");
    //pc.printf("\nPointer %i",*datax);
    if (strcmp(datax,"0" )<=0){
        sound=sound_period;
        wait(1);
        sound=0;
        myLcd.SetXY(char(1),char(1));
        myLcd.DrawString("  ERROR NO IP");       
        }
    else{
        myLcd.SetXY(char(1),char(1));
        myLcd.DrawString("   CONECTED");
        }    
    

Discussions