Estoy usando el compilador mbed de ARM para programar mi STM32 Nucleo. También estoy usando un ESP8266 como mi módulo WiFi.
Mis conexiones son así:
El siguiente es mi código mbed:
#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;
}
Puedo conectarme a mi punto de acceso WiFi, lo que significa que no hay problema con la conexión. Pero los datos que paso no se actualizan en Thingspeak en absoluto. También lo probé incluyendo HTTP/1.0 y HTTP/1.1 en la cadena 'servidor', todavía nada. ¿Me estoy perdiendo de algo?
Lo resolví aumentando la demora para establecer la conexión Wifi después del reinicio. Para aquellos que puedan encontrar esto útil, el código de trabajo es el siguiente:
#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;
}
usuario72833
Harsha
usuario72833
Harsha
usuario72833
Harsha
usuario72833
CrisR