Subscribe to AWS broke with keys? #38
Replies: 7 comments 21 replies
-
from the looks of it, I am not seeing a possible way to connect to AWS MQTT |
Beta Was this translation helpful? Give feedback.
-
Please let me know if this is helpful: #24 (comment) |
Beta Was this translation helpful? Give feedback.
-
This is my following line.after the creation of the MQTTClient object
client.subscribe(
listOf( Subscription(
"thing-update/GLOBALMARINE/MAOEM/MAOEM_MTC/D-C4DD57AA3AA4/#",
SubscriptionOptions(
Qos.EXACTLY_ONCE))
)
)
client.run()
…On Mon, Mar 18, 2024 at 4:20 PM Davide Pianca ***@***.***> wrote:
Can you please give a brief explanation of how you setup the broker so
that I can try to reproduce the issue?
—
Reply to this email directly, view it on GitHub
<#38 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNN3B4KKFIXKV3CLDQHJYTYY5LAVAVCNFSM6AAAAABDFOG5BSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DQMZTGIYTS>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I just tested with AT_MOST_ONCE and AT_LEAST_ONCE, both of those take me
back to UNSPECIFIED_ERROR. where EXACTLY_ONCE gave me a
SocketClosedException.
We are using AWS IOT Core. It has to be wss://<>/mqtt, I get AWS
credentials and I pass it in to a signv4 algorithm and return the URI. I
then use that with the address to make the connection. My topic is set up
correctly, and for our other javascript connections we do not use a
clientId, (I have attempted with both)
I was really hopeful that it was the QoS. And it still might be with a
combination of other things, those of which I have yet to figure out. :/
… Message ID: <davidepianca98/KMQTT/repo-discussions/38/comments/8857367@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
This is exactly what I had done. your steps with the aws_signv4 is what I
had used to test. Then I took the mqtt URI and stuck it into mqttclient. I
then converted that repo into kotlin and have that working in creating the
signed URL which I tested by usin it back into that aws_signv4 repository.
Here is my code...
val signv4Url: String = generateSignv4Mqtt(host, region, awsKeys.accessKey,
awsKeys.secretKey, awsKeys.sessionToken)
val client: MQTTClient = MQTTClient(
MQTTVersion.MQTT5,
address = host,
webSocket = signv4Url,
port = 443,
tls = TLSClientSettings(),
clientId = generateRandomClientId(),
) {
val payload = it.payload?.toByteArray()?.decodeToString()
println("AWSListener: $payload")
}
client.subscribe(
listOf( Subscription(
"thing-update/GLOBALMARINE/MAOEM/MAOEM_MTC/D-C4DD57AA3AA4/#",
SubscriptionOptions(
Qos.*AT_LEAST_ONCE*))
)
)
client.run()
StackTrace
:47.195 13946-14027 AndroidRuntime com.dometic.test.mtcv2
E FATAL EXCEPTION: DefaultDispatcher-worker-3
Process: com.dometic.test.mtcv2, PID: 13946
mqtt.MQTTException: UNSPECIFIED_ERROR
at MQTTClient.handleSuback(MQTTClient.kt:565)
at MQTTClient.handlePacket(MQTTClient.kt:389)
at MQTTClient.check(MQTTClient.kt:300)
at MQTTClient.step(MQTTClient.kt:367)
at MQTTClient.run(MQTTClient.kt:377)
at
DometicMQTTClient$1.invokeSuspend(DometicMQTTClient.kt:113)
at
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at
kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at
kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at
kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
at
kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Suppressed:
kotlinx.coroutines.internal.DiagnosticCoroutineContextException:
***@***.***, Dispatchers.IO]
…On Thu, Mar 21, 2024 at 3:39 AM Davide Pianca ***@***.***> wrote:
This is what I did to test it with the WebSocket connection, please let me
know if anything is different from your setup.
1. AWS IAM service
2. Create a new user
3. Give it the policy AWSIoTDataAccess
4. Create Access Key
5. Copy the access key and secret key
6. Generate the mqtt websocket URL as mentioned here:
https://github.com/pedrohbtp/aws_signv4_mqtt?tab=readme-ov-file#how-to-use-use
:
- pip install boto3
- pip install aws-signv4-mqtt
- aws_signv4_mqtt.generate_signv4_mqtt(iot_host, iot_region,
access_key, secret_key)
- Copy the "/mqtt?..." part of the URL
This is my Kotlin code:
val client = MQTTClient(
MQTTVersion.MQTT5,
"iot_host.iot.iot_region.amazonaws.com",
443,
TLSClientSettings(serverCertificate = "C:\\Users\\david\\IdeaProjects\\KMQTT\\AmazonRootCA1.pem"),
30,
webSocket = "/mqtt?..." ) {
println(it.payload?.toByteArray()?.decodeToString())
}
client.subscribe(listOf(Subscription("sdk/test/js", SubscriptionOptions(Qos.AT_LEAST_ONCE))))
thread {
while (true) {
Thread.sleep(5000)
client.publish(false, Qos.AT_MOST_ONCE, "sdk/test/js", "hello1".toByteArray().toUByteArray())
}
}
client.run()
EXACTLY_ONCE is giving socket closed exception because AWS closes the
connection when you try to publish or subscribe with that Qos value. While
when subscribing to a topic which is not allowed you get an error in the
SUBACK packet saying that the subscription was not enabled but the
connection remains open.
Can you send the stack trace of the UNSPECIFIED_ERROR you are getting? It
might be because of something else and I would like to see exactly where in
the code it is happening.
—
Reply to this email directly, view it on GitHub
<#38 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNN3BYO2M2FHVSIVMPCYFLYZKMFLAVCNFSM6AAAAABDFOG5BSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DQNRSGU4TI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Here I'm connected through Postman.
[image: image.png]
…On Thu, Mar 21, 2024 at 2:48 PM Davide Pianca ***@***.***> wrote:
Again here the broker is returning unspecified error when trying to
subscribe. You said you were able to subscribe with this exact topic filter
and qos combination also from other clients? Because it really seems the
problem is that this client is not allowed to subscribe to this but the
broker is giving back a generic error unfortunately. Please try this exact
subscription from another client if possible. Also you can try using qos
AT_MOST_ONCE and/or going more specific with the topic subscription instead
of using the wildcard.
This is getting really weird.
—
Reply to this email directly, view it on GitHub
<#38 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNN3B3WGIQ6A5DNCG4M6WLYZM2R5AVCNFSM6AAAAABDFOG5BSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DQNZQGM2TK>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I will give a go at one of the topics instead of wild card, but AWS IoT
says wildcards should work. This really isn't making any sense... I'm happy
the connection is working, and we're getting an acknowledgement. but It is
bizarre that the subscriptions are dying. I don't ever get Not_Authorized.
but I'm not currently publishing. I will be in the future. I'll attempt to
publish something in the meantime too, but I won't get to it for a couple
of days. I appreciate you looking at this, and any more info that you find
out would be greatly helpful.
…On Fri, Mar 22, 2024 at 8:33 AM Davide Pianca ***@***.***> wrote:
The image is not showing. Anyway what happens if you try to subscribe to a
more specific topic that you know is being used like
"thing-update/GLOBALMARINE/MAOEM/MAOEM_MTC/D-C4DD57AA3AA4/*topic1*"?
I also have been testing a bit more with policies. When subscribing to a
topic which is not allowed I'm getting NOT_AUTHORIZED. When publishing to a
topic not allowed I'm getting socket closed. So this UNSPECIFIED_ERROR for
the corresponding subscription in the SUBACK packet is even more baffling.
—
Reply to this email directly, view it on GitHub
<#38 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNN3B2RLFCCYBDIA3MILHLYZQXL3AVCNFSM6AAAAABDFOG5BSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DQNZYGI4DQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
My existing broker has authentication to be accesskey,secretkey and token... how might I implement this library to connect?
Beta Was this translation helpful? Give feedback.
All reactions