77#include < Wire.h>
88#include < vector>
99#include < algorithm>
10+ #include < WiFi.h>
11+
12+ #include " sdkconfig.h"
1013
1114/* DS1307 functions */
1215
@@ -26,6 +29,9 @@ static uint8_t read_month = 0;
2629static uint16_t read_year = 0 ;
2730static int peek_data = -1 ;
2831
32+ const char *ssid = " Wokwi-GUEST" ;
33+ const char *password = " " ;
34+
2935const auto BCD2DEC = [](uint8_t num) -> uint8_t {
3036 return ((num / 16 * 10 ) + (num % 16 ));
3137};
@@ -247,7 +253,7 @@ void test_api() {
247253 Wire.flush ();
248254}
249255
250- void scan_bus () {
256+ bool device_found () {
251257 std::vector<uint8_t > found_addresses;
252258 uint8_t err;
253259
@@ -259,14 +265,33 @@ void scan_bus() {
259265 log_i (" Found device at address: 0x%02X" , address);
260266 found_addresses.push_back (address);
261267 } else if (address == DS1307_ADDR) {
262- TEST_FAIL_MESSAGE (" Failed to find DS1307" );
268+ log_e (" Failed to find DS1307" );
269+ return false ;
263270 }
264271 }
265272
266273 // Find DS1307_ADDR in found_addresses
267274 auto it = std::find (found_addresses.begin (), found_addresses.end (), DS1307_ADDR);
268- TEST_ASSERT_TRUE (it != found_addresses.end ());
275+ return it != found_addresses.end ();
276+ }
277+
278+ void scan_bus () {
279+ TEST_ASSERT_TRUE (device_found ());
280+ }
281+
282+ #if SOC_WIFI_SUPPORTED
283+ void scan_bus_with_wifi () {
284+ // delete old config
285+ WiFi.disconnect (true , true , 1000 );
286+ delay (1000 );
287+ WiFi.begin (ssid, password);
288+ delay (5000 );
289+ bool found = device_found ();
290+ WiFi.disconnect (true , true , 1000 );
291+
292+ TEST_ASSERT_TRUE (found);
269293}
294+ #endif
270295
271296/* Main */
272297
@@ -282,6 +307,9 @@ void setup() {
282307 log_d (" Starting tests" );
283308 UNITY_BEGIN ();
284309 RUN_TEST (scan_bus);
310+ #if SOC_WIFI_SUPPORTED
311+ RUN_TEST (scan_bus_with_wifi);
312+ #endif
285313 RUN_TEST (rtc_set_time);
286314 RUN_TEST (rtc_run_clock);
287315 RUN_TEST (change_clock);
0 commit comments