我一直在为我的粒子光子代码尝试很长时间,以从我的Raspberry Pi网络主机上获取一个项目的json。 http://10.1.41.3:5000/
它具有MBTA巴士到达信息,我希望我的光子获取json并将其发布到光子控制台中。这是我的代码。
// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>
#include "application.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" , "*/*"},
{ "User-agent", "Particle HttpClient"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
}
void loop() {
if (nextTime > millis()) {
return;
}
Particle.publish("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "10.1.41.3";
request.port=5000;
//request.path=":5000";
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
String r=String(response.status);
// Get request
http.get(request, response, headers);
Particle.publish("Application>\tResponse status: ");
Particle.publish(r);
Particle.publish("Application>\tHTTP Response Body: ");
Particle.publish(response.body);
nextTime = millis() + 10000;
}
我做错了什么?我希望光子获取整个json列表并将其发布。端口是5000