react-native-paho-mqtt icon indicating copy to clipboard operation
react-native-paho-mqtt copied to clipboard

My mqtt is not working when i am using the release version but it is working when i am using it in build format

Open Harshkhosla opened this issue 1 year ago • 5 comments

export const Click = (user) => { // debugger; // console.log(user, "coming hear"); return (dispatch) => { // const { authtoken, field2 } = user; // console.log(authtoken,"ekvhjwejh");

const client = new Client({ uri: 'ws://192.168.10.111:9001/ws', clientId: 'JOULS ECOTECH243546578989', storage: myStorage });
// set event handlers
client.on('connectionLost', (responseObject) => {
  if (responseObject.errorCode !== 0) {
    console.log(responseObject.errorMessage);
  }
});
const onConnect = () => {

  client.on('messageReceived', (message) => {
    console.log(message?.payloadString);
    dispatch(setAuthtoken(message?.payloadString));
  });
}

client.connect()
  .then(() => {
    // Once a connection has been made, make a subscription and send a message.
    console.log('onConnect');
    return client.subscribe('Jouls_Ecotech_User_Notifications');
  })
  .then(() => {
    const sampleee ={
      "Charging Mode": "Balanced_Mode"
    }
    const message = new Message(JSON.stringify(user));
    message.destinationName = 'Jouls_Ecotech_User_ID';
    // const sample = new Message(JSON.stringify(sampleee));
    // sample.destinationName = 'Jouls_Ecotech_User_Charging Modes';
    client.send(message);
    // client.send(sample);
  }).then(() => {
    onConnect()
  })
  .catch((responseObject) => {
    if (responseObject.errorCode !== 0) {
      console.log('onConnectionLost:' + responseObject.errorMessage);
    }
  })


//   client.onConnectionLost = onConnectionLost;
//   client.onMessageArrived = onMessageArrived;

} } my code in this the connection is happning when my app is in build form but when i release it to play store or use its release format it is giving connection error .

Harshkhosla avatar May 31 '23 13:05 Harshkhosla

Did you get this working? Seems I have the same issue after upgrading to expo 49 and SDK Version 33. Dev build connects to mqtt as expected. Production release does not. Any help is highly appreciated!

GaWr26 avatar Oct 03 '23 13:10 GaWr26

Yes i get it working , you have to enable the working of production build . In this file android/app/src/debug/AndroidManifest.xml try checking if these permissions included in your file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:usesCleartextTraffic="true"
        tools:targetApi="28"
        android:networkSecurityConfig="@xml/network_security_config"
        tools:ignore="GoogleAppIndexingWarning">
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
    </application>

If you still face any problem feel free to contact me.

Harshkhosla avatar Oct 03 '23 15:10 Harshkhosla

Thanks for the quick reply. I figured out it has to do with my broker not using TLS encryption. Connecting to an encrypted broker works. I will open a new issue to see how to connect in my case

GaWr26 avatar Oct 04 '23 09:10 GaWr26

NO issues . Good to be able to help.

Harshkhosla avatar Oct 06 '23 11:10 Harshkhosla

@Harshkhosla I've tried adding the permissions and the issue persists. I used to be able to connect to my local network broker in Expo SDK 48 but not in Expo 49. I'm not sure how to go about it without downgrading to 48. Can you please try to help me? I'm creating a local build with expo prebuild and then, after modifying the file, running ./gradlew assembleRelease --stacktrace

bearkillerPT avatar Oct 17 '23 13:10 bearkillerPT