A WPF app with an integrated HTTP server that enables the web browser to access local hardware devices that would otherwise not be accessible via JavaScript.
The client part of a Web application often needs to access local devices. One example is access to NFC hardware. Specifications like Web NFC for direct support by the browser are not yet generally available, so I came up with the idea of a local program that allows access to local resources via an HTTP interface.
NFC tags are very well suited for identifying things. They are cheap and robust.
A thing is a physical asset modeled by a digital twin. In the DeviceServer a thing is identified by a type and a unique ID. A GUID is used as ID, see class definition Thing.cs. After the production of a thing in a factory, the type and ID are written to an NFC tag by a Web application and the tag is attached to the product. The tag can be read again afterwards, using again the DeviceServer's functionality. The ID of a thing serves as a pointer to a complex data set, which is stored e.g. in the digital twin in the cloud or in a storage built on distributed ledger technology.
The thing ID is not related to the serial number of a physical asset. Unlike the ID, serial numbers are not necessarily unique; different manufacturers of products may use the same serial numbers. They are therefore stored as a normal attribute in the digital twin.
Following are a few simple examples that show how to use the HTTP server from within the PowerShell.
PS C:\> $response = Invoke-WebRequest -Uri http://SANTACLARA.muc.smarttrust.de:9090/readthing -UseBasicParsing PS C:\> $response.StatusCode 200 PS C:\> $response.Content | ConvertFrom-Json | ConvertTo-Json { "Type": 9000, "TypeAsString": "Digger", "Id": "fbc0ceff-ed5b-4e7e-8160-2862dfe5bf57", "CreatedWhen": "0001-01-01T00:00:00" }
PS C:\> $thing = @{ Type = "80"; Id = [System.Guid]::NewGuid().toString() } PS C:\> $json = $thing | ConvertTo-Json PS C:\> $json { "Id": "7b3b9920-225f-4f4e-b1e3-62b08413fdd7", "Type": "80" } PS C:\> $response = Invoke-WebRequest -Uri http://SANTACLARA.muc.smarttrust.de:9090/writething -Method POST -Body $json PS C:\> $response.StatusCode 204
See definition of ThingType
in Thing.cs for known thing types.
DeviceServer is written in C# Version 8.0. It uses the following technologies and software modules:
- .NET Core 3.1
- HttpListener
- Windows Presentation Foundation with Data binding
- Task Parallel Library
- Microsoft.Windows.SDK.Contracts
- Serilog
- Json.NET
You do not have to obtain any packages manually, the project file DeviceServer.csproj does this automatically.
When a UWP app provides a network service, only its own code or an app on another machine can access the service. Since the app and the web browser should run on the same machine, UWP is not an alternative.
The Software is WIP, development started on June 11, 2020.
What already runs (Thursday, 20/07/16 - 13:10 CEST):
- Identification of Smartcard readers
- Identification of NFC tags
- Writing Thing data to / Reading Thing data from MIFARE Ultralight NFC tag
- Services of the HTTP Server:
GET /settings
,GET /reader
,GET /nfctag
,GET /readthing
andPOST /writething
- Simple file based emulation mode
- Setting CORS response headers
Because development takes place in my free time (and I love my family), progress is slow.
- Microsoft Windows 10 - the App has been tested with OS Build 17763.1217, any newer version of the operating system should do the job.
- Microsoft Visual Studio Community 2019
Clone the repository, open DeviceServer.sln in VS16 and build the solution.
Click on Start Browser and your standard browser navigates to index.html.
If a file Thing.json
exist in the app's root directory, thing data will be read from / written to it. This simple emulation mode facilitates integration tests without NFC hardware, it can be activated on the app's UI.
The following is a file Thing.json
resulting from a POST /writething
in emulation mode:
PS Microsoft.PowerShell.Core\FileSystem::\\sandboxes.muc.smarttrust.de\Sandboxes\markus\Git-Repositories\DeviceServer\DeviceServer\bin\Debug\netcoreapp3.1> dir Verzeichnis: \\sandboxes.muc.smarttrust.de\Sandboxes\markus\Git-Repositories\DeviceServer\DeviceServer\bin\Debug\netcoreapp3.1 Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 20.06.2020 11:27 logs d----- 12.06.2020 16:21 media -a---- 15.06.2020 12:26 4463 DeviceServer.deps.json -a---- 20.06.2020 11:27 116736 DeviceServer.dll -a---- 20.06.2020 11:27 174592 DeviceServer.exe -a---- 20.06.2020 11:27 35480 DeviceServer.pdb -a---- 15.06.2020 12:26 236 DeviceServer.runtimeconfig.dev.json -a---- 15.06.2020 12:26 161 DeviceServer.runtimeconfig.json -a---- 09.11.2019 00:56 693680 Newtonsoft.Json.dll -a---- 26.05.2020 00:17 127488 Serilog.dll -a---- 15.05.2020 21:31 29696 Serilog.Sinks.File.dll -a---- 20.06.2020 12:13 143 Thing.json -a---- 20.06.2020 12:11 2 Thing.json.backup PS Microsoft.PowerShell.Core\FileSystem::\\sandboxes.muc.smarttrust.de\Sandboxes\markus\Git-Repositories\DeviceServer\DeviceServer\bin\Debug\netcoreapp3.1> Get-Content -Path .\Thing.json { "Type": 3, "TypeAsString": "ExhaustSystem", "Id": "00e5acbe-50d3-4563-ac93-94c6af6da61b", "CreatedWhen": "0001-01-01T00:00:00" }
To run the DeviceServer on a computer with Windows 10, a number of six files are required, which are located in the folder bin/Debug/netcoreapp3.1. Additionally version 3.1 of the .NET Core Desktop Runtime is required. The installation requires administration rights.
You also need a PC/SC device driver for the NFC reader to be used.
The app was tested with the following hardware:
- ACR122U
- ACR1255U-J1 Bluetooth®
- HID® OMNIKEY® 5427 CK
- Tags with MIFARE Ultralight chip
- MIDAS NFC Wet Inlay with NTAG® 213 chip