br-automation-com / paho.mqtt.c-ar

MQTT Client for Automation Runtime based on eclipse/paho.mqtt.c
17 stars 6 forks source link

Unable to specify path when using MQTT over websockets #30

Open abdiel-mireles opened 11 months ago

abdiel-mireles commented 11 months ago

When using mqtt over websockets, paho defaults the websocket path to '/mqtt' if one is not provided in the URI. It seems that even if you add a path to the URI in the IoTMqtt_Client though, the path is never actually used. This is not normally an issue, but when connecting to Azure IoT Hub, the path is required to be '/$iothub/websocket'. Obviously, this wouldn't be an issue in TCP but unfortunately, at the moment, we can only use websockets for our connection. Is there a way for us to specify the path correctly?

image

patricthysell commented 11 months ago

Hi, the current implementation does not support an additional path on top of the server name, think the current code says it all. We would need to add an additional Parameters->ServerPath for that to work. At this point, I cannot give you any timeline for the addon. If possible, take contact with your local sales representative that we coordinate it that way. Thanks.

    if (Parameters->ConnectionType == IotMqtt_WS)
    {
        if (Parameters->TLS.UseTLS)
        {
            snprintf(Internal->host,sizeof(Internal->host),"wss://%s:%d",(char*)Parameters->ServerUri,Parameters->Port);
        }   
        else
        {
            snprintf(Internal->host,sizeof(Internal->host),"ws://%s:%d",(char*)Parameters->ServerUri,Parameters->Port);
        }
    }
patricthysell commented 10 months ago

Hi again @abdiel-mireles - I came to think of the PahoMQTT library, which exports the complete paho mqtt API as c functions to be called in your user task. This Library is also part of this repository, whereas you would need to do some more coding to get it all to work. Theres a sample in Samples/LegacySamples/SampleParam which should get you started, and as it is the standard paho api, it is identical to using the paho c-api under eg. Linux. In any case, with this you would be able to set the path as you desire. Let me kow how it goes. cheers.