Skip to content

Instantly share code, notes, and snippets.

@brulint
Created March 23, 2025 14:27
Show Gist options
  • Save brulint/58268812c6d3b6da9aa69d08b4db6732 to your computer and use it in GitHub Desktop.
Save brulint/58268812c6d3b6da9aa69d08b4db6732 to your computer and use it in GitHub Desktop.
Send a simple HTTP request to REST API over Wifi with ESP32
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
void setup() {
Serial.begin(115200);
while (!Serial) delay(100);
WiFi.begin("SSID", "P4ssw0rd");
while (WiFi.status() != WL_CONNECTED) delay(500);
Serial.println("Connected.");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// https://docs.kraken.com/api/docs/rest-api/get-ticker-information
http.begin("https://api.kraken.com/0/public/Ticker?pair=XXBTZEUR");
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String response = http.getString();
JsonDocument doc;
DeserializationError error = deserializeJson(doc, response);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
} else {
Serial.print("BTC: ");
Serial.println(doc["result"]["XXBTZEUR"]["c"][0].as<double>());
}
} else {
Serial.printf("failed, error: %i %s\n", httpCode, http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.println("Network unreachable");
}
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment