SparkCore --> ThingSpeak - HTTP Get Problems | Particle / Spark | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
SparkCore --> ThingSpeak - HTTP Get Problems
Avatar
cuperman007
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
1
February 13, 2015 - 3:04 am
sp_Permalink sp_Print

Hi All,

I've recently purchased a couple of SparkCores that I want to communicate with each other via ThingSpeak.

I have one Core that is writing a value to a channel - all is good with this.

My other Core needs to read from that channel and then react. Should be simples, but my Core is not GETting the same data as my browser. I am using the ThingSpeak IP number to eliminate any potential DNS issues.

My channel field GET is: http://184.106.153.149/channels/24587/fields/1/last

This is currently resulting a simple "2" when requested via a browser (or POSTMAN) but on my Core the result is a 400:

============================
Application>.Start of Loop.
HttpClient>.Connecting to IP: 184.106.153.149:80
HttpClient>.Start of HTTP Request.
GET channels/24587/field/1.json HTTP/1.0
Connection: close
Accept: */*
HttpClient>.End of HTTP Request.

HttpClient>.Receiving TCP transaction of 128 bytes.
HTTP/1.1 400 Bad Request
Server: nginx/1.7.5
Date: Mon, 09 Feb 2015 20:54:50 GMT
Content-Type: text/html
Content-Length: 172
Connection: close

400 Bad Request

400 Bad Request


nginx/1.7.5

HttpClient>.End of TCP transaction.
HttpClient>.Error: Timeout while reading response.

HttpClient>.End of HTTP Response (5423ms).
HttpClient>.Status Code: 400
----------------------------------Application>.Response status: 400
----------------------------------Application>.HTTP Response Body:
400 Bad Request

400 Bad Request


nginx/1.7.5

============================

My SparkCore sketch uses the HttpClient from the Spark library:

//============================
// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"

/**
* Declaring the variables.
*/
unsigned int nextTime = 0; // Next time to contact the server
HttpClient http;

// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
// { "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};

http_request_t request;
http_response_t response;

// thing speak api IP
IPAddress server(184,106,153,149);

void setup() {
Serial.begin(9600);
}

void loop() {
if (nextTime > millis()) {
return;
}

Serial.println();
Serial.println("============================");
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.ip = server;
//request.hostname = "www.timeapi.org";
request.port = 80;
//request.path = "channels/24587/fields/1/last";
request.path = "channels/24587/field/1.json";

// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";

// Get request
http.get(request, response, headers);

Serial.println("----------------------------------");
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);

Serial.println("----------------------------------");
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);

nextTime = millis() + 10000;
}
//============================

I've been playing with this for a couple of weeks now trying to get a working solutio, but no dice.

Any help gratefully received.

Avatar
cuperman007
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
2
February 13, 2015 - 3:59 pm
sp_Permalink sp_Print

The problem has been found...
Missing "/" at the start of the path.

request.path = "/channels/24587/field/1.json";

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
29 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

dannymm1

KamorkasOr

GRV2903

Jusikaclaiz

Raymondpoers

ScottDus

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee