Skip to content

Instantly share code, notes, and snippets.

@yamamaya
Created May 10, 2020 16:27
Show Gist options
  • Save yamamaya/59c7c93ab845e9b49ae96a0f5b33bc6c to your computer and use it in GitHub Desktop.
Save yamamaya/59c7c93ab845e9b49ae96a0f5b33bc6c to your computer and use it in GitHub Desktop.
#include <Adafruit_ZeroDMA.h>
#include <TFT_eSPI.h>
#include "AtWiFi.h"
#include"Free_Fonts.h"
TFT_eSPI tft;
const char* ssid = "******";
const char* password = "*******";
void setup() {
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0, 2);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextSize(1);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(2000);
WiFi.begin(ssid, password);
tft.print( "Connecting to WiFi ... " );
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
tft.println( "Success" );
}
int LoopCount = 0;
#define WAIT_UNIT 10
#define WAIT_MAX 3000
void loop() {
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0);
LoopCount ++;
tft.print( "#" );
tft.println( LoopCount );
const uint16_t port = 80;
const char* host = "192.168.0.11";
WiFiClient client;
tft.print( "Connecting to Web server ... " );
if (!client.connect(host, port)) {
tft.println("Failed");
exit( 0 );
}
tft.println( "Success" );
tft.print( "Sending GET request ... " );
client.print("GET /test.html\r\n"); // sending HTTP GET request
tft.println( "Success" );
int waitloop = 0;
while (!client.available() && waitloop < WAIT_MAX) {
waitloop++;
delay(WAIT_UNIT);
}
if (client.available() > 0) {
tft.print("Responded in ");
tft.print( waitloop * WAIT_UNIT );
tft.println("ms.");
String line = client.readString();
if ( line.length() != 60 ) {
tft.println( "Unexpected response" );
exit( 0 );
}
line.replace("\r\n", "\n");
line.replace('\r', '\n');
tft.println( line );
} else {
tft.print("Timed out ");
tft.print( waitloop * WAIT_UNIT );
tft.println("ms.");
exit( 0 );
}
client.stop();
delay( 1000*5 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment