Skip to content

Commit cec538e

Browse files
committed
Update for Raspbian Support
1 parent 2f34be3 commit cec538e

32 files changed

+306
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,4 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi3-Test-CSharp/Assets/Configs.json

CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi3-Test-CSharp/Assets/Configs.json renamed to CSharp/Raspberry-Pi-OS/ISBM-2.0-Pi-Test-CSharp/ISBM20Pi3TestCore31/Configs.json

File renamed without changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<AssemblyVersion>0.1.0.1</AssemblyVersion>
7+
<FileVersion>0.1.0.1</FileVersion>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Reference Include="ISBM20ClientAdapterCore31">
12+
<HintPath>Packages\ISBM20ClientAdapter\netcoreapp3.1\ISBM20ClientAdapterCore31.dll</HintPath>
13+
</Reference>
14+
<Reference Include="Newtonsoft.Json">
15+
<HintPath>Packages\Newtonsoft\Newtonsoft.Json.dll</HintPath>
16+
</Reference>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<None Update="Configs.json">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</None>
23+
<None Update="Packages\ISBM20ClientAdapter\netcoreapp3.1\ISBM20ClientAdapterCore31.dll">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
26+
<None Update="Packages\ISBM20ClientAdapter\netcoreapp3.1\Newtonsoft.Json.dll">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</None>
29+
<None Update="Packages\Newtonsoft\Newtonsoft.Json.dll">
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31+
</None>
32+
<None Update="SyncMeasurements.json">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
35+
</ItemGroup>
36+
37+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30309.148
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ISBM20Pi3TestCore31", "ISBM20Pi3TestCore31.csproj", "{C99A5967-7563-46B7-8B2A-00DE8CC6D7A6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C99A5967-7563-46B7-8B2A-00DE8CC6D7A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C99A5967-7563-46B7-8B2A-00DE8CC6D7A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C99A5967-7563-46B7-8B2A-00DE8CC6D7A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C99A5967-7563-46B7-8B2A-00DE8CC6D7A6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0F34AFA2-77C7-401D-93F7-CD2BA1BA6DEB}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* Purpose: This is a simple application that acts as an ISBM publication Provider.
2+
* It demonstrates an IoT device using an ISBM Client Adapter to post-publication
3+
* to an ISBM Server Adapter. It is interoperable with any ISBM compatible adapters
4+
* regardless of the actual service bus that delivers the messages.
5+
*
6+
* Remarks: 1. This is an .Net Core 3.1 project that targets Raspberry Pi OS for deployment.
7+
* 2. This demo does not close publication session for simpliclty. It behaves as power
8+
* loss when the program exits.
9+
*
10+
* Author: Pak Wong
11+
* Date Created: 2022/08/31
12+
*
13+
* (c) 2022
14+
* This code is licensed under MIT license
15+
*/
16+
17+
using System;
18+
using System.Threading;
19+
using ISBM20ClientAdapter;
20+
using ISBM20ClientAdapter.ResponseType;
21+
using Newtonsoft.Json;
22+
using Newtonsoft.Json.Linq;
23+
24+
namespace ISBM20Pi3TestCore21
25+
{
26+
class Program
27+
{
28+
static string _hostName = "";
29+
static string _channelId = "";
30+
static string _topic = "";
31+
static string _sessionId = "";
32+
33+
static Boolean _authentication;
34+
static string _username = "";
35+
static string _password = "";
36+
37+
static string _bodTemplate = "";
38+
39+
static ProviderPublicationService _myProviderPublicationService = new ProviderPublicationService();
40+
41+
static void Main(string[] args)
42+
{
43+
44+
SetConfigurations();
45+
GetBODTemplate();
46+
47+
//Open an Provider Publication Session
48+
OpenPublicationSessionResponse myOpenPublicationSessionResponse = _myProviderPublicationService.OpenPublicationSession(_hostName, _channelId);
49+
Console.WriteLine("Host Address " + _hostName);
50+
Console.WriteLine("Channel Id " + _channelId);
51+
52+
53+
if (myOpenPublicationSessionResponse.StatusCode == 201)
54+
{
55+
//SessionID is stored in a class level valuable for repeatedly used in every BPD post publication.
56+
_sessionId = myOpenPublicationSessionResponse.SessionID;
57+
Console.WriteLine("Publication Session " + _sessionId);
58+
Console.WriteLine("ISBM 2.0 IoT Device is ready!!");
59+
}
60+
else
61+
{
62+
Console.WriteLine(myOpenPublicationSessionResponse.StatusCode + " " + myOpenPublicationSessionResponse.ISBMHTTPResponse);
63+
Console.WriteLine("Please check configurations!!");
64+
}
65+
66+
Thread.Sleep(1000);
67+
68+
while (true)
69+
{
70+
PublishBOD();
71+
Thread.Sleep(5000);
72+
}
73+
74+
75+
}
76+
77+
private static void SetConfigurations()
78+
{
79+
//Read application configurations from Configs.json
80+
string filename = "Configs.json";
81+
82+
string JsonFromFile = System.IO.File.ReadAllText(filename);
83+
84+
JObject JObjectConfigs = JObject.Parse(JsonFromFile);
85+
_hostName = JObjectConfigs["hostName"].ToString();
86+
_channelId = JObjectConfigs["channelId"].ToString();
87+
_topic = JObjectConfigs["topic"].ToString();
88+
89+
_authentication = (Boolean)JObjectConfigs["authentication"];
90+
if (_authentication == true)
91+
{
92+
_username = JObjectConfigs["userName"].ToString();
93+
_password = JObjectConfigs["password"].ToString();
94+
}
95+
}
96+
97+
private static void GetBODTemplate()
98+
{
99+
string filename = "SyncMeasurements.json";
100+
101+
string JsonFromFile = System.IO.File.ReadAllText(filename);
102+
103+
_bodTemplate = JsonFromFile;
104+
}
105+
106+
private static void PublishBOD()
107+
{
108+
109+
//Create new BOD message from SyncMeasurements use case template
110+
string bodMessage = FillBODFields(_bodTemplate);
111+
112+
//Post Publication - BOD message
113+
PostPublicationResponse myPostPublicationResponse = _myProviderPublicationService.PostPublication(_hostName, _sessionId, _topic, bodMessage);
114+
115+
string MessageId = "";
116+
if (myPostPublicationResponse.StatusCode == 201)
117+
{
118+
MessageId = myPostPublicationResponse.MessageID;
119+
Console.WriteLine("Message " + MessageId + " has been pusblished!!");
120+
}
121+
else
122+
{
123+
Console.WriteLine(myPostPublicationResponse.StatusCode + " " + myPostPublicationResponse.ISBMHTTPResponse);
124+
}
125+
126+
}
127+
128+
private static string FillBODFields(string bodTemplate)
129+
{
130+
131+
//Create a sim value
132+
//-------------------------------------------------
133+
Random myRandom = new Random();
134+
double randomValue = (double)myRandom.Next(1, 100);
135+
136+
double simMeasurement = randomValue / 100 + 8;
137+
//-------------------------------------------------
138+
139+
JObject objBOD = JObject.Parse(_bodTemplate);
140+
141+
objBOD["syncMeasurements"]["applicationArea"]["bODID"] = System.Guid.NewGuid().ToString();
142+
objBOD["syncMeasurements"]["applicationArea"]["creationDateTime"] = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
143+
144+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurementLocation"]["UUID"] = "6EEBDB09-39EC-4E40-9FD9-3864FD49B0DB";
145+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurementLocation"]["shortName"] = "Headwater Elevation";
146+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurementLocation"]["infoSource"]["UUID"] = "9B005C91-A36F-4D69-A3ED-CC51E78E3A66";
147+
148+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["UUID"] = System.Guid.NewGuid().ToString();
149+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["recorded"]["dateTime"] = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
150+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["infoSource"]["UUID"] = "9B005C91-A36F-4D69-A3ED-CC51E78E3A66";
151+
152+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["data"]["measure"]["value"] = simMeasurement;
153+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["data"]["measure"]["unitOfMeasure"]["UUID"] = "73e8145d-7a92-49ef-9b10-6162a06f7876";
154+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["data"]["measure"]["unitOfMeasure"]["shortName"] = "Feet";
155+
objBOD["syncMeasurements"]["dataArea"]["measurements"][0]["measurement"][0]["data"]["measure"]["unitOfMeasure"]["infoSource"]["UUID"] = "cf3f3a8a-1e42-4f15-9288-9cf2241e163d";
156+
157+
return objBOD.ToString(Newtonsoft.Json.Formatting.None);
158+
}
159+
160+
161+
}
162+
}

CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi3-Test-CSharp/Assets/SyncMeasurements.json renamed to CSharp/Raspberry-Pi-OS/ISBM-2.0-Pi-Test-CSharp/ISBM20Pi3TestCore31/SyncMeasurements.json

File renamed without changes.

CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi3-Test-CSharp/App.xaml renamed to CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi-Test-CSharp/ISBM20PiTestUWP/App.xaml

File renamed without changes.

CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi3-Test-CSharp/App.xaml.cs renamed to CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi-Test-CSharp/ISBM20PiTestUWP/App.xaml.cs

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"hostName": "Your ISBM Server Adapter Host Address",
3+
"channelId": "Your Channel Id",
4+
"topic": "OIIE:S30:V1.1/CCOM-JSON:SyncMeasurements:V1.0",
5+
"authentication": 0,
6+
"userName": "",
7+
"password": ""
8+
}

CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi3-Test-CSharp/Assets/LockScreenLogo.scale-200.png renamed to CSharp/Windows-10-IoT_Core/ISBM-2.0-Pi-Test-CSharp/ISBM20PiTestUWP/Assets/LockScreenLogo.scale-200.png

File renamed without changes.

0 commit comments

Comments
 (0)