1
\$\begingroup\$

I am using ARM's mbed compiler to program my STM32 Nucleo. I am also using an ESP8266 as my WiFi module.

My connections are as such:

  • Rx of the ESP8266 is connected to D8 on the Nucleo.
  • Tx of the ESP8266 is connected to D2 on the Nucleo.
  • Gnd of the ESP8266 to the gnd on the board. All other pins of the ESP8266 are connected to 3.3V on the Nucleo.

The following is my mbed code:

#include "mbed.h"  

Serial esp(D8, D2);  
DigitalOut myled(LED1);

void flush(void) {  
  while (esp.readable()) {  
    (void)esp.getc();  
  }    
}  

int main() {  
  esp.baud (115200);
  char server[]="GET /update?key=NR************2Z&field1=7";
  flush();  

  esp.printf("AT+RST\r\n");
  wait(2);  

  esp.printf("AT+CWMODE=1\r\n");  
  wait(3);  

  esp.printf("AT+CWJAP=\"Harsha\",\"*****\"\r\n"); 
  wait(3);  

  esp.printf("AT+CIPMUX=1\r\n");
  wait(3); 

  esp.printf("AT+CIPSTART=4,\"TCP\",\"184.106.153.149\",80\r\n");  
  wait(3);

  esp.printf("AT+CIPSEND=4,%d\r\n", sizeof(server)+2);  
  wait(2);

  esp.printf("%s\r\n", server); 
  wait(3);

  esp.printf("AT+CIPCLOSE\r\n"); 

  while(1) {  
    myled = 1;
    wait(0.1);

    myled = 0;
    wait(0.1);
   } 

  return 0;  
}

I am able to connect to my WiFi hotspot which means there is no problem with the connection. But the data I pass is not updated in Thingspeak at all. I have also tried it including HTTP/1.0 and HTTP/1.1 in the 'server' string, still nothing. Am I missing something?

\$\endgroup\$
  • 1
    \$\begingroup\$ How can you be sure your AT commands work? I don't see any error checking at all \$\endgroup\$ – user72833 Feb 19 '16 at 7:59
  • \$\begingroup\$ I was trying to avoid an error check with a long delay. I know its not useful but is error checking that important? I have seen other codes where AT commands are just blindly sent. \$\endgroup\$ – Harsha Feb 19 '16 at 8:00
  • \$\begingroup\$ Delays won't do anything useful if the device answers ERROR in a few msecs... \$\endgroup\$ – user72833 Feb 19 '16 at 8:02
  • \$\begingroup\$ Okay, lets assume there was an error, its still not gonna say what error it is. It means that there is something wrong with the AT commands somewhere. Thats what I want opinions for. \$\endgroup\$ – Harsha Feb 19 '16 at 8:04
  • 3
    \$\begingroup\$ Blindly sending AT commands while not reading the manual is asking for trouble. I have tried to point you in the correct direction (RTFM). I have never used this module nor do I have any intent to do so. Oddly enough, I have just had the same discussion with a customer and they would do everything to not read the manual ... while still complaining things wouldn't work. Letting other people do the debugging for you won't lead you very far. Sorry, but you have to do your homework (what is the module answering?). \$\endgroup\$ – user72833 Feb 19 '16 at 11:25
1
\$\begingroup\$

I solved it by increasing the delay for establishing the Wifi connection after the reset. For those who might find this helpful, the working code is as below:

#include "mbed.h"  

Serial esp(D8, D2);  
DigitalOut myled(LED1);

void flush(void) {  
    while (esp.readable()) {  
        (void)esp.getc();  
    }    
}

char server[]="GET /update?api_key=9FL*********C2&field2=";

int main() {  
    int x=7;
    esp.baud(115200);
    flush();  

    esp.printf("AT+RST\r\n"); /* reset module */  
    wait(2);  
    flush();  

    esp.printf("AT+CWMODE=3\r\n");  
    wait(1);  
    flush();  

    // The huge delay was key to obtaining the IP address, so that further commands don't interfere with the ongoing process
    esp.printf("AT+CWJAP=\"Harsha\",\"*******\"\r\n"); /* configure as access point */  
    wait(20);  
    flush();  

    esp.printf("AT+CIPMUX=1\r\n");
    wait(5);
    flush();  
    //response();
    esp.printf("AT+CIPSTART=0,\"TCP\",\"api.thingspeak.com\",80\r\n");  
    wait(5);
    flush();  
    //response();

    esp.printf("AT+CIPSEND=0,%d\r\n", sizeof(server)+15);  
    wait(3);
    flush();  
    //response();

    esp.printf("%s", server);
    esp.printf("%d", x);
    esp.printf(" HTTP/1.0\r\n\r\n\r\n\r\n\r\n");
    wait(2);
    flush(); 

    while(1) {  
        //To indicate completion
        myled = 1;
        wait(0.1);
        myled = 0;
        wait(0.1);
    }   
    return 0;  
}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.