Hello Everyone
I have this little problem, where I am unable to send data to Ubidot using a spark core.
I have tried to follow every step in this tutorial:
http://ubidots.com/docs/devices/spark.html
But all i get is a value of “-1” from Serial.println(response.status);
and nothing from Serial.println(response.body);
.
I tried my self to add the line request.hostname = "things.ubidots.com";
, giving me following end result:
#include "HttpClient/HttpClient.h"
//#include "dnsclient/dnsclient.h" // Add this library if your Spark is having problems with DNS
#define VARIABLE_ID "My variable ID"
#define TOKEN "My Token"
HttpClient http;
float lightLevel = 0;
char resultstr[64];
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
//{ "Host", "things.ubidots.com" }, // Declare the host here if your Spark has DNS problems
{ "Content-Type", "application/json" },
{ "X-Auth-Token" , TOKEN },
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
//Uncomment these lines if your Spark is having problems with DNS resolution:
// ------------------------DNS-FIX--------------------------------------------
//IPAddress dnsServerIP(8,8,8,8);
//IPAddress remote_addr;
//DNSClient dns;
//char serverName[] = "things.ubidots.com";
// ---------------------------------------------------------------------------
void setup() {
pinMode(A0, INPUT);
request.port = 80;
// dns.begin(dnsServerIP); // Uncomment if having DNS problems
// dns.getHostByName(serverName, remote_addr); // Uncomment if having DNS problems
// request.ip = remote_addr; // Uncomment if having DNS problems
request.hostname = "things.ubidots.com";
request.path = "/api/v1.6/variables/"VARIABLE_ID"/values";
Serial.begin(9600);
}
void loop() {
// Get variable
lightLevel = analogRead(A0);
// Send to Ubidots
sprintf(resultstr, "{\"value\":%.4f}", lightLevel);
request.body = resultstr;
http.post(request, response, headers);
Serial.println(response.status);
Serial.println(response.body);
delay(1000);
}
Can anybody tell me what I’m doing wrong?
Kind Regards
Kristoffer