ESP32 as wifi module in Legato 21.05.0

I have a ESP32 kernel module using SPI working from the command line on WP7702,

What do i have to change so the wifiService will work with ESP32 instead of a TI module ?

Dec 19 15:23:09 swi-mdm9x28-wp user.info Legato: INFO | dcsDaemon[7935]/dcsDaemon T=main | dcsTechRank.c dcsTechRank_Init() 858 | Wifi client is available
Dec 19 15:23:09 swi-mdm9x28-wp user.info Legato: INFO | dcsDaemon[7935]/dcsWifi T=main | dcsWifi.c DcsWifiClientStart() 250 | Starting Wifi client
Dec 19 15:23:09 swi-mdm9x28-wp user.info Legato: INFO | wifiService[8056] | WIFI_START
Dec 19 15:23:09 swi-mdm9x28-wp user.err Legato: =ERR= | wifiService[8056] | ERR* failed to write i2c data
Dec 19 15:23:09 swi-mdm9x28-wp user.err Legato: =ERR= | wifiService[8056] | FTL* Failed to enable PCA9548A I2C switch
Dec 19 15:23:09 swi-mdm9x28-wp user.info Legato: INFO | wifiService[8056] | Clean up due to unknown error
Dec 19 15:23:09 swi-mdm9x28-wp user.warn Legato: -WRN- | wifiService[8056]/daemon T=main | pa_wifi_client.c pa_wifiClient_Start() 532 | Failed to start WiFi client command “WIFI_START” systemResult (32512)
Dec 19 15:23:09 swi-mdm9x28-wp user.warn Legato: -WRN- | wifiService[8056]/daemon T=main | le_wifiClient.c le_wifiClient_Start() 821 | Unable to start WIFI client; return code: -6
Dec 19 15:23:09 swi-mdm9x28-wp user.warn Legato: -WRN- | dcsDaemon[7935]/dcsWifi T=main | dcsWifi.c le_dcsWifi_GetChannelList() 906 | Unable to start wifiClient for scanning

you might need to see the code in \legato-21.05.2.rc2\modules\WiFi\service

I got the src through leaf in VSCode
/home/pm/.leaf/wp76-legato_21.05.2.rc2-202302240920
I don’t see any changes in modules/wifi/service compared to the one currently used
/home/pm/.leaf/wp77-legato_21.05.0-202110290357

Would it be correct that wifi service is handled by scripts so if i make changes to tiwifi.sh and pa_wifi.sh or is there more to it?

I got it working!

root@swi-mdm9x28-wp:~# wifi client start
successfully called start.
root@swi-mdm9x28-wp:~# wifi client scan
starting scan.

Still need some more testing!
Is there a good example of using the dcs.api with both cell and wifi ?

how about these two test app?

Thanks i will check those

I got something working using the examples but it seems to be a lot more complicated compared to using le_data where everything is kinda handled automatic.
I found some description on using wifi with le_data

config set dataConnectionService:/wifi/SSID TEST-MOBILE
config set dataConnectionService:/wifi/passphrase password
config set dataConnectionService:/wifi/secProtocol 3

Is the secProtocol the same as this enum ?
and does it need to be set or is it enough with just a password ?

typedef enum
{
LE_WIFICLIENT_SECURITY_NONE = 0,
///< no security.
LE_WIFICLIENT_SECURITY_WEP = 1,
///< Using WEP.
LE_WIFICLIENT_SECURITY_WPA_PSK_PERSONAL = 2,
///< Using WPA
LE_WIFICLIENT_SECURITY_WPA2_PSK_PERSONAL = 3,
///< Using WPA2
LE_WIFICLIENT_SECURITY_WPA_EAP_PEAP0_ENTERPRISE = 4,
///< Using WPA Enterprise
LE_WIFICLIENT_SECURITY_WPA2_EAP_PEAP0_ENTERPRISE = 5
///< Using WPA2 Enterprise
}
le_wifiClient_SecurityProtocol_t;

according to this document:

it needs to do “wifi client setsecurityproto”.
Have you tried this command first and see if it can connect wifi client?

If it needs this command, I believe you also need to set
config set dataConnectionService:/wifi/secProtocol 3

For the definition of enum, you can see here:

Thanks

There was a few hints in the log
wifiService[9567]/daemon T=main | le_wifiClient.c le_wifiClient_LoadSsid() 2134 | No wifi security protocol set at wifiService:/wifi/channel/wptest/secProtocol
dcsDaemon[26583]/dcs T=main | dcsTech.c dcsTech_Start() 336 | Request to start channel wptest of technology wifi
secStore[26692]/le_pa_secStoreTz T=main | pa_secStoreTz.c ConfigTreeRead() 989 | Node not exist!! ‘/sys/259/apps/wifiService/wifiService/channel/wptest/passphrase’
wifiService[26701]/daemon T=main | le_wifiClient.c WifiClient_LoadCfg_WpaPsk() 1911 | Failed to read passphrase from secStore path wifiService/channel/wptest/passphrase for SSID wptest; retcode -1

so after adding le_wifiClient_ConfigurePsk() it connected to the wifi.

le_cfg_SetString(iteratorRef, CFG_NODE_SSID, “wptest”);
le_cfg_SetString(iteratorRef, CFG_NODE_SECPROTOCOL, “3”);
le_cfg_SetString(iteratorRef, CFG_NODE_PASSPHRASE, “password”);
// Commit the transaction to make sure these new settings get written to the tree.
le_cfg_CommitTxn(iteratorRef);

le_wifiClient_ConfigurePsk((const uint8_t*)“wptest”, strlen(“wptest”), LE_WIFICLIENT_SECURITY_WPA2_PSK_PERSONAL, (const uint8_t*)“password”, strlen(“password”), (const uint8_t*)“password”, strlen(“password”));

ConnectionRef = le_data_Request();

If i removed power from the wifi it retried a few times, gave up and connected to the cell which is good,
but is there a way to make it reconnect to the wifi again when it comes back ?

have you tried to “le_data_Release()” and reconnect by le_data_Request()?

I will try that, but guess i will have to do le_wifiClient_Scan in the background and wait for the SSID to come back

Jan 6 15:29:56 swi-mdm9x28-wp user.err Legato: =ERR= | MCExe[26994]/mc T=WiFi | WiFi.cpp testScanResult() 97 | le_wifiClient_GetSsid OK, ssidLength 6;SSID: “wptest”
Jan 6 15:29:56 swi-mdm9x28-wp user.err Legato: =ERR= | MCExe[26994]/mc T=WiFi | WiFi.cpp testScanResult() 105 | FOUND SSID
Jan 6 15:29:56 swi-mdm9x28-wp user.err Legato: =ERR= | MCExe[26994]/mc T=WiFi | mainComponent.cpp resetDataConnection() 713 | resetDataConnection!!!
Jan 6 15:29:56 swi-mdm9x28-wp user.err Legato: =ERR= | MCExe[26994]/mc T=WiFi | mainComponent.cpp resetDataConnection() 718 | le_data_Release
Jan 6 15:29:57 swi-mdm9x28-wp user.err Legato: =ERR= | MCExe[26994]/mc T=WiFi | mainComponent.cpp resetDataConnection() 723 | le_data_Request
Jan 6 15:29:57 swi-mdm9x28-wp user.info Legato: INFO | dcsDaemon[26960]/dcsDaemon T=main | dcsServer.c ProcessCommand() 1395 | Sharing the already connected data channel 1 of technology 1

I even tried le_mrc_SetRadioPower(LE_OFF) and le_mrc_SetRadioPower(LE_ON)
in between le_data_Release and le_data_Request with some sleep(1) in between but it kept using the cell ?

so le_data_Request() only establish wifi connection after power reset?
How about setting the sleep time to be longer like one minute?
I think you need to wait for the data channel to be totally released in the data event handler called by le_data_AddConnectionStateHandler().

BTW, you can also see if you need to set the rank of technology like this:


    le_data_SetTechnologyRank(1,LE_DATA_WIFI );
    le_data_SetTechnologyRank(2,LE_DATA_CELLULAR  );

I had another app running that was using le_data_Request() so it was not releasing until that was restarted.

I did not have to use le_data_SetTechnologyRank()

so the problem is solved by running one application for calling le_data_Request() ?

Yes The problem is solved for now,
Thanks