Coder Social home page Coder Social logo

Comments (20)

hannesa2 avatar hannesa2 commented on August 15, 2024 1

Indeed, this lines are probably crap

// THIS DOES NOT WORK!
mqttAndroidClient.subscribe(subscriptionTopic, 0, new IMqttMessageListener() {
@Override
public void messageArrived(String topic, MqttMessage message) {
Log.d("Message arrived", topic + " : " + new String(message.getPayload()));
}
});

Anyway, I assume this is the main reason https://developer.android.com/about/versions/oreo/background.html
Here is the discussion eclipse/paho.mqtt.android#281

I would love when someone would implement a solution with https://developer.android.com/reference/android/app/job/JobScheduler.html . I would approve immediate

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

Thanks for the reply. I didn't have an idea of the changes from Android 8 on.
It seems to me now that we can forget about long time TCP connections and about a reliable and instant MQTT transfer as well :(

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

Yes, this is the biggest problem in this library. Maybe I will fix it in the next few days, but I promise nothing

There is no reason to give up that early. You can switch back to
targetSdkVersion 24 then I expect to work properly.

But with this you can't publish to Google play store anymore

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

The thing is how to test it in Espresso test this background service behavior ?

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

@JiriBilek Your have to help me.

I following your connection String serverUri = "tcp://broker.hivemq.com:1883";

Does this works for you, or is it my network connection ? (I'm on vacation, and maybe the port it locked in my hotel)
image

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

In your example, I had to add to the manifest more privileges to be able to connect:

    <!-- Permissions the Application Requires -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

In your example,

It's the example, not mine 😉 I just try to keep this library alive.

Please see #84 This solves only the init crash.
And yes there are too less permission, and unfortunately it's doesn't show any error when it's missing 👎

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

I tried the example on Android 5.1 and it lost the connection as well.

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

I try to reproduce it, but till now I failed.
image

This looks not that bad.

How does it looks like on your side ?

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

It looks the same. Between "The Connection was list" and "Reconnected" is losing the data from the broker.

image

The last line is confusing - failed connection because already connected. Weird.

I use QoS 0 as I my intention is to know about the event asap. I am monitoring a beehive (bumblebees, actually).

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

my intention is to know about the event asap

It has the touch of eclipse/paho.mqtt.android#281 (comment) Solution 1 with forground services You battery will be empty sooner, but everything has a price

Anyway I tried to introduce a test to capture the error case with #98 and #96 and to be honest I need help here to first have 1 #reproduce able issue, then (only after this) I can look for a 2 #solution.

For a better understanding it comes with screenshots of test case
image

I'm stuck on 1 #reproduce able issue. You are warmly welcome to jump into this.

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

Yes, I read the comment about foreground services. It may solve my problem. It'll take me time as I must study the android services first. Until now, I took the paho.mqtt library as such and have not studied the internals in it.

As to the tests, I want to help but I don't understand what should I do.

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

As to the tests, I want to help but I don't understand what should I do.

I need to know, how to reproduce it.

Btw, the BasicDemo can send a message, but never receive it. -wtf-

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

Between "The Connection was list" and "Reconnected" is losing the data from the broker.

Did you changed the qos (quality of service) ? Maybe it helps.
Btw, when you do your changes in a branch of your fork, I could at least follow what you did

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

Ok, I must leave now but in the afternoon I'll fork the repo and play with the qos.

from paho.mqtt.android.

JiriBilek avatar JiriBilek commented on August 15, 2024

I forked the repo, made necessary changes (JiriBilek@8eda6ae) and run it. It run without losing the connection for 30 minutes while the phone was connected to the usb for the whole time. Shortly after disconnecting the usb cable, it lost the connection.

image

Still Android 5.1.

Edit: I realized that with the USB power, my old app runs fine and holds the connection like a charm. Next, I'll try the same on Android 10.

Edit2: I checked out the AwakeTest and run it. As long as the phone was connected to the PC (and charging), it held the connection. After plugging out, the connection was lost.

from paho.mqtt.android.

HubKing avatar HubKing commented on August 15, 2024

Can my app receive the MQTT message even if the screen is turned off or my app is not the foreground app, with this library? The "basic sample" seems to be working, but that was with my app in the foreground with the screen on. My app would not be very useful if I have to keep the screen on and my app as the foreground app to receive the MQTT message.

If it is possible, would you add another simple sample project to show the incoming message in the system notification when the app is not the foreground app or the screen is turned off?

from paho.mqtt.android.

hannesa2 avatar hannesa2 commented on August 15, 2024

Without foreground service, you could give https://github.com/hannesa2/paho.mqtt.android/releases/tag/3.4.0-beta5 a try.
I uses Workmanager to avoid to keep device always on.

from paho.mqtt.android.

stale avatar stale commented on August 15, 2024

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

from paho.mqtt.android.

stale avatar stale commented on August 15, 2024

Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution.

from paho.mqtt.android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.