Help for send local URL

Hello,
I want to send this URL from my Photon, via my local network (http://hd1.freebox.fr/pub/remote_control?code=12345678&key=power) or “power” represents a keyword.
If I send this URL through my web browser, it controls my TV box.

I installed the library HttpClient.h, I looked at the example but I do not see how to indicate my URL. Hostname, port, patch …?!?

Thanks for help

This sample shows how

For your case

    request.hostname = "hd1.freebox.fr";
    request.port = 80;
    request.path = "/pub/remote_control";

Or what else are you missing?

1 Like

Since this is a GET request, you can add the parameters right on the URL like this:

request.path = "/pub/remote_control?code=12345678&key=power";
2 Likes

Thanks but i’m already try this…

    // This #include statement was automatically added by the Particle IDE.
#include <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;

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

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

    Serial.println();
    Serial.println("Application>\tStart of Loop.");
    // Request path and body can be set at runtime or at setup.
    request.hostname = "http://hd1.freebox.fr";
    request.port = 80;
    request.path = "/pub/remote_control?code=86700567&key=power";

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

    // Get request
    http.get(request, response, headers);
    Serial.print("Application>\tResponse status: ");
    Serial.println(response.status);

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

    nextTime = millis() + 10000;
}

I use the Particle Web IDE, is this a problem ?

Does it work?
Does it not work?
If not, then what does it do?
What’s the serial output?

Have a close look what the difference is between your hostname and mine (or the one in the sample you copied the code from) :wink:

2 Likes

It does not work and do nothing !
I’m working with the Web IDE so, don’t have a serial monitor

How can I see the result of sending the request?

I just understood how to have the monitor serie;)
it says 1 time “: ok”

I found … you should not put “http: //” in the host
So, I found another library, simpler.

// This #include statement was automatically added by the Particle IDE.
#include "rest_client.h"

RestClient client = RestClient("hd1.freebox.fr");

void setup() {
  Serial.begin(9600);
  Serial.println("starting...");
}
String response;
void loop() {

  response = "";
  int statusCode = client.get("/pub/remote_control?code=86700567&key=power", &response);
  Serial.print("Status code from server: ");
  Serial.println(statusCode);
  Serial.print("Response body from server: ");
  Serial.println(response);
  delay(5000);    

}

I am proud of myself :wink:

2 Likes

Exactly that :+1: