Skip to main content

PSMQTT

This project has adopted the following policies CodeOfConduct Contributing Security

Project status​

GitHub Workflow Status Codecov Platform PowerShell Gallery License docs changelog GitHub release (latest SemVer including pre-releases) GitHub release (latest SemVer including pre-releases)

About​

This powershell module allows you to connect to a MQTT broker and post new messages as well as subscribing to a topic to receive new messages.

Installation​

To install from the PowerShell gallery using PowerShellGet run the following command:

Install-Module PSMQTT -Scope CurrentUser

Usage​

Start by connecting to the MQTT broker with Connect-MQTTBroker. You can connect either annonymous or with username & password

# With username & password

$Session = Connect-MQTTBroker -Hostname mqttbroker.contoso.com -Port 1234 -Username mqttuser -Password (ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force)

# Annonymous

$Session = Connect-MQTTBroker -Hostname mqttbroker.contoso.com -Port 1234

To send a message to the MQTT broker use Send-MQTTMessage

Send-MQTTMessage -Session $Session -Topic 'foo' -Payload '{"attribute":"value"}'

To subscribe to messages sent to the MQTT broker, use Watch-MQTTTopic

Watch-MQTTTopic -Session $Session -Topic "topic/#"

You can subscribe to subtopics by using / and you can also use wildcards with # as in the example above.

One you are done you can close the session by calling Disconnect-MQTTBroker

Disconnect-MQTTBroker -Session $Session