diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70228b1..0363f7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,33 +28,35 @@ jobs: # TestNTPClient - name: TestNTPClient (ESP8266) fqbn: esp8266:esp8266:nodemcuv2 + sketch_dir: examples/TestNTPClient sketch: examples/TestNTPClient/TestNTPClient.ino platforms: | - name: esp8266:esp8266 source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json - - name: TestNTPClient (ESP32) - fqbn: esp32:esp32:esp32 - sketch: examples/TestNTPClient/TestNTPClient.ino - platforms: | - - name: esp32:esp32 - source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + artifact_name: testntp-esp8266 - name: TestNTPClient (Uno+ESP-01) fqbn: arduino:avr:uno + sketch_dir: examples/TestNTPClient sketch: examples/TestNTPClient/TestNTPClient.ino platforms: | - name: arduino:avr + artifact_name: testntp-uno # examples - - name: NodeMCU (ESP8266) + - name: Example - NodeMCU (ESP8266) fqbn: esp8266:esp8266:nodemcuv2 + sketch_dir: examples/NodeMCU sketch: examples/NodeMCU/NodeMCU.ino platforms: | - name: esp8266:esp8266 source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json - - name: Arduino UNO + artifact_name: example-nodemcu-esp8266 + - name: Example - Arduino UNO + ESP-01 fqbn: arduino:avr:uno + sketch_dir: examples/ArduinoEspWifiShield sketch: examples/ArduinoEspWifiShield/ArduinoEspWifiShield.ino platforms: | - name: arduino:avr + artifact_name: example-arduinouno steps: - uses: actions/checkout@v6 @@ -79,3 +81,66 @@ jobs: libraries: | - source-path: ./ - name: WiFiEsp + cli-compile-flags: | + - --export-binaries + + - name: Tree sketch directory + run: tree -L 5 ${{ matrix.config.sketch_dir }} + + simulate: + name: Simulate / TestNTPClient (ESP32) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Cache Arduino platforms and libraries + uses: actions/cache@v5 + with: + path: | + ~/.arduino15/packages + ~/Arduino/libraries + key: ${{ runner.os }}-arduino-esp32:esp32:esp32-${{ hashFiles('.github/workflows/ci.yml') }} + restore-keys: | + ${{ runner.os }}-arduino-esp32:esp32:esp32- + + - name: Patch WiFi credentials for Wokwi + run: | + sed -i -E 's/(WIFI_SSID\s*=\s*)"[^"]*"/\1"Wokwi-GUEST"/' examples/TestNTPClient/TestNTPClient.ino + sed -i -E 's/(WIFI_PASSWORD\s*=\s*)"[^"]*"/\1""/' examples/TestNTPClient/TestNTPClient.ino + + - name: Compile sketch + uses: arduino/compile-sketches@v1 + with: + fqbn: esp32:esp32:esp32 + platforms: | + - name: esp32:esp32 + source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketch-paths: | + - examples/TestNTPClient/TestNTPClient.ino + libraries: | + - source-path: ./ + - name: WiFiEsp + cli-compile-flags: | + - --export-binaries + + - name: Tree sketch directory + run: tree -L 5 examples/TestNTPClient/ + + - name: Upload compiled binary + uses: actions/upload-artifact@v4 + with: + name: testntp-esp32-bin + path: examples/TestNTPClient/ + + - name: Simulate with Wokwi + uses: wokwi/wokwi-ci-action@v1 + with: + token: ${{ secrets.WOKWI_TOKEN }} + path: examples/TestNTPClient + timeout: 300000 + expect_text: "0 failed" + fail_text: "[FAIL]" + serial_log_file: wokwi-serial.log + + - name: Cat serial log + run: cat wokwi-serial.log diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 42f8048..bc4c48f 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -4,7 +4,7 @@ on: push: branches: - master - pull_request: + # pull_request: workflow_dispatch: permissions: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2aca916 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/examples/**/build/ diff --git a/examples/TestNTPClient/TestNTPClient.ino b/examples/TestNTPClient/TestNTPClient.ino index 098b090..5bf45dc 100644 --- a/examples/TestNTPClient/TestNTPClient.ino +++ b/examples/TestNTPClient/TestNTPClient.ino @@ -230,6 +230,23 @@ void test_stale_time() { Serial.print(g_failed - _f); Serial.println(F(" failed")); \ } while (0) +#if defined(ESP32) +void setupEsp32Watchdog() { + // 30 s — long enough for slow NTP in Wokwi simulation; still catches infinite loops. + esp_task_wdt_config_t twdt_config = { + .timeout_ms = 30000, + .idle_core_mask = 0, + .trigger_panic = true + }; + // Arduino framework may have already initialized TWDT with a 5 s timeout. + // esp_task_wdt_init() fails in that case, so use reconfigure() first. + if (esp_task_wdt_reconfigure(&twdt_config) != ESP_OK) + esp_task_wdt_init(&twdt_config); + // ESP_ERR_INVALID_ARG means already subscribed by the framework — still fine. + esp_task_wdt_add(NULL); +} +#endif + void setup() { Serial.begin(115200); delay(100); @@ -240,6 +257,11 @@ void setup() { WiFi.init(&esp_serial); #endif +#if defined(ESP32) + setupEsp32Watchdog(); + Serial.println(F("ESP32 watchdog timer configured (30 s timeout)")); +#endif + wifi_connect(); RUN(1, test_constants); diff --git a/examples/TestNTPClient/diagram.json b/examples/TestNTPClient/diagram.json new file mode 100644 index 0000000..29e192c --- /dev/null +++ b/examples/TestNTPClient/diagram.json @@ -0,0 +1,29 @@ +{ + "version": 1, + "author": "aharshac", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-devkit-c-v4", + "id": "esp", + "top": 0, + "left": 0, + "attrs": {} + } + ], + "connections": [ + [ + "esp:TX", + "$serialMonitor:RX", + "", + [] + ], + [ + "esp:RX", + "$serialMonitor:TX", + "", + [] + ] + ], + "dependencies": {} +} diff --git a/examples/TestNTPClient/wokwi.toml b/examples/TestNTPClient/wokwi.toml new file mode 100644 index 0000000..da6b343 --- /dev/null +++ b/examples/TestNTPClient/wokwi.toml @@ -0,0 +1,5 @@ +[wokwi] +version = 1 +firmware = "build/esp32.esp32.esp32/TestNTPClient.ino.bin" +elf = "build/esp32.esp32.esp32/TestNTPClient.ino.elf" +rfc2217ServerPort = 4000