@@ -38,6 +38,32 @@ export const ControllerCommandStrings: Record<ControllerCommand, string> = {
3838 [ ControllerCommand . CONFIG_ERASE ] : "CONFIG_ERASE" ,
3939} ;
4040
41+ enum WifiKvNs {
42+ Ssids = "wifi_net" ,
43+ Main = "wifi_cfg" ,
44+ }
45+
46+ enum WifiKeys {
47+ Mode = "mode" ,
48+ StaMode = "sta_mode" ,
49+ StaSpecific = "sta_ssid" ,
50+ StaApFallback = "sta_ap_fallback" ,
51+ ApSsid = "ap_ssid" ,
52+ ApPass = "ap_pass" ,
53+ CurrentIp = "current_ip" ,
54+ }
55+
56+ export enum WifiMode {
57+ DISABLED = 0 ,
58+ STATION = 1 ,
59+ AP = 2 ,
60+ }
61+
62+ export enum WifiStaMode {
63+ BEST_SIGNAL = 0 ,
64+ SPECIFIC_SSID = 1 ,
65+ }
66+
4167enum KeyValueDataType {
4268 INT64 = 0 ,
4369 FLOAT32 = 1 ,
@@ -82,8 +108,8 @@ export class Controller {
82108 return false ;
83109 }
84110
85- public start ( path : string ) : Promise < void > {
86- this . _logger ?. verbose ( "Starting program: " + path ) ;
111+ public start ( entryPoint : string = "" ) : Promise < void > {
112+ this . _logger ?. verbose ( "Starting program: " + ( entryPoint ? entryPoint : "" ) ) ;
87113 return new TimeoutPromise (
88114 TIMEOUT_MS ,
89115 ( resolve , reject ) => {
@@ -98,7 +124,7 @@ export class Controller {
98124
99125 const packet = this . _out . buildPacket ( ) ;
100126 packet . put ( ControllerCommand . START ) ;
101- for ( const c of path ) {
127+ for ( const c of entryPoint ) {
102128 packet . put ( c . charCodeAt ( 0 ) ) ;
103129 }
104130 packet . send ( ) ;
@@ -449,4 +475,67 @@ export class Controller {
449475 }
450476 ) ;
451477 }
478+
479+ // WiFi Configuration Methods
480+ public async addWifiNetwork ( ssid : string , password : string ) : Promise < void > {
481+ this . _logger ?. verbose ( `Adding WiFi network: ${ ssid } ` ) ;
482+ return this . configSetString ( WifiKvNs . Ssids , ssid . substring ( 0 , 15 ) , password ) ;
483+ }
484+
485+ public async removeWifiNetwork ( ssid : string ) : Promise < void > {
486+ this . _logger ?. verbose ( `Removing WiFi network: ${ ssid } ` ) ;
487+ return this . configErase ( WifiKvNs . Ssids , ssid ) ;
488+ }
489+
490+ public getWifiMode ( ) : Promise < WifiMode > {
491+ return this . configGetInt ( WifiKvNs . Main , WifiKeys . Mode ) as Promise < WifiMode > ;
492+ }
493+
494+ public setWifiMode ( mode : WifiMode ) : Promise < void > {
495+ return this . configSetInt ( WifiKvNs . Main , WifiKeys . Mode , mode ) ;
496+ }
497+
498+ public getWifiStaMode ( ) : Promise < WifiStaMode > {
499+ return this . configGetInt ( WifiKvNs . Main , WifiKeys . StaMode ) as Promise < WifiStaMode > ;
500+ }
501+
502+ public setWifiStaMode ( mode : WifiStaMode ) : Promise < void > {
503+ return this . configSetInt ( WifiKvNs . Main , WifiKeys . StaMode , mode ) ;
504+ }
505+
506+ public getWifiStaSpecific ( ) : Promise < string > {
507+ return this . configGetString ( WifiKvNs . Main , WifiKeys . StaSpecific ) ;
508+ }
509+
510+ public setWifiStaSpecific ( ssid : string ) : Promise < void > {
511+ return this . configSetString ( WifiKvNs . Main , WifiKeys . StaSpecific , ssid ) ;
512+ }
513+
514+ public getWifiStaApFallback ( ) : Promise < number > {
515+ return this . configGetInt ( WifiKvNs . Main , WifiKeys . StaApFallback ) ;
516+ }
517+
518+ public setWifiStaApFallback ( enabled : boolean ) : Promise < void > {
519+ return this . configSetInt ( WifiKvNs . Main , WifiKeys . StaApFallback , enabled ? 1 : 0 ) ;
520+ }
521+
522+ public getWifiApSsid ( ) : Promise < string > {
523+ return this . configGetString ( WifiKvNs . Main , WifiKeys . ApSsid ) ;
524+ }
525+
526+ public setWifiApSsid ( ssid : string ) : Promise < void > {
527+ return this . configSetString ( WifiKvNs . Main , WifiKeys . ApSsid , ssid ) ;
528+ }
529+
530+ public getWifiApPassword ( ) : Promise < string > {
531+ return this . configGetString ( WifiKvNs . Main , WifiKeys . ApPass ) ;
532+ }
533+
534+ public setWifiApPassword ( password : string ) : Promise < void > {
535+ return this . configSetString ( WifiKvNs . Main , WifiKeys . ApPass , password ) ;
536+ }
537+
538+ public getCurrentWifiIp ( ) : Promise < string > {
539+ return this . configGetString ( WifiKvNs . Main , WifiKeys . CurrentIp ) ;
540+ }
452541}
0 commit comments