Setting up solution - gpeipman/TemperatureStation GitHub Wiki

Table of Contents

Requirements

  1. Computer with Visual Studio
  2. MSSQL database
  3. .NET Core and ASP.NET Core
  4. Windows 10 IoT Background Application template
  5. IIS with ASP.NET Core support configured or Linux with .NET Core installed

Deploying and configuring web application

  1. Clone or download TemperatureStation source code
  2. Take database creation script from ExternalFiles folder and set up database
  3. Open application settings file and change database connection string

Deploying from command line

  1. Open web application folder in command prompt
  2. Type: dotnet restore
  3. Type: dotnet build
  4. Go back to command prompt and type: dotnet publish
  5. Take files and move them to your web server

Deploying from Visual Studio

  1. Open solution in Visual Studio
  2. Right click on web application project and select Publish...
  3. Give name to publishing profile
  4. Select publishing type (Azure, WebDeploy, File system)
  5. Configure publishing
  6. Save profile
  7. Click Publish

Deploying and configuring Windows 10 IoT Service

  1. Clone or download TemperatureStation source code
  2. Open it in Visual Studio
  3. Right-click on service project and select Properties

Configuring logging

NB! Logging is currently configurable on code level and it will stay like this until I find decent solution for configuration files and their editing in IoT application. Loggers are located in Loggers folder of IoT application.

Currently logger is instantiated in the beginning of Run() method of IoT service Startup task (StartupTask,cs in IoT application root). No dependency injection is currently used.

public async void Run(IBackgroundTaskInstance taskInstance)
{
    _deferral = taskInstance.GetDeferral();
    taskInstance.Canceled += TaskInstance_Canceled;

    _logger = new SyslogLogger();
    _logger.Info("Starting weather station service");
    // ...
}

Configuring RaspberryPi for ETW logs

Getting ETW logs work is a little bit tricky and hacky business.

  1. Add reference to NuGet package Microsoft.Diagnostics.Tracing.EventSource
  2. Build application, get error and take the failed command with copy and paste to some text editor
  3. Remove the reference to Microsoft.Diagnostics.Tracing.EventSource
  4. In text editor change file extension from winmdobj to winmd and run the command on command prompt
  5. TBC

ETW logs

ETW logger is defined in TemperatureStationEventSource class that is located in Loggers folder of IoT application. The class doesn't need any additional configuring on code level.

ApplicationInsights logs

ApplicationInsights logger is defined in ApplicationInsightsLogger class (Loggers folder of IoT application). Before using it InstrumentationKey must be set in this class. There is string constant called InstrumentationKey for this.

internal class ApplicationInsightsLogger : ILogger
{
    private const string InstrumentationKey = "key";
    // ....
}

Syslog logs

Syslog logger logs data to Syslog server located somewhere in (usually local) network. Logger is defined in SyslogLogger class (Loggers folder of IoT application). Before using this class two constants must be set:

  • SyslogHost - host name or IP of Syslog server
  • SyslogPort - logging port of Syslog server (usually 514)
internal class SyslogLogger : ILogger
{
    private const string SyslogClientName = "TemperatureStation";
    private const string SyslogHost = "192.168.1.2";
    private const int SyslogPort = 514;
    // ...
}

Fallback logger

FallbackLogger is pseudo-logger that actually doesn't do any logging. It takes in two logger instances. If logging to first logger fails then second one is used. Main scenario for fallback logger is backing up logging when external log server goes down or there are problems with network.

var networkLogger = new SyslogLogger();
var localLogger = new TemperatureStationEventSource();

_logger = new FallbackLogger(networkLogger, localLogger);
⚠️ **GitHub.com Fallback** ⚠️