Using the LILYGO TTGO T-Internet-POE ESP32 Ethernet board with Blynk - Projects made with Blynk - Blynk Community
Tue Nov 15 2022 03:00:05 GMT+0000 (Coordinated Universal Time)
Saved by @leawoliu
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud // See the Device Info tab #define BLYNK_TEMPLATE_ID "REDACTED" #define BLYNK_DEVICE_NAME "REDACTED" #define BLYNK_AUTH_TOKEN "REDACTED" #define BLYNK_FIRMWARE_VERSION "1.0.0" // For Blynk.Air OTA, Increment with each update #define BLYNK_PRINT Serial #include <ETH.h> // You can use either the SSL or non-SSL library. Stick with SSL unless you have a good reason to change... //#include <BlynkSimpleEsp32.h> #include <BlynkSimpleEsp32_SSL.h> #include <Update.h> // For Blynk.Air OTA #include <HTTPClient.h> // For Blynk.Air OTA // Change this to match what it says on your ESP32 chip... // #define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT // For ESP32 module with PSRAM (WROVER) #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT // For ESP32 module without PSRAM (WROOM) // Ethernet stuff - don't change unless you know more about this than me... #define ETH_POWER_PIN -1 // Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source) #define ETH_TYPE ETH_PHY_LAN8720 // Type of the Ethernet PHY (LAN8720 or TLK110) #define ETH_ADDR 0 // I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) #define ETH_MDC_PIN 23 // Pin# of the I²C clock signal for the Ethernet PHY #define ETH_MDIO_PIN 18 // Pin# of the I²C IO signal for the Ethernet PHY #define NRST 5 static bool eth_connected = false; BlynkTimer timer; void WiFiEvent(WiFiEvent_t event) // Callback that is triggered when an Ethernet event occurs { switch (event) { case ARDUINO_EVENT_ETH_START: Serial.println("ETH Started"); // set eth hostname here ETH.setHostname("esp32-ethernet"); break; case ARDUINO_EVENT_ETH_CONNECTED: Serial.println("ETH Connected"); break; case ARDUINO_EVENT_ETH_GOT_IP: Serial.print("ETH MAC: "); Serial.print(ETH.macAddress()); Serial.print(", IPv4: "); Serial.print(ETH.localIP()); if (ETH.fullDuplex()) { Serial.print(", FULL_DUPLEX"); } Serial.print(", "); Serial.print(ETH.linkSpeed()); Serial.println("Mbps"); eth_connected = true; break; case ARDUINO_EVENT_ETH_DISCONNECTED: Serial.println("ETH Disconnected"); eth_connected = false; break; case ARDUINO_EVENT_ETH_STOP: Serial.println("ETH Stopped"); eth_connected = false; break; default: break; } } void setup() { Serial.begin(115200); WiFi.onEvent(WiFiEvent); // Defines the callback (above) to be called when an Ethernet event occurs // Initialise the Ethernet interface... pinMode(NRST, OUTPUT); digitalWrite(NRST, 0); delay(200); digitalWrite(NRST, 1); delay(200); digitalWrite(NRST, 0); delay(200); digitalWrite(NRST, 1); ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); // If you wnat to define a static IP address for your Ethernet device you can do it here using ETH.config() // The parameters are: (Device static IP address, Gateway, Subnet mask, DNS server IP) // Comment-out the ETH.config command if you want these to be parameters to be assigned by DHCP //ETH.config(IPAddress(192, 168, 1, 90), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 1)); Blynk.config(BLYNK_AUTH_TOKEN); Blynk.connect(); timer.setInterval(1000L, myTimerEvent); } void loop() { if (eth_connected) { Blynk.run(); } timer.run(); } void myTimerEvent() { Blynk.virtualWrite(V1, millis() / 1000); } BLYNK_WRITE(InternalPinOTA) // For Blynk.Air OTA { String overTheAirURL = param.asString(); HTTPClient http; http.begin(overTheAirURL); int httpCode = http.GET(); if (httpCode != HTTP_CODE_OK) {return;} int contentLength = http.getSize(); if (contentLength <= 0) {return; } bool canBegin = Update.begin(contentLength); if (!canBegin) { return;} Client& client = http.getStream(); int written = Update.writeStream(client); if (written != contentLength) {return;} if (!Update.end()) {return;} if (!Update.isFinished()) {return;} reboot(); } void reboot() // For Blynk.Air OTA { ESP.restart(); for (;;) {} // Wait here until the restart has begun }
Comments