Skip to content

Web dashboard for displaying temperature and humidity data from the MXChip AZ3166 IoT Devkit

License

Notifications You must be signed in to change notification settings

SeanoNET/RoomTempDashboard

Repository files navigation

RoomTempDashboard

Build Docker CLI

Web dashboard for displaying temperature and humidity data from RoomTempDevice-IoT or local stack RoomTempMQTTConsumer

Getting Started

Install .NET Core version 3.1 or above

  • git clone https://github.com/SeanoNET/RoomTempDashboard.git
  • cd RoomTempDashboard/src
  • dotnet restore && dotnet run

Local Stack

See RoomTempMQTTConsumer for running the MQTT consumer - this replaces all the cloud services with local alternatives. The local version uses postgres as the db engine due to mssql not supported being supported on arm processors yet. Using postgres will allow you to run this stack on a Raspberry Pi or other arm32 devices.

Config

Configure the Postgres DataSource connection string in appsettings.json

Setup and start the RoomTempMQTTConsumer first, it will generate the database and tables for you.

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Hangfire": "Information"
    }
  },
  "AllowedHosts": "*",
  "DataSource": "Host=localhost;Database=MQTT;Username=postgres;Password=St0ngPassword1!"
}

Running locally in Docker

Install Docker

Build the image:

docker build -t roomtempdashboard:dev .

Run the image:

docker container run -p 5000:5000 -e DataSource="Host=localhost;Database=MQTT;Username=postgres;Password=St0ngPassword1!" -e "ASPNETCORE_URLS: http://0.0.0.0:5000" --name roomtempdash roomtempdashboard:dev

Install Docker Compose and start the other services with the docker-compose.yml.

version: '3'

services:

  consumer:
    image: seanonet/roomtempmqttconsumer:latest
    environment:
      DataSource: Host=dbdata;Database=MQTT;Username=postgres;Password=St0ngPassword1!;
      ClientId: metric-consumer
      MqttServerIp: mqtt
      MqttServerPort: 1883
      MqttSubscribeTopic: home/room/temp-mon/data
    depends_on:
        - mqtt
        - dbdata
  mqtt:
    image: eclipse-mosquitto:1.6
    ports:
        - 1883:1883
        - 9001:9001
    volumes:
        - mosquitto:/mosquitto/data
        - mosquitto:/mosquitto/log eclipse-mosquitto
  dbdata:
    image: postgres:12
    ports:
    - 5432:5432
    environment:
        POSTGRES_PASSWORD: St0ngPassword1!
    volumes:
        - dbsql:/var/lib/postgresql/data
  dashboard:
    build: .
    image: roomtempdashboard:dev
    ports:
        - 5000:5000
    environment:
        DataSource: Server=dbdata;Database=MQTT;User Id=sa;Password=St0ngPassword1!;
        ASPNETCORE_URLS: http://0.0.0.0:5000

volumes:
    mosquitto:
    dbsql:

run docker-compose up --build.

Running Stack in Production on Swarm

For running in production see RoomTempStack

Cloud Stack

Setup MSSQL Entity Framework Provider

Install the Microsoft.EntityFrameworkCore.SqlServer NuGet package.

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 3.1.1

Replace options.UseNpgsql() with options.UseSqlServer() in ConfigureServices.

Startup.cs

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.Configure<CookiePolicyOptions>(options =>
    {
        // This lambda determines whether user consent for non-essential cookies is needed for a given request.
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;
    });


    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
    services.AddSignalR();
    services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetSection("DataSource").Value));
}

Config

Configure the MSSQL DataSource connection string in appsettings.json.

You will need to manually create the table and database see Creating the SQL Database

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Hangfire": "Information"
    }
  },
  "AllowedHosts": "*",
  "DataSource": "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"
}

Configuring the MXChip and IoT Hub

For configuring the MXChip/IoT Hub and for uploading device code refer to RoomTempDevice-IoT Getting Started

Stream Analytics

The Stream Analytics job will process the events from the payload sent to IoT Hub and output the data into the MSSQL data source so the RoomTempDashboard can retrieve the data.

Creating the Stream Analytics job

SELECT 
    CAST(TEMPERATURE AS float) AS Temperature,
    CAST(HUMIDITY AS float) AS Humidity,
    CAST(EVENTPROCESSEDUTCTIME AS datetime) as MeasuredAt
INTO
    optSensorData
FROM
    iptSensorData

Creating the SQL Database

Create a table called SensorData - The output from the Stream Analytics Job

CREATE TABLE [dbo].[SensorData](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Temperature] [decimal](18, 13) NULL,
	[Humidity] [decimal](18, 13) NULL,
	[MeasuredAt] [datetime] NULL,
 CONSTRAINT [PK_SensorData] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

Icons

Microsoft Azure, Cloud and Enterprise Symbol / Icon Set

About

Web dashboard for displaying temperature and humidity data from the MXChip AZ3166 IoT Devkit

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published