Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Help! Paho MQTT Android Application

Hi Golnaz,

as you can see, the exception is related to the "default file persistence", which is used to store the client state on disk or other file system, so it can be retrieved if the client is recreated.

The default location for the file system persistence (. I think) is probably not writeable on your Android system.  Two solutions, if this is the case:

1) turn off the file persistence completely, by creating the client like so:

client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2", null);

2) set the file persistence to a writeable directory:

MqttDefaultFilePersistence fp = MqttDefaultFilePersistence("writeable directory name");
client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2", fp);


Ian


On 05/02/14 13:23, Golnaz Makhtoumi wrote:

Hi All,

 

I want to stablish a connection to local broker (Mosquitto) by MQTT.

The simple java project is working and I can publish a message.

 

But now when I want to use the same concept in Android project, it only goes to exception.

Here is the main code inside the MQTTService.java (which is a service)

 

@Override

            public void onCreate() {

                         // TODO Auto-generated method stub

                         super.onCreate();

            Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

                         try {

                               client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2");

                               client.connect();

                               MqttMessage message = new MqttMessage();

                               message.setPayload("A single wessage".getBytes());

                               client.publish("pahodemo/test", message);

                              client.disconnect();

                             } catch (MqttException e) {

                               Toast.makeText(this, "went to exception", Toast.LENGTH_LONG).show();

                               e.printStackTrace();

                              

                             }

            }

 

It seems like it does go into try but cannot create instance of MqttClient and then throws exception.

 

In logcat under syste,.err tag I get MqttException(0) at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:76)

And so on..

 

What am I doing wrong?

 

Thanks in advance

 



_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev


Back to the top