Skip to content

Commit

Permalink
Fixed Arduino IoT_cloud_logging HTTP request problem
Browse files Browse the repository at this point in the history
  • Loading branch information
metriful committed Oct 14, 2020
1 parent 6e12af2 commit 392e0dc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Arduino/Examples/IoT_cloud_logging/IoT_cloud_logging.ino
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ WiFiClient client;

// Buffers for assembling http POST requests
char postBuffer[450] = {0};
char fieldBuffer[50] = {0};
char fieldBuffer[60] = {0};

// Structs for data
AirData_t airData = {0};
Expand Down Expand Up @@ -183,8 +183,9 @@ void loop() {
// Assemble the data into the required format, then send it to the
// Tago.io cloud as an HTTP POST request.
void http_POST_data_Tago_cloud(void) {
if (client.connect("api.tago.io", 80)) {
client.println("POST /data HTTP/1.1");
if (client.connect("api.tago.io", 80)) {
client.println("POST /data HTTP/1.1");
client.println("Host: api.tago.io");
client.println("Content-Type: application/json");
client.println("Device-Token: " TAGO_DEVICE_TOKEN_STRING);

Expand Down Expand Up @@ -240,7 +241,7 @@ void http_POST_data_Tago_cloud(void) {
sprintf(fieldBuffer,"Content-Length: %u",len);
client.println(fieldBuffer);
client.println();
client.println(postBuffer);
client.print(postBuffer);
}
else {
Serial.println("Connection failed");
Expand All @@ -250,8 +251,9 @@ void http_POST_data_Tago_cloud(void) {
// Assemble the data into the required format, then send it to the
// Thingspeak.com cloud as an HTTP POST request.
void http_POST_data_Thingspeak_cloud(void) {
if (client.connect("api.thingspeak.com", 80)) {
client.println("POST /update HTTP/1.1");
if (client.connect("api.thingspeak.com", 80)) {
client.println("POST /update HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("Content-Type: application/x-www-form-urlencoded");

uint8_t T_positive_integer = airData.T_C_int_with_sign & TEMPERATURE_VALUE_MASK;
Expand Down Expand Up @@ -293,7 +295,7 @@ void http_POST_data_Thingspeak_cloud(void) {
sprintf(fieldBuffer,"Content-Length: %u",len);
client.println(fieldBuffer);
client.println();
client.println(postBuffer);
client.print(postBuffer);
}
else {
Serial.println("Connection failed");
Expand Down

0 comments on commit 392e0dc

Please sign in to comment.