![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is a SLIP interface for the STM32F446RE Nucleo Board. It is designed to work specifically with the esp-link software for the ESP8266. The program is an example of a rest command.
Diff: main.cpp
- Revision:
- 1:99c58a942425
- Parent:
- 0:70a6082c1bf7
- Child:
- 2:20ea1be14e4b
--- a/main.cpp Thu Jul 14 20:38:18 2016 +0000 +++ b/main.cpp Thu Jul 28 02:46:43 2016 +0000 @@ -48,9 +48,10 @@ } } -#define BUFLEN 266 +#define BUFLEN 512 + char response[BUFLEN]; -int loop() { +char *loop_get() { //debugSerial.printf("begin main loop \n\r"); // process any callbacks coming from esp_link esp.Process(); @@ -60,21 +61,48 @@ // Request /utc/now from the previously set-up server rest.get("/utc/now"); - char response[BUFLEN]; + //char response[BUFLEN]; memset(response, 0, BUFLEN); uint16_t code = rest.waitResponse(response, BUFLEN); if(code == HTTP_STATUS_OK){ debugSerial.printf("STM: GET successful: %s\n\r", response); + wait(60); + return response; } else { debugSerial.printf("STM: GET failed: %i\n\r",code); + wait(60); + return (char *)code; + } + } + return "0"; +} + +int loop_post() { + //debugSerial.printf("begin main loop \n\r"); + // process any callbacks coming from esp_link + esp.Process(); + debugSerial.printf("Wifi Connected: %i \n\r",wifiConnected); + // if we're connected make an HTTP request + while(wifiConnected) { + // Post to cloud + //rest.post("/post.php", "{sunleaf: test1}"); + + rest.post("/hummingbirdqueue/messages", "{sunleaf: test1}"); + char response[BUFLEN]; + memset(response, 0, BUFLEN); + uint16_t code = rest.waitResponse(response, BUFLEN); + if(code == HTTP_STATUS_OK){ + debugSerial.printf("STM: POST successful: %s\n\r", response); + } else { + debugSerial.printf("STM: POST failed: %i\n\r",code); return code; } - wait(1); + wait(60); } - return 0; - + return 0; } + int main() { led1=0; debugSerial.baud(115200); // the baud rate here needs to match the esp-link config @@ -111,7 +139,7 @@ { //debugSerial.printf("Wifi status: %i\n\r", packet->value); //debugSerial.printf("waiting for wifi status...\n\r"); - if(packet->value == 2) { ///ideally this would coincide with STATION_GOT_IP... + if(packet->value >= 1) { ///ideally this would coincide with STATION_GOT_IP... debugSerial.printf("WIFI CONNECTED\n\r"); wifiConnected = true; } else { @@ -124,16 +152,21 @@ // Set up the REST client to talk to www.timeapi.org, this doesn't connect to that server, // it just sets-up stuff on the esp-link side - int err = rest.begin("www.timeapi.org"); + //int err = rest.begin("www.timeapi.org"); + //int err = rest.begin("posttestserver.com"); + const char* host = "vivaplanetbusservicedev.servicebus.windows.net"; + uint16_t port = 443; + + int err = rest.begin(); if (err != 0) { debugSerial.printf("REST begin failed: %i\n\r",err); while(1) ; } debugSerial.printf("STM-REST ready\n\r"); - int loopStat = 0; - while(loopStat == 0){ - debugSerial.printf("status: %i\n\r",loopStat); - loopStat = loop(); - wait(1); + while(response != "0"){ + debugSerial.printf("status: %i\n\r",response); + //loop_get(); + loop_post(); + wait(60); } } \ No newline at end of file