- /*
- https://github.com/ldijkman/WT32-ETH01-LAN-8720-RJ45-
- HTTP client connection to phillips tv api
- https://techtutorialsx.com/2017/05/19/esp32-http-get-requests/
- https://techtutorialsx.com/2017/05/20/esp32-http-post-requests/
- HTTPclient github
- https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino
- https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/src/HTTPClient.h
- https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/src/HTTPClient.cpp
- */
- #include <ETH.h>
- #include <ArduinoJson.h> // Json converter
- #include <HTTPClient.h> // Connection http
- #define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN // ETH_CLOCK_GPIO17_OUT
- #define ETH_POWER_PIN 16 // The enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
- #define ETH_TYPE ETH_PHY_LAN8720 // Type of the Ethernet PHY LAN8720
- #define ETH_ADDR 1 // I²C-address of Ethernet PHY
- #define ETH_MDC_PIN 23 // The I²C clock signal for the Ethernet PHY
- #define ETH_MDIO_PIN 18 // The I²C IO signal for the Ethernet PHY
- #define NRST 21 // The nRST (enable) for the Ethernet PHY
- static bool eth_connected = false; // Global variable to pull status of eth.
- const int httpsPort = 1925; //HTTPS= 443 and HTTP = 80, Phillips HTTPS= 1926 and HTTP = 1925
- int apiVersion[] = {1, 5, 6}; // possible api versions
- int apiv = 0;
- StaticJsonDocument<384> doc;
- String json;
- HTTPClient http;
- WiFiClient client;
- HTTPClient httpSecure;
- void WiFiEvent(WiFiEvent_t event) // used for connecting the ethernet connection
- {
- switch (event) {
- case SYSTEM_EVENT_ETH_START: //set eth hostname here, Called in setup
- Serial.println("ETH Started");
- ETH.setHostname("esp32-ethernet");
- break;
- case SYSTEM_EVENT_ETH_CONNECTED: // Called when cable is connected
- eth_connected = true; // Set the flag true if cable is connected
- Serial.println("ETH Connected");
- break;
- case SYSTEM_EVENT_ETH_GOT_IP: // Called when DHCP gifted the IP
- Serial.print("ETH MAC : ");
- Serial.println(ETH.macAddress());
- Serial.print("IPv4 : ");
- Serial.println(ETH.localIP());
- break;
- case SYSTEM_EVENT_ETH_DISCONNECTED: // Called when cable is disconnnected
- Serial.println("ETH Disconnected");
- eth_connected = false;
- break;
- case SYSTEM_EVENT_ETH_STOP: // Not yet seen
- Serial.println("ETH Stopped");
- eth_connected = false;
- break;
- default:
- break;
- }
- }
- void setup()
- {
- Serial.begin(115200);
- WiFi.onEvent(WiFiEvent);
- ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
- http.begin("tvip", 1925, "/6/ambilight/power");
- httpSecure.begin(client, "tvip", 1926, "", true);
- JsonArray scope = doc.createNestedArray("scope");
- scope.add("read");
- scope.add("write");
- scope.add("control");
- JsonObject device = doc.createNestedObject("device");
- device["device_name"] = "heliotrope";
- device["device_os"] = "Android";
- device["app_name"] = "ESP32api";
- device["type"] = "native";
- device["app_id"] = "app.id";
- device["id"] = "HWvAq8UdGxbGbsH7";
- serializeJson(doc, json);
- }
- void loop()
- {
- int httpCode;
- if (eth_connected)
- {
- if (apiv == 0)
- {
- for (int i = 0; i < 3; i++)
- {
- Serial.printf("Sending GET api version %s\n", String(apiVersion[i]));
- http.setURL(("/" + String(apiVersion[i]) + "/system"));
- httpCode = http.GET();
- if (httpCode == HTTP_CODE_OK)
- {
- String payload = http.getString();
- Serial.println(payload);
- apiv = apiVersion[i];
- http.end();
- break;
- }
- }
- }
- else if (apiv != 0)
- {
- delay(1000);
- Serial.println("Sending pair request to https");
- httpSecure.setURL(("/" + String(apiv) + "/pair/request"));
- httpCode = httpSecure.POST(json); // returns code -11 aka timeout
- Serial.println(httpCode);
- payload = httpSecure.getString(); // no payload
- Serial.println(payload);
- }
- }
- else {
- Serial.println("Pending");
- }
- delay(1000);
- }
HTTPS digit auth on the ESP32 based WT32-S1 ETH
HTTPS digit auth on the ESP32 based WT32-S1 ETH
For a project i am trying to make an HTTPS connection to Phillips TV using their jointspace API. I already got a working prototype with the http version on port 1925, but now i am trying to pair it on port 1926 via https. But i am getting an timeout code on the post request to start the digit auth.
Who is online
Users browsing this forum: No registered users and 107 guests