Unable to send data to Thingspeak using ESP8266 and STM32 Nucleo
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&amp;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;  
}