Skip to content

Commit 4ff53ff

Browse files
authored
Add dotnet Template (#8)
* 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
1 parent e2a203f commit 4ff53ff

8 files changed

Lines changed: 68 additions & 112 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@ on:
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
13-
defaults:
14-
run:
15-
working-directory: mqtt-device
16-
1712
steps:
1813
- uses: actions/checkout@v3
1914
- name: Setup .NET
2015
uses: actions/setup-dotnet@v2
2116
with:
2217
dotnet-version: 6.0.x
2318
- name: Restore dependencies
24-
run: dotnet restore
19+
run: dotnet restore ./mqtt-device/
2520
- name: Build
26-
run: dotnet build --no-restore
21+
run: dotnet build --no-restore ./mqtt-device/
22+
- name: Pack template package
23+
run: dotnet pack ./mqtt-device-template.csproj
2724
- name: List packages
2825
run: |
2926
echo "## Installed Packages " >> $GITHUB_STEP_SUMMARY
3027
echo " " >> $GITHUB_STEP_SUMMARY
31-
dotnet list package >> $GITHUB_STEP_SUMMARY
28+
dotnet list ./mqtt-device/ package >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
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)
44

5+
```bash
6+
dotnet new install IoTModels.MqttDevice.Template
7+
dotnet new mqtt-device -o myDevice
8+
```
9+
510
## What is in this template?
611

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

1620
### Device Model
1721

@@ -23,10 +27,10 @@ The device implements:
2327

2428
## How to run
2529

26-
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>`.
30+
The dotnet project contains a `launchSettings.json` with some pre-configured profiles.
2731

2832
### MQTT Broker
29-
To connect to a local MQTT broker like mosquitto, you can use the [mosquitto-local](https://github.com/ridomin/mosquitto-local) Docker image.
33+
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.
3034

3135
```
3236
docker run -it --rm -p 8080:8080 -p 1883:1883 -p 8883:8883 -p 8884:8884 -p 8443:8443 ridomin/mosquitto-local:dev

mqtt-device-template.csproj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageType>Template</PackageType>
5+
<PackageVersion>0.1</PackageVersion>
6+
<PackageId>IoTModels.MqttDevice.Template</PackageId>
7+
<Title>MQTT Device</Title>
8+
<Authors>ridomin</Authors>
9+
<Description>Project template to create MQTT Devices, compatible with DTDL interfaces</Description>
10+
<PackageTags>mqtt;iot;dtdl</PackageTags>
11+
12+
<TargetFramework>net6.0</TargetFramework>
13+
14+
<IncludeContentInPack>true</IncludeContentInPack>
15+
<IncludeBuildOutput>false</IncludeBuildOutput>
16+
<ContentTargetFolders>content</ContentTargetFolders>
17+
<NoWarn>$(NoWarn);NU5128</NoWarn>
18+
<NoDefaultExcludes>true</NoDefaultExcludes>
19+
20+
<Copyright>copyleft</Copyright>
21+
<PackageProjectUrl>https://github.com/iotmodels/device-template</PackageProjectUrl>
22+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<Content Include="mqtt-device\**\*" Exclude="mqtt-device\**\bin\**;mqtt-device\**\obj\**" />
27+
<Compile Remove="**\*" />
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "rido",
4+
"classifications": [ "Common", "Worker" ],
5+
"identity": "MQTTNet.IoT.Device",
6+
"name": "MQTT Device",
7+
"shortName": "mqtt-device",
8+
"preferNameDirectory": true,
9+
"tags": {
10+
"language": "C#",
11+
"type": "project"
12+
},
13+
"sourceName": "mqtt-device",
14+
"postActions": [{
15+
"description": "To run this project you must specify the MQTT Connection Settings.",
16+
"manualInstructions": [{
17+
"text": "dotnet run /ConnectionStrings:cs=<Your Connection String>"
18+
}],
19+
"actionId": "AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C"
20+
}]
21+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using dtmi_com_example_devicetemplate;
1+
// <auto-generated/>
2+
#nullable enable
3+
4+
using dtmi_com_example_devicetemplate;
25
using MQTTnet.Extensions.MultiCloud.AzureIoTClient;
36
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient;
47
using MQTTnet.Extensions.MultiCloud.Connections;

mqtt-device/Dockerfile

Lines changed: 0 additions & 20 deletions
This file was deleted.

mqtt-device/Properties/launchSettings.json.template

Lines changed: 0 additions & 47 deletions
This file was deleted.

mqtt-device/ca.pem

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)