powershellmqtt

PowerShell and M2MQTT


I'm trying to create a simple MQTT client in PowerShell to receive some messages from a broker. This broker is using a non standard port.

To do that, I followed the instructions I found at https://jackgruber.github.io/2019-06-05-ps-mqtt/

When using the example's code it's working fine but when I'm trying to specify a port like

$MqttClient = [uPLibrary.Networking.M2Mqtt.MqttClient]("mqtt-broker.net",41383)

it throws the error:

Cannot convert the "System.Object[]" value of type "System.Object[]" to type "uPLibrary.Networking.M2Mqtt.MqttClient".
At line:1 char:1
+ $MqttClient = [uPLibrary.Networking.M2Mqtt.MqttClient]("ext.mqtt.drya ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : ConvertToFinalInvalidCastException 

Any ideas?


Solution

  • I managed to specify the port by doing this:

    enum MqttSslProtocols
    {    None
        SSLv3
        TLSv1_0
        TLSv1_1
        TLSv1_2
    }
    
    $sslProtocol = [MqttSslProtocols]::TLSv1_2
    $MqttClient = [uPLibrary.Networking.M2Mqtt.MqttClient]::new("my-url",8883,$true,$null,$null,$sslProtocol)
    

    You need to match the parameters of one of the constructor signatures.