MakoIoT.Device.Services.DataProviders 1.0.35.33495

There is a newer version of this package available.
See the version list below for details.
dotnet add package MakoIoT.Device.Services.DataProviders --version 1.0.35.33495
NuGet\Install-Package MakoIoT.Device.Services.DataProviders -Version 1.0.35.33495
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MakoIoT.Device.Services.DataProviders" Version="1.0.35.33495" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MakoIoT.Device.Services.DataProviders --version 1.0.35.33495
#r "nuget: MakoIoT.Device.Services.DataProviders, 1.0.35.33495"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MakoIoT.Device.Services.DataProviders as a Cake Addin
#addin nuget:?package=MakoIoT.Device.Services.DataProviders&version=1.0.35.33495

// Install MakoIoT.Device.Services.DataProviders as a Cake Tool
#tool nuget:?package=MakoIoT.Device.Services.DataProviders&version=1.0.35.33495

Mako-IoT.Device.Services.DataProviders

This component lets you send data (for example from sensors) through mesage bus either periodically or based on an event. See Messaging sample.

Usage

Data provider with periodically executed logic ("polling")

public class MyPollingDataProvider : IDataProvider
{
    private readonly IMySensor _sensor;
    public string Id { get; }
    public event MessageEventHandler DataReceived;
    
    public MyPollingDataProvider(IMySensor sensor)
    {
        Id = nameof(MyPollingDataProvider);
        _sensor = sensor;
    }

    public void GetData()
    {
        var data = _sensor.Read();
        DataReceived?.Invoke(this, new MessageEventArgs(new SensorMessage(data)));
    }
}

Event-based Data provider (e.g. for button press event)

public class MyButtonDataProvider : IDataProvider
{
    public string Id { get; }
    public event MessageEventHandler DataReceived;
    
    public MyButtonDataProvider(IButton button)
    {
        Id = nameof(MyButtonDataProvider);
        button.Press += (s, e) => DataReceived?.Invoke(this, new MessageEventArgs(new ButtonPressedMessage("My button")));
    }

    public void GetData() { }
}

Registration in DeviceBuilder

DeviceBuilder.Create()
    .AddMqtt()
    .AddMessageBus()
    .AddWiFi()
    .AddScheduler(o => { })
    .AddDataProviders(o =>
    {
        o.AddDataProvider(typeof(MyPollingDataProvider), nameof(MyPollingDataProvider));
        o.AddDataProvider(typeof(MyButtonDataProvider), nameof(MyButtonDataProvider));
    })
    .AddConfiguration(cfg =>
    {
        cfg.WriteDefault(DataProvidersConfig.SectionName, new DataProvidersConfig
        {
            Providers = new[] { new DataProviderConfig { DataProviderId = "HelloWorldDataProvider", PollInterval = 5000 }}
        });

        cfg.WriteDefault(WiFiConfig.SectionName, new WiFiConfig
        {
            Ssid = "",
            Password = ""
        });

        cfg.WriteDefault(MqttConfig.SectionName, new MqttConfig
        {
            BrokerAddress = "test.mosquitto.org",
            Port = 1883,
            UseTLS = false,
            ClientId = "device1",
            TopicPrefix = "mako-iot-test"
        });
    })
    .Build()
    .Start();

Note

Remember to abstract your hardware (sensors, buttons, etc.) with interfaces (ISensor, IButton, etc.). This allows to write unit tests for data providers.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.41.4378 37 6/4/2024
1.0.40.6398 96 3/22/2024
1.0.39.40982 155 1/6/2024
1.0.38.62361 114 12/30/2023
1.0.37.39506 138 12/2/2023
1.0.36.52266 102 12/1/2023
1.0.35.33495 112 11/17/2023
1.0.34.45334 96 11/16/2023
1.0.33.47573 92 11/11/2023
1.0.32.16941 89 11/10/2023
1.0.31.42696 96 11/9/2023
1.0.30.29999 86 11/7/2023
1.0.29.37213 118 10/6/2023
1.0.28.37750 116 10/6/2023
1.0.25.52930 174 5/25/2023
1.0.24.2714 156 5/24/2023
1.0.22.34917 146 5/23/2023
1.0.20.35485 138 5/22/2023
1.0.19.58422 142 5/22/2023