Hi! I’m trying to do a Spark Core code to use the REST API from theThings.IO. I want to Post the value 0. I did this code and it compiles but it doesn’t work. Does anybody know what the problem is? I failed trying to communicate with Xively too. Help please!
#include "HttpClient/HttpClient.h"
HttpClient http;
#define THINGTOKEN "XXXXXXXX"
#define USERTOKEN "theThingsIO-Token: XXXXXXXXX"
http_header_t headers[] = {
{ "Accept", "application/json" },
{ "Authorization" , USERTOKEN },
{ "Content-Type", "application/json" },
{ NULL, NULL }
};
http_request_t request;
http_response_t response;
void setup() {
request.hostname = "api.thethings.io";
request.port = 80;
Serial.begin(9600);
}
void loop() {
request.path = "/v1/ThingWrite";
String jsonString ="{";
jsonString +="\"thing\":{";
jsonString +="\"id\":";
jsonString +=THINGTOKEN;
jsonString +="},";
jsonString +="\"values\":";
jsonString +="[";
jsonString +="{";
jsonString +="\"key\":\"air\",";
jsonString +="\"value\":";
jsonString +="0";
jsonString +="";
jsonString +="\"units\":\"lumens\",";
jsonString +="\"type\":\"temporal\"";
jsonString +="}";
jsonString +="]";
jsonString +="}";
request.body =jsonString;
http.post(request, response, headers);
Serial.println(response.status);
Serial.println(response.body);
delay(1000);
}