24
24
#include " LEDManager.h"
25
25
#include " PWMManager.h"
26
26
27
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
27
28
#include " ThreadUtil.h"
29
+ #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
30
+ #include < platform/Zephyr/InetUtils.h>
31
+ #include < platform/telink/wifi/TelinkWiFiDriver.h>
32
+ #endif
28
33
29
34
#include < DeviceInfoProviderImpl.h>
30
35
#include < app/clusters/identify-server/identify-server.h>
@@ -74,7 +79,7 @@ uint8_t sFactoryResetCntr = 0;
74
79
bool sIsCommissioningFailed = false ;
75
80
bool sIsNetworkProvisioned = false ;
76
81
bool sIsNetworkEnabled = false ;
77
- bool sIsThreadAttached = false ;
82
+ bool sIsNetworkAttached = false ;
78
83
bool sHaveBLEConnections = false ;
79
84
80
85
#if APP_SET_DEVICE_INFO_PROVIDER
@@ -213,13 +218,16 @@ CHIP_ERROR AppTaskCommon::StartApp(void)
213
218
214
219
AppEvent event = {};
215
220
216
- #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD
221
+ #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
222
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
217
223
StartThreadButtonEventHandler ();
224
+ #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
225
+ StartWiFiButtonEventHandler ();
218
226
#endif
227
+ #endif /* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE */
219
228
220
229
#ifdef CONFIG_BOOTLOADER_MCUBOOT
221
- if (!chip::DeviceLayer::ConnectivityMgr ().IsThreadProvisioned () &&
222
- !chip::DeviceLayer::ConnectivityMgr ().IsWiFiStationProvisioned ())
230
+ if (!sIsNetworkProvisioned )
223
231
{
224
232
LOG_INF (" Confirm image." );
225
233
OtaConfirmNewImage ();
@@ -359,10 +367,14 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed)
359
367
case kButtonId_FactoryReset :
360
368
FactoryResetButtonEventHandler ();
361
369
break ;
362
- #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
370
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
363
371
case kButtonId_StartThread :
364
372
StartThreadButtonEventHandler ();
365
373
break ;
374
+ #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
375
+ case kButtonId_StartWiFi :
376
+ StartWiFiButtonEventHandler ();
377
+ break ;
366
378
#endif
367
379
case kButtonId_StartBleAdv :
368
380
StartBleAdvButtonEventHandler ();
@@ -433,16 +445,18 @@ void AppTaskCommon::LinkButtons(ButtonManager & buttonManager)
433
445
buttonManager.addCallback (FactoryResetButtonEventHandler, 0 , true );
434
446
buttonManager.addCallback (ExampleActionButtonEventHandler, 1 , true );
435
447
buttonManager.addCallback (StartBleAdvButtonEventHandler, 2 , true );
436
- #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD
448
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
437
449
buttonManager.addCallback (StartThreadButtonEventHandler, 3 , true );
450
+ #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
451
+ buttonManager.addCallback (StartWiFiButtonEventHandler, 3 , true );
438
452
#endif
439
453
}
440
454
441
455
void AppTaskCommon::UpdateStatusLED ()
442
456
{
443
457
if (sIsNetworkProvisioned && sIsNetworkEnabled )
444
458
{
445
- if (sIsThreadAttached )
459
+ if (sIsNetworkAttached )
446
460
{
447
461
LedManager::getInstance ().setLed (LedManager::EAppLed_Status, 950 , 50 );
448
462
}
@@ -506,8 +520,8 @@ void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent)
506
520
{
507
521
LOG_INF (" StartBleAdvHandler" );
508
522
509
- // Don't allow on starting Matter service BLE advertising after Thread provisioning.
510
- if (ConnectivityMgr (). IsThreadProvisioned () )
523
+ // Disable manual Matter service BLE advertising after device provisioning.
524
+ if (sIsNetworkProvisioned )
511
525
{
512
526
LOG_INF (" Device already commissioned" );
513
527
return ;
@@ -578,7 +592,7 @@ void AppTaskCommon::FactoryResetTimerEventHandler(AppEvent * aEvent)
578
592
LOG_INF (" Factory Reset Trigger Counter is cleared" );
579
593
}
580
594
581
- #if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE && CHIP_DEVICE_CONFIG_ENABLE_THREAD
595
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
582
596
void AppTaskCommon::StartThreadButtonEventHandler (void )
583
597
{
584
598
AppEvent event;
@@ -592,7 +606,7 @@ void AppTaskCommon::StartThreadButtonEventHandler(void)
592
606
void AppTaskCommon::StartThreadHandler (AppEvent * aEvent)
593
607
{
594
608
LOG_INF (" StartThreadHandler" );
595
- if (!chip::DeviceLayer::ConnectivityMgr (). IsThreadProvisioned () )
609
+ if (!sIsNetworkProvisioned )
596
610
{
597
611
// Switch context from BLE to Thread
598
612
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
@@ -609,6 +623,37 @@ void AppTaskCommon::StartThreadHandler(AppEvent * aEvent)
609
623
LOG_INF (" Device already commissioned" );
610
624
}
611
625
}
626
+
627
+ #elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
628
+ void AppTaskCommon::StartWiFiButtonEventHandler (void )
629
+ {
630
+ AppEvent event;
631
+
632
+ event.Type = AppEvent::kEventType_Button ;
633
+ event.ButtonEvent .Action = kButtonPushEvent ;
634
+ event.Handler = StartWiFiHandler;
635
+ GetAppTask ().PostEvent (&event);
636
+ }
637
+
638
+ void AppTaskCommon::StartWiFiHandler (AppEvent * aEvent)
639
+ {
640
+ LOG_INF (" StartWiFiHandler" );
641
+
642
+ if (!strlen (CONFIG_DEFAULT_WIFI_SSID) || !strlen (CONFIG_DEFAULT_WIFI_PASSWORD))
643
+ {
644
+ LOG_ERR (" default WiFi SSID/Password are not set" );
645
+ }
646
+
647
+ if (!sIsNetworkProvisioned )
648
+ {
649
+ net_if_up (InetUtils::GetWiFiInterface ());
650
+ NetworkCommissioning::TelinkWiFiDriver ().StartDefaultWiFiNetwork ();
651
+ }
652
+ else
653
+ {
654
+ LOG_INF (" Device already commissioned" );
655
+ }
656
+ }
612
657
#endif
613
658
614
659
void AppTaskCommon::ExampleActionButtonEventHandler (void )
@@ -673,11 +718,12 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /*
673
718
case DeviceEventType::kThreadStateChange :
674
719
sIsNetworkProvisioned = ConnectivityMgr ().IsThreadProvisioned ();
675
720
sIsNetworkEnabled = ConnectivityMgr ().IsThreadEnabled ();
676
- sIsThreadAttached = ConnectivityMgr ().IsThreadAttached ();
721
+ sIsNetworkAttached = ConnectivityMgr ().IsThreadAttached ();
677
722
#elif CHIP_DEVICE_CONFIG_ENABLE_WIFI
678
723
case DeviceEventType::kWiFiConnectivityChange :
679
724
sIsNetworkProvisioned = ConnectivityMgr ().IsWiFiStationProvisioned ();
680
725
sIsNetworkEnabled = ConnectivityMgr ().IsWiFiStationEnabled ();
726
+ sIsNetworkAttached = ConnectivityMgr ().IsWiFiStationConnected ();
681
727
#if CONFIG_CHIP_OTA_REQUESTOR
682
728
if (event->WiFiConnectivityChange .Result == kConnectivity_Established )
683
729
{
0 commit comments