HTTP client Particle code not getting json from my raspberry Pi Webhost












0















Ive been trying fro a long time for my particle photon code to get the json from my Raspberry Pi web host for a project. http://10.1.41.3:5000/



it has MBTA bus arrival information and I want my photon to get the json and publish it into the photon console. Here is my code.



    // 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;
}


What have i done wrong? I want the photon to get the whole json list and publish it. The port is 5000










share|improve this question



























    0















    Ive been trying fro a long time for my particle photon code to get the json from my Raspberry Pi web host for a project. http://10.1.41.3:5000/



    it has MBTA bus arrival information and I want my photon to get the json and publish it into the photon console. Here is my code.



        // 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;
    }


    What have i done wrong? I want the photon to get the whole json list and publish it. The port is 5000










    share|improve this question

























      0












      0








      0








      Ive been trying fro a long time for my particle photon code to get the json from my Raspberry Pi web host for a project. http://10.1.41.3:5000/



      it has MBTA bus arrival information and I want my photon to get the json and publish it into the photon console. Here is my code.



          // 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;
      }


      What have i done wrong? I want the photon to get the whole json list and publish it. The port is 5000










      share|improve this question














      Ive been trying fro a long time for my particle photon code to get the json from my Raspberry Pi web host for a project. http://10.1.41.3:5000/



      it has MBTA bus arrival information and I want my photon to get the json and publish it into the photon console. Here is my code.



          // 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;
      }


      What have i done wrong? I want the photon to get the whole json list and publish it. The port is 5000







      json particle-photon






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 15:58









      pilot0674pilot0674

      13




      13
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415925%2fhttp-client-particle-code-not-getting-json-from-my-raspberry-pi-webhost%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415925%2fhttp-client-particle-code-not-getting-json-from-my-raspberry-pi-webhost%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga