I need to post data from the Spark Core to my server.
The body in the POST request is 200 characters long. As soon as the size of the body increases beyond 64 characters, the core flashes red (using httpclient library).
If the body is less than 64 characters, it works fine.
How can I send 200 characters body using http POST to my server?
I don’t see anything in @nmattisson 's lbrary that has a 64 character limit. His code either takes a char array you give it or uses a 1024 char buffer internally.
Maybe you could post some of the code here and we can help you debug?
#include "application.h"
#include "HttpClient.h"
#include "HttpClient.cpp"
unsigned int i = 0;
char message[60]; // With 60 it works!!! With 65 or more it does not work - red flashes!!!!
/**
* Declaring the variables.
*/
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ "Content-Type", "application/json" },
{ "Authorization" , "Basic ZGV2aWNlX0hhbmRzY2h1aK8xOjE="},
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers with NULL
};
http_request_t request;
http_response_t response;
SYSTEM_MODE(SEMI_AUTOMATIC);
void setup() {
Serial.begin(9600);
// Request path and body can be set at runtime or at setup.
request.hostname = "api.gymneus.com";
request.port = 80;
request.path = "/V1/rawdata";
WiFi.connect();
}
void loop() {
// Creating POST body here:
sprintf(message, "[{\"startAt\":\"september\",\"sensor\":\"kingqwerty\"}]");
request.body = message;
// POST request
http.post(request, response, headers);
// Show what is posted on serial output
Serial.println(response.status);
Serial.println(response.body);
}
In this code, if the message exceeds 64 characters, the core flashes red.
@nmattisson - Yes, that could be a possibility. However, since the error (red flashes) occurs only when the value exceeds 64 characters, it is likely it is because of limit of number of characters rather than RAM.
@bko & @nmattisson:
Can you run this code on your core with message[200]?
I tried this with the message string at 100 bytes and 200 bytes and it ran for several minutes before I stopped it without errors. Maybe something in your environment around the core like routers etc. is different.
I also added this code so I could flash it over the air again:
void loop() {
int pinValue = digitalRead(D0);
if (pinValue == HIGH) {
Spark.connect();
while(true) { SPARK_WLAN_Loop(); }
}
...
@pteja, it looks like your server doesn’t respond, or the response doesn’t reach the Spark. Are GET requests working fine?
When it comes to network stability the CC3000 from TI has unfortunately not been as good as one could expect. Problems connecting to certain networks, certain routers and IP ranges have been fairly commonplace and while the situation has improved a lot since the firmware update, it’s still isn’t great.
@SebastianT - this might help you:
On your server (assuming you have access to your own server running PHP), put this PHP file - this is an echo server - echoes back whatever it gets:
Compile and put this code on the core - you need to edit the application.cpp file to match the echo server host details:
Using this I was able to make sure that there is some limit but it is much more than 64 bits.