Skip to content

Commit

Permalink
Add dotnet Template (#8)
Browse files Browse the repository at this point in the history
* upd to 0.23

* upd to 0.5

* Template (#7)

* add template, remove docker

* prep pkg

* pack template in ci

* pack template

* fix list pkgs
  • Loading branch information
ridomin authored Nov 14, 2022
1 parent e2a203f commit 4ff53ff
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 112 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@ on:

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
working-directory: mqtt-device

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
run: dotnet restore ./mqtt-device/
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore ./mqtt-device/
- name: Pack template package
run: dotnet pack ./mqtt-device-template.csproj
- name: List packages
run: |
echo "## Installed Packages " >> $GITHUB_STEP_SUMMARY
echo " " >> $GITHUB_STEP_SUMMARY
dotnet list package >> $GITHUB_STEP_SUMMARY
dotnet list ./mqtt-device/ package >> $GITHUB_STEP_SUMMARY
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

This repo can be used as a template repo to create new MQTT devices using [MQTTnet.Extensions.MultiCloud](https://github.com/iotmodels/MQTTnet.Extensions.MultiCloud)

```bash
dotnet new install IoTModels.MqttDevice.Template
dotnet new mqtt-device -o myDevice
```

## What is in this template?

- A dotnet 6.0 worker project
- With references to MQTTnet MultiCloud extensions
- A sample device template model
- The C# interface representing the device model
- Implementations for Azure IoT Hub and MQTT Broker
- Implementations for Azure IoT Hub and any MQTT Broker
- Sample Device implementation
- Default launch settings for different endpoints
- Sample CA certificate to connect to [mosquitto-local](https://github.com/ridomin/mosquitto-local)

### Device Model

Expand All @@ -23,10 +27,10 @@ The device implements:

## How to run

The dotnet project contains a `launchSettings.json.template` with some pre-configured profiles. To avoid publishing this file with credentials, this file it's git.ignored. Run `./init-template.sh` to rename this file, then use `dotnet run --launch-profile <profile>`.
The dotnet project contains a `launchSettings.json` with some pre-configured profiles.

### MQTT Broker
To connect to a local MQTT broker like mosquitto, you can use the [mosquitto-local](https://github.com/ridomin/mosquitto-local) Docker image.
To connect to a local MQTT broker like mosquitto, you can use the [mosquitto-local](https://github.com/ridomin/mosquitto-local) Docker image. To connect with TLS you have to provide the CA certificate.

```
docker run -it --rm -p 8080:8080 -p 1883:1883 -p 8883:8883 -p 8884:8884 -p 8443:8443 ridomin/mosquitto-local:dev
Expand Down
30 changes: 30 additions & 0 deletions mqtt-device-template.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>0.1</PackageVersion>
<PackageId>IoTModels.MqttDevice.Template</PackageId>
<Title>MQTT Device</Title>
<Authors>ridomin</Authors>
<Description>Project template to create MQTT Devices, compatible with DTDL interfaces</Description>
<PackageTags>mqtt;iot;dtdl</PackageTags>

<TargetFramework>net6.0</TargetFramework>

<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
<NoWarn>$(NoWarn);NU5128</NoWarn>
<NoDefaultExcludes>true</NoDefaultExcludes>

<Copyright>copyleft</Copyright>
<PackageProjectUrl>https://github.com/iotmodels/device-template</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<Content Include="mqtt-device\**\*" Exclude="mqtt-device\**\bin\**;mqtt-device\**\obj\**" />
<Compile Remove="**\*" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions mqtt-device/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "rido",
"classifications": [ "Common", "Worker" ],
"identity": "MQTTNet.IoT.Device",
"name": "MQTT Device",
"shortName": "mqtt-device",
"preferNameDirectory": true,
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "mqtt-device",
"postActions": [{
"description": "To run this project you must specify the MQTT Connection Settings.",
"manualInstructions": [{
"text": "dotnet run /ConnectionStrings:cs=<Your Connection String>"
}],
"actionId": "AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C"
}]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using dtmi_com_example_devicetemplate;
// <auto-generated/>
#nullable enable

using dtmi_com_example_devicetemplate;
using MQTTnet.Extensions.MultiCloud.AzureIoTClient;
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient;
using MQTTnet.Extensions.MultiCloud.Connections;
Expand Down
20 changes: 0 additions & 20 deletions mqtt-device/Dockerfile

This file was deleted.

47 changes: 0 additions & 47 deletions mqtt-device/Properties/launchSettings.json.template

This file was deleted.

32 changes: 0 additions & 32 deletions mqtt-device/ca.pem

This file was deleted.

0 comments on commit 4ff53ff

Please sign in to comment.