0

I'm trying to publish a message via MQTT. So I created a blank Android app and added the Paho MQTT library to it.

This is the line of code I execute first:

MqttClient client = new MqttClient("tcp://192.168.178.34", "Foo");

This throws an "MqttException" which contains no message, no error code, no nothing. So currently I have no idea what's going wrong.

I also added the following permissions to my app:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Can anyone give me a hint what I could be doing wrong here?

tommybee
  • 2,409
  • 1
  • 20
  • 23
Boris
  • 8,551
  • 25
  • 67
  • 120

1 Answers1

0

In the code, The activated class is the TCPNetworkModule class which is using connect method of the socket class directly(see the start method of the class).

I think the exception might be the NetworkOnMainThreadException attempting to use blocking IO.

That's why we use MqttAndroidClient instead.

tommybee
  • 2,409
  • 1
  • 20
  • 23