55#include < Arduino.h>
66#include < unity.h>
77#include < Wire.h>
8+ #include < vector>
9+ #include < algorithm>
10+ #include < WiFi.h>
11+
12+ #include " sdkconfig.h"
813
914/* DS1307 functions */
1015
@@ -24,6 +29,9 @@ static uint8_t read_month = 0;
2429static uint16_t read_year = 0 ;
2530static int peek_data = -1 ;
2631
32+ const char *ssid = " Wokwi-GUEST" ;
33+ const char *password = " " ;
34+
2735const auto BCD2DEC = [](uint8_t num) -> uint8_t {
2836 return ((num / 16 * 10 ) + (num % 16 ));
2937};
@@ -245,6 +253,42 @@ void test_api() {
245253 Wire.flush ();
246254}
247255
256+ bool device_found () {
257+ uint8_t err;
258+
259+ for (uint8_t address = 1 ; address < 127 ; ++address) {
260+ Wire.beginTransmission (address);
261+ err = Wire.endTransmission ();
262+ log_d (" Address: 0x%02X, Error: %d" , address, err);
263+ if (err == 0 ) {
264+ log_i (" Found device at address: 0x%02X" , address);
265+ } else if (address == DS1307_ADDR) {
266+ log_e (" Failed to find DS1307" );
267+ return false ;
268+ }
269+ }
270+
271+ return true ;
272+ }
273+
274+ void scan_bus () {
275+ TEST_ASSERT_TRUE (device_found ());
276+ }
277+
278+ #if SOC_WIFI_SUPPORTED
279+ void scan_bus_with_wifi () {
280+ // delete old config
281+ WiFi.disconnect (true , true , 1000 );
282+ delay (1000 );
283+ WiFi.begin (ssid, password);
284+ delay (5000 );
285+ bool found = device_found ();
286+ WiFi.disconnect (true , true , 1000 );
287+
288+ TEST_ASSERT_TRUE (found);
289+ }
290+ #endif
291+
248292/* Main */
249293
250294void setup () {
@@ -258,6 +302,10 @@ void setup() {
258302
259303 log_d (" Starting tests" );
260304 UNITY_BEGIN ();
305+ RUN_TEST (scan_bus);
306+ #if SOC_WIFI_SUPPORTED
307+ RUN_TEST (scan_bus_with_wifi);
308+ #endif
261309 RUN_TEST (rtc_set_time);
262310 RUN_TEST (rtc_run_clock);
263311 RUN_TEST (change_clock);
0 commit comments