Skip to content

Latest commit

 

History

History
143 lines (115 loc) · 6.71 KB

README.md

File metadata and controls

143 lines (115 loc) · 6.71 KB

.NET NuGet version (SmartIOT.Connector) SmartIOT.Connector NuGet Package Downloads HitCount

SmartIOT.Connector - Cloud Connector for IOT devices and industrial PLCs

This project aims at creating a simple connector and scheduler for automation devices, like industrial PLCs, publishing data to the cloud and more.

SmartIOT.Connector image

SmartIOT.Connector enables you to connect to a variety of IOT sensors and industrial PLCs and distribute their data to an external system in form of an event describing the changed data.
The external system can then process the data being read and can send back to SmartIOT.Connector data to be written to the devices.
SmartIOT.Connector is a good fit for industrial and automation needs, where developers are being asked to abstract away from device communication protocols and must concentrate solely on the business logic to implement.

Quick start

The following quick start creates an SmartIOT.Connector instance that connects to a device (namely a Siemens PLC) and reads 100 bytes from Tag 20.
Whenever a change is detected in the tag, a message is published to the Mqtt Server specified in the connection string below.
It also listens for incoming messages in topic tagWrite and tries to write data to tag 22.
For message formats, read the docs here for project SmartIOT.Connector.Messages. JSON serializer is used by default, but Protobuf can also be used, or even your own serializer.

  1. Create a configuration json file (see this file for configuration reference):
{
    "ConnectorConnectionStrings": [
        "mqttClient://Server=<IpAddress or hostname>;ClientId=MyClient;Port=1883"
    ],
    "DeviceConfigurations": [
        {
            "ConnectionString": "snap7://Ip=<IpAddress>;Rack=0;Slot=0;Type=PG",
            "DeviceId": "1",
            "Enabled": true,
            "Name": "Test Device",
            "IsPartialReadsEnabled": false,
            "IsWriteOptimizationEnabled": true,
            "Tags": [
                {
                    "TagId": "DB20",
                    "TagType": "READ",
                    "ByteOffset": 0,
                    "Size": 100,
                    "Weight": 1
                },
                {
                    "TagId": "DB22",
                    "TagType": "WRITE",
                    "ByteOffset": 0,
                    "Size": 100,
                    "Weight": 1
                }
            ]
        }
    ],
    "SchedulerConfiguration": {
        "MaxErrorsBeforeReconnection": 10,
        "RestartDeviceInErrorTimeoutMillis": 30000,
        "WaitTimeAfterErrorMillis": 1000,
        "WaitTimeBetweenEveryScheduleMillis": 0,
        "WaitTimeBetweenReadSchedulesMillis": 0,
        "TerminateAfterNoWriteRequestsDelayMillis": 3000,
        "TerminateMinimumDelayMillis": 0
    }
}
  1. Use SmartIotConnectorBuilder to create the connector and run it:
// Build SmartIOT.Connector and bind it to your DI container or wherever you can do this:
var smartiot = new SmartIOT.Connector.Core.SmartIotConnectorBuilder()
    .WithAutoDiscoverDeviceDriverFactories()
    .WithAutoDiscoverConnectorFactories()
    .WithConfigurationJsonFilePath("smartiot-config.json")
    .Build();

// Start SmartIOT.Connector whenever you need it to run
smartiot.Start();

// Stop SmartIOT.Connector before shutting down everything
smartiot.Stop();

otherwise, you can add SmartIOT.Connector to DI container with these extension methods:

// this method will start an IHostedService running SmartIOT.Connector
builder.Services.AddSmartIOTConnector(cfg =>
{
    // configure here.
    cfg.WithAutoDiscoverDeviceDriverFactories()
        .WithAutoDiscoverConnectorFactories()
        .WithConfigurationJsonFilePath("smartiot-config.json");
});

var app = builder.Build();

// you can configure further..
app.UseSmartIOTConnector(smartIotConnector =>
{
    smartIotConnector.AddPrometheus(conf); // for example, adding Prometheus here..
});

Documentation

SmartIOT.Connector.App and Docker integration

If you want to run SmartIOT.Connector as a standalone application or as a Docker container, see project SmartIOT.Connector.App for further details.

Here is a quick link to the Docker image repository: https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-app

Run as a Windows Service

The application SmartIOT.Connector.App supports being run as a WinService. All you need to do is install it and run. Follow this guide for further informations

Nuget packages

You can find SmartIOT.Connector packages on nuget.org site and on Visual Studio Package Manager: https://www.nuget.org/packages?q=SmartIOT.Connector

Credits

These libraries provide connectivity with underlying devices: