Git Product home page Git Product logo

luca-domenichini / smartiot.connector Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 1.0 936 KB

SmartIOT.Connector is a simple connector and scheduler that lets you connect your IoT devices to the cloud and more

License: MIT License

C# 99.19% Dockerfile 0.09% Batchfile 0.73%
automation connector iot mqtt scheduler snap7 azure s7net plc s71200 s71500 siemens siemens-s7-plcs s7300 modbus modbus-tcp

smartiot.connector's Introduction

.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:

smartiot.connector's People

Contributors

luca-domenichini avatar macel94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

nanofabricfx

smartiot.connector's Issues

Extensibiliy docs

Docs for how to easily create a customized device and connector is missing.
People now should simply copy from existing implementations.

GRPC connectors

Would be good to have grpc connectors, both client and server style.

Server connector should bring up a grpc service that allows clients to request data on demand.
It should also provide a streaming method to have events pushed to clients asynchronously.
This package (or another one?) should also provide a client library to be easily used by external processes

Client connector should do the same but the opposite way.
This package (or another one?) should also provide a grpc service to be installed in an external application that wants to act as the grpc service server. External clients, at this point, should query that grpc service for data/status/streaming etc...

Maybe client and server packages can be the same in both connector kind, be that SmartIOT -> grpc client -> grpc server or SmartIOT -> grpc server -> grpc client... maybe some endpoints would be useless.. must investigate that.

Monitoring web app

Would be good to have a web app integrated in the default app to display some data about the internals of the running system.

That app should use the API already exposed to display statistics, and should also provide a way to update the system state:

  • add/remove device
  • add/remove connector
  • get data, set data
  • etc...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.