Skip to content

Instantly share code, notes, and snippets.

@igrr
Last active June 2, 2016 03:38
Show Gist options
  • Save igrr/a81e10c37575c3ea2874d6c1a18b0eb4 to your computer and use it in GitHub Desktop.
Save igrr/a81e10c37575c3ea2874d6c1a18b0eb4 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
uint8_t buff[128] = { 0 };
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin("#!/bin/test", "test_bin");
Serial.begin(115200);
Serial.println();
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
Serial.println();
Serial.println(WiFi.localIP());
HTTPClient http;
Serial.print("[HTTP] begin...\n");
http.begin("http://www.eetimes.com/");
Serial.print("[HTTP] GET...\n");
int httpCode = http.GET();
if (httpCode < 0) {
Serial.print("[HTTP] GET... failed, error: ");
Serial.println(http.errorToString(httpCode));
return;
}
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode != HTTP_CODE_OK) {
return;
}
int len = http.getSize();
WiFiClient* stream = http.getStreamPtr();
// read all data from server
while (http.connected() && (len > 0 || len == -1)) {
// get available data size
size_t size = stream->available();
if (size) {
// read up to 128 bytes
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
// write it to Serial
Serial.write(buff, c);
if (len > 0) {
len -= c;
}
}
delay(1);
}
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment