Skip to content

Getting started

Kees Schollaart edited this page Mar 22, 2020 · 9 revisions

Prerequisites

  • Create an Azure Function using Visual Studio or using Visual Studio Code
  • Make sure your Microsoft.NET.Sdk.Functions package version is 1.0.23 or higher
  • For local development: Make sure your Functions SDK is up to date (make sure you have V2 installed) [howto-1 & howto-2]
  • Install the CaseOnline.Azure.WebJobs.Extensions.Mqtt NuGet package in you Functions Project
  • Add a connectionstring to your 'local.settings.json' during development time or in Azure to your Application Settings
  • When deploying/running on Azure, make sure the application-setting FUNCTIONS_EXTENSION_VERSION to ~2.

The Connectionstring

The default name/key for the connectionstring is MqttConnection.

The available parts are:

  • Server (just the dns/hostname)
  • Username (string, optional)
  • Password (string, optional)
  • Port (integer, optional, defaults to 1883 or 8883 when tls=true)
  • Tls (boolean, optional, defaults to false)
  • ClientId (string, optional, defaults to a random Guid)

Example Connectionstring

This is an example of the local.settings.json file

{ 
        "IsEncrypted": false,
	"Values": {
                "AzureWebJobsStorage": "UseDevelopmentStorage=true",
		"MqttConnection": "Server=<<my.mqttserver.com>>;Username=<<username>>;Password=<<password>>"
	}
}

Multiple connections

Is is possible to work with multiple connections but it is also possible to reuse connections for multiple triggers or outputs. When adding a second connectionstring to your settings make sure to point to this connectionstring using the ConnectionString property on the Mqtt(Trigger) attribute.