Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Last active August 6, 2019 11:56
Show Gist options
  • Save maxpromer/de539a4f5e205e6b5cb873c7ecfde836 to your computer and use it in GitHub Desktop.
Save maxpromer/de539a4f5e205e6b5cb873c7ecfde836 to your computer and use it in GitHub Desktop.
#include <WiFi.h>
#include <HTTPClient.h>
#define WIFI_STA_NAME "xxxxxxxxxx"
#define WIFI_STA_PASS "xxxxxxxxxx"
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_STA_NAME);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_STA_NAME, WIFI_STA_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
String url = "http://ioxhop.info/files/test.txt";
Serial.println();
Serial.println("Get content from " + url);
HTTPClient http;
http.begin(url);
int httpCode = http.GET();
if (httpCode == 200) {
String content = http.getString();
Serial.println("Content ---------");
Serial.println(content);
Serial.println("-----------------");
} else {
Serial.println("Fail. error code " + String(httpCode));
}
Serial.println("END");
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment