[SOLVED] Can't send data using spark core

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

Hi the link says the tutorial is deprecated, have you tried the link that is suggested in the website? Particle Tutorial

Hi Hackmed

No, I haven’t. I’ll give it a go thanks a lot. Just one more quick question, do you know if the new tutorial, will work with the old cores?

Best regards
Krisly.

@Krisly you’re welcome. It should work though the problem with the old cores is that “-1” message you were getting. Sometimes they can’t resolve DNS, sometimes they suffer a memory problem and the requests start failing so a restart is needed. I would recommend making sure you have the latest firmware in the core and then try the tutorial. Let us know the result!

Hello Again

I’ve now followed the tutorial you send me @hackmed, and it worked perfect with the Photon! Thank you!!
However I’m still unable to get the older cores to work, but at least i am off and away using the Photon.

1 Like