Клиентский код HTTP не получает JSON от моего малинового Pi Webhost - PullRequest
0 голосов
/ 21 ноября 2018

Я долго пытался, чтобы мой фотонный код частиц получил json от моего веб-хостинга Raspberry Pi для проекта.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

...