0

I am trying to connect to an AWS MQTT broker/server using the Hive MQ client library for Android Studio (v1.3.0) with an AWS pre-signed URL.

implementation("com.hivemq:hivemq-mqtt-client:1.3.0")
implementation(platform("com.hivemq:hivemq-mqtt-client-websocket:1.3.0"))

The parameters I am using are shown below with the sensitive information removed:

host: xxx.amazonaws.com
path: /mqtt?X-Amz-Algorithm=xxx&X-Amz-Credential=xxx&X-Amz-Date=xxx&X-Amz-SignedHeaders=host&X-Amz-Signature=xxx

This is my latest attempt to connect:

MqttClient.builder()
    .identifier(UUID.randomUUID().toString())
    .serverHost(host)
    .webSocketConfig()
        .serverPath(path)
     .applyWebSocketConfig()
     .sslWithDefaultConfig()
     .useMqttVersion3()
     .build()

But when connecting, I get the error:

com.hivemq.client.mqtt.exceptions.ConnectionFailedException: io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: Invalid handshake response getStatus: 426 Upgrade Required

  • have you figured it out? – Boni2k Oct 04 '22 at 08:37
  • From what I remember the "426 Upgrade Required" was usually because the pre-signed URL had expired or was invalid, and happened with other MQTT clients too. – Jonathan Mason Oct 05 '22 at 09:06
  • Can confirm - at least for Hive MQ it was caused by URI encoding issues: https://community.hivemq.com/t/connect-mqtt-broker-with-pre-signed-url/751/9 I finally managed to make it work with paho and the signed URL - but I had to to write the keys all in lowercase: "wss://host:443/mqtt?x-amz-customauthorizer-signature=${URLEncoder.encode(sig)}&token_name=${URLEncoder.encode(token)}&x-amz-customauthorizer-name=${URLEncoder.encode(authname)}" – Boni2k Oct 06 '22 at 12:11

0 Answers0