//--tested, working--// //--client and server side--// size_t WiFiClient::write(const uint8_t *buffer, size_t size) { // //don't do anything if not properly set up // if (_socketIndex == NO_SOCKET_AVAIL) { return 0; } // //write the buffer to the socket // int iRet = sl_Send(WiFiClass::_handleArray[_socketIndex], buffer, size, 0); // Flow control signal; perform a paced-retry. while (iRet == SL_EAGAIN) { delay(10); #ifndef SL_PLATFORM_MULTI_THREADED$ /* HACK: required in nonos builds, otherwise we hang in this loop */ sl_Task(); #endif iRet = sl_Send(WiFiClass::_handleArray[_socketIndex], buffer, size, 0); } if ((iRet < 0) || (iRet != size)) { // //if an error occured or the socket has died, call stop() //to make the object aware that it's dead // stop(); return 0; } else { return iRet; } }
unsigned int WiFiClass::getTotalDevices(void) { #ifndef SL_PLATFORM_MULTI_THREADED sl_Task(); #endif return WiFiClass::_connectedDeviceCount; }
//--tested, working--// uint8_t WiFiClass::status() { int8_t name[33]; int16_t NameLen; uint8_t i; if (!_initialized) { init(); } if (role == ROLE_AP) { return WL_AP_MODE; } #ifndef SL_PLATFORM_MULTI_THREADED // // The class variable WiFi_status is maintained by the slWlanEvenHandler // sl_Task(); #endif #if 0 /* If SimpleConfig was started then wait for SimpleConfig to be complete. * Only delete the existing profile if the connection was successfull */ if(_SimpleConfigComplete && (WiFi_status == WL_CONNECTED)) { for (i = 0; i < 7; i++) { _SimpleConfigComplete = false; int16_t ret = sl_WlanProfileGet(i, name, &NameLen, NULL, NULL, NULL, NULL); if (ret < 0) { continue; } name[NameLen] = '\0'; Serial.print("\nProfile: "); Serial.print(i); Serial.print(" SSID: "); Serial.println((char*)name); /* Delete the profiles that do not match the SSID that the board is connected to */ if (strcmp((char *)name, connected_ssid) != 0) { sl_WlanProfileDel(i); Serial.print("Deleting Profile: "); Serial.println(i); } } } #endif return WiFi_status; }
//--tested, working--// uint8_t WiFiClass::status() { if (!_initialized) { init(); } if (role == ROLE_AP) { return WL_AP_MODE; } #ifndef SL_PLATFORM_MULTI_THREADED // // The class variable WiFi_status is maintained by the slWlanEvenHandler // sl_Task(); #endif return WiFi_status; }
int WiFiClass::startSmartConfig() { unsigned char policyVal; if (!_initialized) { init(); } if (sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,1), &policyVal, 1 /*PolicyValLen*/) < 0) { return -1; } if (sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES) < 0) { return -1; } sl_WlanSmartConfigStart(0, //groupIdBitmask SMART_CONFIG_CIPHER_NONE, //cipher 0, //publicKeyLen 0, //group1KeyLen 0, //group2KeyLen NULL, //publicKey NULL, //group1Key NULL); //group2Key /* Block until connected */ while (WiFi.status() != WL_CONNECTED) { #ifndef SL_PLATFORM_MULTI_THREADED // TODO: this call appears unnecessary: status() already calls sl_Task sl_Task(); #else // TODO: is 10 appropriate? to save power, shouldn't we always delay? delay(10); #endif } if (sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/) < 0) { return -1; } return (0); }
//--tested, working--// IPAddress WiFiClass::localIP() { #ifndef SL_PLATFORM_MULTI_THREADED // //the local IP is maintained with callbacks, so sl_Task() //is critical. The IP is "written" into the buffer to avoid memory errors // sl_Task(); #endif SlNetCfgIpV4Args_t config = {0}; unsigned char len = sizeof(SlNetCfgIpV4Args_t); sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO, NULL, &len, (unsigned char*)&config); // //change the uint32_t IP to the IPAddress class and return // IPAddress retIP(0,0,0,0); retIP = sl_Htonl(config.ipV4); return retIP; }