Hello, 

I try to to send sensor data over MQTT protocol using Mitta. It works in 20 minutes and then sensor can't anymore connect to Wlan. 

Hoping your soon answer, kind regards.

package main;
import platforms.xdk110;
native unchecked fn WLAN_Reconnect() header "XDK_WLAN.h";
native unchecked fn WlanNetworkConnect_GetIpStatus(): uint32 header "BCDS_WlanNetworkConnect.h";

let tempCorrection = 6.5975;
let disconnected = "WLANNWCT_STATUS_DISCONNECTED";

every button_one.pressed {
    println('Button one pressed');
}

setup npluspnet : WLAN {
    ssid = "nupis-iot";
    authentication = Personal(psk = "nupabc.123");
    //Ku,Fr+Ve,Ko+Ve,Ve,Qu+In.
}

setup backend : MQTT {
    transport = npluspnet;
    url = "mqtt://10.1.207.1:1883";
    clientId = "XDK2";
    var battery = topic("XDK2/battery");
    var temperature = topic("XDK2/temperature");
    var pressure = topic("XDK2/pressure");
    var humidity = topic("XDK2/humidity");
    var accelerometer = topic("XDK2/accelerometer");
//    var noise = topic("XDK2/noise");
    var gyroscope = topic("XDK2/gyroscope");
    var light = topic("XDK2/light");
    var magnetometer = topic("XDK2/magnetometer");
}

setup Gyroscope_BMI160 {
  range = Range_250s;
  bandwidth = BW_10_7Hz;
}

every 60000 milliseconds {
    checkWlanConnect();
    checkBattery();    
}

every 1000 milliseconds {
    checkTemperature();
    checkLight();
    checkPressure();
    checkHumidity();
    checkAccelerometer();
//    checkNoise();
    checkGyroscope();
/*    checkMagnetometer();*/
}

fn checkBattery() {
    let ps = XDK110.powerStatus.read();
    where(ps) {
           is(PowerStatus.Battery -> level) {
               backend.battery.write(`${level}`);
        }
        is(PowerStatus.Corded) {
               backend.battery.write(`100`);
        }
    }
}

fn checkMagnetometer() {
    var x = magnetometer.x_axis.read();
    var y = magnetometer.y_axis.read();
    var z = magnetometer.z_axis.read();
    var resistance = magnetometer.resistance.read();
    backend.magnetometer.write(`{ "x":${x}, "y":${y}, "z":${z}, "resistance":${resistance} }`);
}

fn checkGyroscope() {
    var x = gyroscope.x_axis.read();
    var y = gyroscope.y_axis.read();
    var z = gyroscope.z_axis.read();
    backend.gyroscope.write(`{ "x":${x}, "y":${y}, "z":${z}} `);
}
/*
 * 
 fn checkNoise() {
    var tmpNoise: float = readNoiseSensor() / 2048;
    backend.noise.write(`${tmpNoise}`);
}
*/
fn checkLight() {
    let tmpLight: double  = light.intensity.read() / 100.0;
    backend.light.write(`${tmpLight}`);
}

fn checkAccelerometer() {
    var x = accelerometer.x_axis.read();
    var y = accelerometer.y_axis.read();
    var z = accelerometer.z_axis.read();
    backend.gyroscope.write(`{ "x":${x}, "y":${y}, "z":${z}} `);

fn checkTemperature() {
    let temp=(environment.temperature.read() / 1000.0) - tempCorrection;
    backend.temperature.write(`${temp}`);
}

fn checkPressure() {
    let pressure: uint32 = environment.pressure.read() / 100;
    backend.pressure.write(`${pressure}`);
}

fn checkHumidity() {
    let humidity: uint32 = environment.humidity.read();
    backend.humidity.write(`${humidity}`);
}

fn checkWlanConnect() {
    var errorCode  = WlanNetworkConnect_GetIpStatus();
       if(errorCode == 3 || errorCode == 2)
       {
        // Stay here until connected and ip acquired.
           // Timeout logic can be added here.
        WLAN_Reconnect();
        println("Wlan reconnected");
    }
}

0 (0 투표)
RE: Wlan connect error after 20 sending data over MQTT
응답
19. 7. 30 오후 1:52 as a reply to Tuan Nguyen Hoang.

Hello Tuan Nguyen Hoang,

First of all thank you for using Mita and your Mita code looks impressive with good use of native functions.

I observed some compilation issues in WLAN_Reconnect() return type definition in line " native unchecked fn WLAN_Reconnect() header "XDK_WLAN.h";" and so. Hope you might have fixed the same.

In my perspective, failure has occurred due to MQTT connection timeout.

May i know how did you derive that wlan connection failed ?

 

+1 (1 투표)
RE: Wlan connect error after 20 sending data over MQTT
응답
19. 7. 31 오전 9:15 as a reply to Padmapriya G.
Hi Padmapriya,
Thank you for your answer. I have tried to connect the sensor with 2 different Wlan in 2 Branch of my company. In the first branch  the failure has not occurred, but in the second failure has occurred and then i can’t ping to IpAddress from Sensor. So i have thought that the connect between Sensor and Router was lost. Can you tell me, how can i fix the MQTT connection timeout failure ?
0 (0 투표)
RE: Wlan connect error after 20 sending data over MQTT
응답
19. 8. 7 오전 8:18 as a reply to Tuan Nguyen Hoang.

Hello,

Mita code you cannot configure MQTT timeout. Timeout is configured to 30 seconds, which is ok. I can propose you to check the second wifi network whether it permits to communicate with external network.

0 (0 투표)