Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jun 13, 2024
1 parent 15b0ba7 commit 5628c37
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
4 changes: 4 additions & 0 deletions examples/TinyGPS_Example/TinyGPS_Example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
// ESP32S3 can freely map unused Pins
#define GPS_RX_PIN 1
#define GPS_TX_PIN 2
#elif defined(LILYGO_T_ETH_ELITE_ESP32S3)
// ESP32S3 can freely map unused Pins
#define GPS_RX_PIN 39
#define GPS_TX_PIN 42
#endif

// The baud rate may not be suitable for all GPS modules. Adjust the baud rate according to your own GPS module.
Expand Down
51 changes: 33 additions & 18 deletions examples/UnitTestExample/UnitTestExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,32 @@ void WiFiEvent(arduino_event_id_t event)
}
}

void testClient(const char *host, uint16_t port)
void testClient()
{
const char *host = "http://httpbin.org/get";
Serial.print("\nconnecting to ");
Serial.println(host);

WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available())
;
while (client.available()) {
Serial.write(client.read());
HTTPClient http;
if (http.begin(host)) {
int httpCode = http.GET();
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
// Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
printLocalTime();
String payload = http.getString();
Serial.println(payload);
Serial.printf(" > Connect %s successes!\n", host);
}
} else {
printLocalTime();
Serial.printf(" > Connect %s failed err:%s!\n", host, http.errorToString(httpCode).c_str());
}
http.end();
}

Serial.println("closing connection\n");
client.stop();
http.end();
}


Expand Down Expand Up @@ -168,15 +175,23 @@ void setup()
{
Serial.begin(115200);


#ifdef LED_PIN
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
#endif


#ifdef SD_MISO_PIN
pinMode(SD_MISO_PIN, INPUT_PULLUP);
SPI.begin(SD_SCLK_PIN, SD_MISO_PIN, SD_MOSI_PIN, SD_CS_PIN);
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SDCard MOUNT FAIL");
} else {
uint32_t cardSize = SD.cardSize() / (1024 * 1024);
String str = "SDCard Size: " + String(cardSize) + "MB";
Serial.println(str);
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}
#endif

Expand Down Expand Up @@ -256,7 +271,7 @@ void loop()
if (eth_connected) {
Serial.println("===========ETH=============");
//test http
testClient("httpbin.org", 80);
testClient();

// test https
// testHTTPS();
Expand Down

0 comments on commit 5628c37

Please sign in to comment.