target.ino 957 B

1234567891011121314151617181920212223242526272829
  1. void resolveTargetRelayIP(){
  2. //Resolve the target relay module IP from mDNS broadcast
  3. if(resolveMdnsService("http", "tcp", TARGET_DEVICE, &target_ip, &target_port)) {
  4. Serial.printf("got an answer for %s.local!\n", TARGET_DEVICE);
  5. Serial.println(target_ip);
  6. Serial.println(target_port);
  7. } else {
  8. Serial.printf("Sorry, %s.local not found\n", TARGET_DEVICE);
  9. }
  10. }
  11. void GetRequest(String url) {
  12. WiFiClient client; // Create a WiFiClient object
  13. HTTPClient http;
  14. http.begin(client, url); // Pass the WiFiClient object and the URL to begin()
  15. int httpCode = http.GET(); // Make the GET request
  16. if (httpCode > 0) {
  17. String payload = http.getString(); // Get the response payload
  18. Serial.println("HTTP Response Code: " + String(httpCode));
  19. Serial.println("Response Payload: " + payload);
  20. } else {
  21. Serial.println("Error on HTTP request");
  22. }
  23. http.end(); // Close connection
  24. }