I am sending sensor data from Bosch XDK sensor using MQTT protocol to an Android App. Everything works fine if the sampling frequency is below 100Hz. However, When I increase this frequency, the APP hangs and becomes unresponsive after a few seconds. I believe this could be a Code optimization problem for the App.
This is the function to handle incoming
This is the function to handle incoming MQTT message:
public void updateSensorValues(String mqttMessage){
try{
JSONArray jsonArray = new JSONArray(mqttMessage);
for(int i = 0;i<jsonArray.length();i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
jsonAccX.put(jsonObject.get("bma280_x"));
jsonAccY.put(jsonObject.get("bma280_y"));
jsonAccZ.put(jsonObject.get("bma280_z"));
jsonGyrX.put(jsonObject.get("bmg160_x"));
jsonGyrY.put(jsonObject.get("bmg160_y"));
jsonGyrZ.put(jsonObject.get("bmg160_z"));
jsonMagX.put(jsonObject.get("bmm150_x"));
jsonMagY.put(jsonObject.get("bmm150_y"));
jsonMagZ.put(jsonObject.get("bmm150_z"));
}
} catch (JSONException e){
System.out.println("Error " + e.getMessage());
}
}
Could anyone guide me if this an optimization problem in Java or I should receive data less frequently?
It is also important to mention that the XDK sensor only allows to transmit 997 characters at a time, therefore, I have to publish the data faster.