Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Wifi reconnect using mita

    Wifi reconnect using mita

    The current setup I have require to have XDK with auto reconnection to WiFi since it is moving to connect the WiFi from another building to another building with same SSID.

    In mita application, when wifi is disconnected, XDK will not try to reconnect it unless it is being restarted again. Is there anyway to implement this auto reconnection by editing some section of generated C? 

    Tags (3)
    4 REPLIES 4
    Padmapriya
    Long-established Member

    Re: Wifi reconnect using mita

    Hello,

    You can modify the WiFi generated code to introduce the reconnect logic. The file will be in the name of resource setup. For example, setup xdkWifi : WLAN, generated file will be in name ConnectivityWLANXdkWifi.c.

    In which, You can check connection status in WlanConnectStatusCallback function WlanNetworkConnect_Status_T. In this callback function if connection status is WLANNWCT_STATUS_DISCONNECTED, then you can again reconnect with the WiFi network. Please refer SDK/XDK110/Common/source/Connectivity/WLAN.c WLAN_Reconnect function.

     

     

    Re: Wifi reconnect using mita

    Hello,

    Thanks for your answer. I tried like this, but it stuck at reconnecting...

    INFO | DEV00-HRL: WiFi DC 
    INFO | DEV00-HRL: Checking for network availability and trying to connect again

    It did print WiFi DC in serial console, This is my code section edited in ConnectivityWLANWireless.c

    static void ConnectivityWLANWireless_WlanConnectStatusCallback(WlanNetworkConnect_Status_T connectStatus)
    {
    	BCDS_UNUSED(connectStatus);
    	(void) xSemaphoreGive(WlanEventSemaphore);
    	if (connectStatus == WLANNWCT_STATUS_DISCONNECTED)
    	{		
    		printf("WiFi DC \r\n");		
    		WLAN_Reconnect();
    	}
    }

     

    Shanmathi
    Established Member

    Re: Wifi reconnect using mita

    Hello,

    WLAN_Recconect functionality is already supported as part of latest workbench release v3.6.0.

    Kindly refer the SendDataOverMQTT, HttpExampleClient or  PpmpUnide  applications which are updated to use reconnect functionality.

    Code snippet from applicaiton

    static Retcode_T AppControllerValidateWLANConnectivity(void)
    {
        Retcode_T retcode = RETCODE_OK;
        WlanNetworkConnect_IpStatus_T nwStatus;
    
        nwStatus = WlanNetworkConnect_GetIpStatus();
        if (WLANNWCT_IPSTATUS_CT_AQRD != nwStatus)
        {
    #if APP_MQTT_SECURE_ENABLE
            static bool isSntpDisabled = false;
            if (false == isSntpDisabled)
            {
                retcode = SNTP_Disable();
            }
            if (RETCODE_OK == retcode)
            {
                isSntpDisabled = true;
                retcode = WLAN_Reconnect();
            }
            if (RETCODE_OK == retcode)
            {
                retcode = SNTP_Enable();
            }
    #else
            retcode = WLAN_Reconnect();
    #endif /* APP_MQTT_SECURE_ENABLE */
        }
        return retcode;
    }

     You could try modifying your applicaiton in the similar manner to make use of reconenct feature.

     

    BR,

    Shanmathi

    Ariful
    New Poster

    Re: Wifi reconnect using mita

    Hello,

    I am facing a problem with my running project. I am writing a code in Eclipse Mita for the XDK110 sensor. it's also working fine and sends data properly to the cloud. But the problem is that if the WLN connection disconnects with the sensor, the sensor can not reconnect with the wifi again. I can not understand how to recall again the WLN connection by Eclipse Mita ? And i also try to use this code on my code but it is showing some error from here {static Retcode_T AppControllerValidateWLANConnectivity(void)}. Can you tell me where i use this code? Please help me to solve this problem.

     

     

    package main; //import the package platforms from xdk110 library
    import platforms.xdk110;

    var count = 0;

    //setup the wifi connection
    setup net: WLAN {

    ssid = "";

    authentication = Personal(psk = "");
    }
    static Retcode_T AppControllerValidateWLANConnectivity(void)
    {
    Retcode_T retcode = RETCODE_OK;
    WlanNetworkConnect_IpStatus_T nwStatus;

    nwStatus = WlanNetworkConnect_GetIpStatus();
    if (WLANNWCT_IPSTATUS_CT_AQRD != nwStatus)
    {
    #if APP_MQTT_SECURE_ENABLE
    static bool isSntpDisabled = false;
    if (false == isSntpDisabled)
    {
    retcode = SNTP_Disable();
    }
    if (RETCODE_OK == retcode)
    {
    isSntpDisabled = true;
    retcode = WLAN_Reconnect();
    }
    if (RETCODE_OK == retcode)
    {
    retcode = SNTP_Enable();
    }
    #else
    retcode = WLAN_Reconnect();
    #endif /* APP_MQTT_SECURE_ENABLE */
    }
    return retcode;
    }


    //setup the MQTT url,clinentId and authentication from clooud_dashboard
    setup backend: MQTT {
    transport = net;
    url = "mqtt://40.68.172.187:1883";
    clientId = "RiELftL1TKIHlNxtPZJsA2Rv";
    authentication = Login("maker:4RMakyzCtY5ou0Nw7zXLsFmDiiNQya9lArNnWoZ1", "");


    //create variable and topic to send data to cloud dashboard

    var telemetry7 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Temp/state");
    var telemetry8 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Humid/state");
    var telemetry9 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Acceleration_X/state");
    var telemetry10 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Acceleration_Y/state");
    var telemetry11 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Acceleration_Z/state");
    var telemetry12 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Press/state");
    var telemetry13 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/light/state");
    var telemetry14 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Magnet_X/state");
    var telemetry15 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Magnet_Y/state");
    var telemetry16 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/Magnet_Z/state");
    var telemetry17 = topic("device/RiELftL1TKIHlNxtPZJsA2Rv/asset/noise/state");
    }


    fn getCelciusString(){
    var celcius = environment.temperature.read()/1000;
    return (`{"value": ${(celcius)}}`);}

    fn getHumidityString(){
    var humidity = environment.humidity.read();
    return (`{"value": ${(humidity)}}`);}

    fn getAccelerometer_XString(){
    var accelerometer_X = accelerometer.x_axis.read()/100;
    return (`{"value": ${(accelerometer_X)}}`);}

    fn getAccelerometer_YString(){
    var accelerometer_Y = accelerometer.y_axis.read()/100;
    return (`{"value": ${(accelerometer_Y)}}`);}

    fn getAccelerometer_ZString(){
    var accelerometer_Z = accelerometer.z_axis.read()/100;
    return (`{"value": ${(accelerometer_Z)}}`);}

    fn getPressureString(){
    var pressure = environment.pressure.read()/1000;
    return (`{"value": ${(pressure)}}`);}

    fn getLightString(){
    var light = light.intensity.read()/2806;
    return (`{"value": ${(light)}}`);}

    fn getMagnetometer_XString(){
    var magnetometer_X = magnetometer.x_axis.read()/100;
    return (`{"value": ${(magnetometer_X)}}`);}

    fn getMagnetometer_YString(){
    var magnetometer_Y = magnetometer.y_axis.read()/100;
    return (`{"value": ${(magnetometer_Y)}}`);}

    fn getMagnetometer_ZString(){
    var magnetometer_Z = magnetometer.z_axis.read()/100;
    return (`{"value": ${(magnetometer_Z)}}`);}


    fn getNoiseFloating(){
    var noise = noise_sensor.noise.read()*100;
    return (`{"value": ${(noise)}}`);}


    //start loop
    //set the time to sending data


    every 10 seconds{
    count++;
    if (count==1){
    backend.telemetry7.write(getCelciusString());
    println(getCelciusString());}

    if(count==2){
    backend.telemetry8.write(getHumidityString());
    println(getHumidityString());}

    if(count==3){
    backend.telemetry9.write(getAccelerometer_XString());
    println(getAccelerometer_XString());}

    if(count==4){
    backend.telemetry10.write(getAccelerometer_YString());
    println(getAccelerometer_YString());}

    if(count==5){
    backend.telemetry11.write(getAccelerometer_ZString());
    println(getAccelerometer_ZString());}

    if(count==6){
    backend.telemetry12.write(getPressureString());
    println(getPressureString());}

    if(count==7){
    backend.telemetry13.write(getLightString());
    println(getLightString());}

    if(count==8){
    backend.telemetry14.write(getMagnetometer_XString());
    println(getMagnetometer_XString());}

    if(count==9){
    backend.telemetry15.write(getMagnetometer_YString());
    println(getMagnetometer_YString());}

    if(count==10){
    backend.telemetry16.write(getMagnetometer_ZString());
    println(getMagnetometer_ZString());}

    if(count==11){
    backend.telemetry17.write(getNoiseFloating());
    println(getNoiseFloating());
    count = 0;


    }
    }

     

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist