Code Monkey home page Code Monkey logo

Comments (19)

davidepianca98 avatar davidepianca98 commented on May 25, 2024 1

Thank you, I will try to find the problem as soon as possible

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

Hello, JitPack cannot provide the dependencies for Apple targets, I should update the Readme to let the users know. Anyway you can clone the repository, build it and publish it to maven local through Gradle. Then you can add maven local in the repositories of your project in build.gradle and you should be able to use the iOS dependencies. Keep in mind it's not been tested yet as I don't have Apple devices as of now.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Hey, thanks for the reply. I've ended up exploring a little bit the project and doing that afterwards. I was able to integrate it on my project but I didn't succeed to connect the MQTT Client (I'm using HiveMQ for the test). Anyways, I'll probably need to take a deep look on the code since I really wanted to integrate it in my project.

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

You can let me know what exactly is happening, so we can work together to solve the problem. I'm interested in expanding the supported platforms as much as possible. As I said I wasn't able to test the iOS implementation, but it's the same as on other POSIX platforms.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Sorry, I should have done that on my previous comment.
The error that is being retrieved is: kotlin.Exception: CONNACK not received in 30 seconds
This is my implementation:

                val client = MQTTClient(
                    mqttVersion = 5,
                    address = "broker.mqttdashboard.com",
                    port = 8000,
                    tls = null,
                    webSocket = true,
                    clientId = "clientId-myClientAsGhYi",
                ) {
                    print("## rjfc ## - ${it.payload?.toByteArray()?.decodeToString()}")
                }
                client.subscribe(
                    listOf(
                        Subscription(
                            topicFilter = "my_custom_topic",
                            SubscriptionOptions(Qos.EXACTLY_ONCE)
                        )
                    )
                )
                client.publish(
                    false,
                    Qos.EXACTLY_ONCE,
                    "my_custom_topic",
                    "hello from KMM".encodeToByteArray().toUByteArray()
                )
                client.run()

I would be happy to help you in that task, since I can provide support regarding Apple dependencies.

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

So it looks like the connection is setup correctly but the CONNACK packet doesn't get sent by the server or received. It would be interesting if you could try without websockets first. Or maybe you could even try to setup mosquitto on your computer and try to connect to it from the phone on your local network, so that you can run wireshark or a similar tool and get a packet trace to see exactly what is happening.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

I've tried without websockets and the result was the same: kotlin.Exception: CONNACK not received in 30 seconds
I've also done the Mosquitto procedure like you suggested and I was able to connect, subscribe and publish to my local network successfully.

The connection on Wireshark:
Screenshot 2023-04-12 at 17 25 53

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

Can you also try on test.mosquitto.org?

I have tried to use your exact code on Windows, to check if it was a problem with HiveMQ specifically, but it's working fine. Another option would be to run the code in the emulator (if possible) with Wireshark on the host to check what is happening to the TCP connection. Maybe the CONNECT packet is not even sent for some reason.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Same error on test.mosquitto.org: kotlin.Exception: CONNACK not received in 30 seconds

But this time, an interesting response. I didn't connect to test.mosquitto.org through my simulator (for some reason it was not recognising the host, giving me the error Socket connection failed: failed resolving address.) but I used my local Mosquitto server. The given error was the same (kotlin.Exception: CONNACK not received in 30 seconds) but this was what I could sniff on the Wireshark:
Screenshot 2023-04-13 at 17 04 10

Comparing with the previous sniff I sent, looks like he is trying to subscribe before connect ACK but I don't really know if that could be the issue. Therefore, he is not succeeding at writing the topic and the message.

This was what I got from the server logs:
Screenshot 2023-04-13 at 16 37 46

As you can see, at some point he connects with success but closes the connection after the 30 seconds. So, my guess would be that he can somehow communicate with the server but not receive any content from it.

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

You could try removing the subscribe and publish calls before callind run in your code, so the client will only try to connect. This way we should be able to tell if indeed the problem is the subscribe before the connack. Sending packets before receiving the connack is not a protocol violation, and indeed the server isn't closing the connection. It looks like the client is not reading correctly the data sent by the server. This could be a problem with my specific iOS implementation of the POSIX calls.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Removed the subscribe and publish and the issue remains. The logs keep telling that the client was able to connect and after the 30 seconds the client closes the connection. In the app, the CONNACK error remains as well.

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

Please try to clone the latest version and see if it's working correctly. I was able to test on macosX64 and I got the same problem, which is now solved. I'm hoping you could try it on iOS too.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Thanks for taking a look into it. I've tried it and now I have a different issue:
Screenshot 2023-04-20 at 19 12 58
It happened when I tried the tool with websockets and without it (locally). Wireshark didn't give much of information but this is what was shown as a log in the local server:
Screenshot 2023-04-20 at 19 39 30

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

Error 54 is connection reset by peer, so the broker is closing the connection because of the malformed packet. Are you sure you are matching the MQTT version between client and broker? This could be because the broker uses MQTT 3.1.1 and you are trying to connect with MQTT 5 for example.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Yap, you're totally correct. I forgot completely that and I made the test without having that in mind (MQTT newbie here). I'll test it as soon as I can and give you some feedback again.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Sorry for the delay but I ended up not having time to give you some feedback until today. However, I've noticed that you have added TLS support! Thanks for that! 🙏🏼

I ended up updating the repo but I'm facing another issue:

❌ Error Log
> Task :shared:kspKotlinIosArm64 FAILED
e: Could not find "openssl-ios-arm64" in [/Users/<my-user>/dashtt-shared/shared, /Users/<my-user>/.konan/klib, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/common, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/platform/ios_arm64]
> Task :shared:kspKotlinIosArm64 FAILED
e: Could not find "openssl-ios-arm64" in [/Users/<my-user>/dashtt-shared/shared, /Users/<my-user>/.konan/klib, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/common, /Users/<my-user>/.konan/kotlin-native-prebuilt-macos-x86_64-1.8.10/klib/platform/ios_arm64]

Execution failed for task ':shared:kspKotlinIosArm64'.
> Compilation finished with errors

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
Execution failed for task ':shared:kspKotlinIosArm64'.
> Compilation finished with errors

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

I suspect that the cause may be the fact that, in your openssl.def, you are pointing to your root files. Could you take a look on this?

Thanks in advance!

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

The def file is just to build OpenSSL. The library should be directly in the KMQTT dependency you are including in your project. Did you recompile KMQTT after updating it and published it to maven local? If yes, then please copy this file https://github.com/davidepianca98/KMQTT/blob/master/kmqtt-common/src/nativeInterop/openssl-ios-arm64.klib to one of the folders in the error while I try to find the problem.

from kmqtt.

ruicanas avatar ruicanas commented on May 25, 2024

Yap, I've done that but it's not working as well. This is what it retrieves me:

> Task :shared:linkDebugFrameworkIosArm64 FAILED
e: /Users/<my-user>/.gradle/caches/modules-2/files-2.1/com.github.davidepianca98/kmqtt-common-iosarm64/0.4.1/bb81191f70669a5e7a4d32c5fbcd289db7348a41/kmqtt-common is going to be cached, but its dependency isn't: /Users/<my-user>/<my-project>/openssl-ios-arm64

/Users/<my-user>/.gradle/caches/modules-2/files-2.1/com.github.davidepianca98/kmqtt-common-iosarm64/0.4.1/bb81191f70669a5e7a4d32c5fbcd289db7348a41/kmqtt-common is going to be cached, but its dependency isn't: /Users/<my-user>/<my-project>/openssl-ios-arm64


Execution failed for task ':shared:linkDebugFrameworkIosArm64'.
> Compilation finished with errors

from kmqtt.

davidepianca98 avatar davidepianca98 commented on May 25, 2024

I was able to reproduce the problem, but it's not clear why the library isn't getting included. To solve the second error (after copying the library to one of those directories) you can temporarily add this to your gradle.properties:

kotlin.native.cacheKind.iosX64=none
kotlin.native.cacheKind.iosArm64=none
kotlin.native.cacheKind.iosSimulatorArm64=none

from kmqtt.

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.