this is my code import java.util.Iterator;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SimpleMqttCallBack implements MqttCallback {
private final Logger logger = LoggerFactory.getLogger(FirstHandler.class);
@Override
public void connectionLost(Throwable throwable) {
logger.info("conection lost");
}
@Override
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
logger.info("inside messageArrived");
String a = new String(mqttMessage.getPayload()); //converting the mqtt message ofjson format in a string
logger.info(a + "\n");
String sbr = a.substring(1, 7);
logger.info(sbr + "\n"); //substring of the string,the code is running fine
JSONArray jsonArray = new JSONArray(a);
//after this line i got connection lost in my log file..may i know the reason
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json = jsonArray.getJSONObject(i);
JSONObject wallet = (JSONObject) json.get("d");
Iterator<String> keys1 = wallet.keys();
while (keys1.hasNext()) {
// ChannelUID channelUID;
String key1 = keys1.next();
if (key1.equals("A_Temperature")) {
logger.info("inside temper");
logger.info(key1 + "\t" + wallet.get(key1));
}
if (key1.equals("A_Humidity")) {
logger.info("inside humi");
logger.info(key1 + "\t" + wallet.get(key1));
}
if (key1.equals("A_Pressure")) {
logger.info("inside pres");
logger.info(key1 + "\t" + wallet.get(key1));
}
}
}
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
}
WHOLE CODE IS RUNNING FINE IN JAVA, BUT IN OPENHAB LOGS I GOT CONNECTION LOST!!!
IS THERE ANY PROBLEM WITH THE LIBRARY THAT I AM USING “javax.json-1.0.4.jar”
i also add /lib/javax.json-1.0.4.jar in classpath in manifest file…
why it is happening…