{"id":27013983,"url":"https://github.com/masterloop/masterloop.plugin.application","last_synced_at":"2025-04-04T13:19:27.726Z","repository":{"id":33485315,"uuid":"158788757","full_name":"Masterloop/Masterloop.Plugin.Application","owner":"Masterloop","description":"Masterloop Application Plugin","archived":false,"fork":false,"pushed_at":"2024-03-27T10:38:41.000Z","size":139,"stargazers_count":7,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T13:19:22.855Z","etag":null,"topics":["application","http","internet","iot","masterloop","mqtt","of","plugin","rest","things"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Masterloop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-23T06:16:03.000Z","updated_at":"2023-07-17T05:46:40.000Z","dependencies_parsed_at":"2024-06-21T17:51:15.303Z","dependency_job_id":"9ebec1dc-9d51-4130-9b9a-ab43dd752081","html_url":"https://github.com/Masterloop/Masterloop.Plugin.Application","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterloop%2FMasterloop.Plugin.Application","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterloop%2FMasterloop.Plugin.Application/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterloop%2FMasterloop.Plugin.Application/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masterloop%2FMasterloop.Plugin.Application/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Masterloop","download_url":"https://codeload.github.com/Masterloop/Masterloop.Plugin.Application/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182427,"owners_count":20897381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application","http","internet","iot","masterloop","mqtt","of","plugin","rest","things"],"created_at":"2025-04-04T13:19:26.949Z","updated_at":"2025-04-04T13:19:27.713Z","avatar_url":"https://github.com/Masterloop.png","language":"C#","readme":"﻿# Masterloop Application Plugin\n\nThis repo contains source code to the Masterloop Application Plugin library.\n\n## How to build\n\n### Prerequisites\n- Visual Studio\n- Windows, Mac or Linux\n- Git\n- .NET Framework, Mono, .NET Core\n\n## Feedback\n\nFile bugs on [Masterloop Home](https://github.com/orgs/Masterloop/projects/1).\n\n## License\n\nUnless explicitly stated otherwise all files in this repository are licensed under the License in the root repository.\n\n## Using the Masterloop IoT Platform HTTP(S) REST interface\n\n### Creating a server connection object\n```\nIMasterloopServerConnection mcs = new MasterloopServerConnection(\"hostname\", \"username\", \"password\");\n```\nwhere\n- \"hostname\" is the name of your Masterloop server\n- \"username\" is your user name\n- \"password\" is your password\n\n\n### Get list of devices\n```\nDevice[] devices = mcs.GetDevices();\n```\n\n### Get device history for a double observation\n```\nDoubleObservation[] observations = mcs.GetObservations(\"mid\", \"obsId\", DataType.Double, fromDate, toDate) as DoubleObservation[];\n```\nwhere\n- \"mid\" is the device identifier (short for Masterloop Id)\n- \"obsId\" is the observation identifier (according to device template)\n- fromDate is the start date in the history query\n- toDate is the end date in the history query\n\nThe result will be all observations of id \"obsId\" between fromDate and toDate for device \"mid\", sorted chronologically.\n\n\n## Using the Masterloop IoT Platform AMQP live messaging interface\n\n### Creating a live connection object\n```\nIMasterloopLiveConnection mlc = new MasterloopLiveConnection(\"hostname\", \"username\", \"password\", true);\n```\nwhere\n- \"hostname\" is the name of your Masterloop server\n- \"username\" is your user name\n- \"password\" is your password\n\n### Registering observation callback\nAs soon as a message is received, it is decoded and dispatched to any listening processes using callbacks.\nRegistration of callbacks are required in order to be informed when a message arrives.\n```\nmlc.RegisterObservationHandler(\"mid\", obsId, handler);\n```\n\nSet \"mid\" to null in order to subscribe to all devices.\n\nA callback handler should have the signature of (example for Double observation type):\n```\nprivate void OnReceivedObservationValue(string mid, int observationId, DoubleObservation o)\n{\n  Console.WriteLine($\"{mid} : {observationId} with value {o.Value} at {o.Timestamp}\");\n}\n```\n\n### Connecting using temporary channel\nIn order to connect applications running for a relatively short lifespan to the live data stream, the app needs to call Connect.\nThis method also tries to re-connect if the connection is broken for some reason.\n```\nLiveAppRequest lar = new LiveAppRequest()\n{\n  MID = \"mid\",\n  ObservationIds = new int[] { 100, 101, 102 },\n  CommandIds = new int[] { 1, 2, 3 },\n  InitObservationValues = true,\n  ReceiveDevicePulse = true\n};\nbool success = mlc.Connect(new LiveAppRequest[] { lar });\n```\n\n### Disconnecting\nWhen a connection should be closed, the following method should always be called:\n```\nmlc.Disconnect();\n```\n\n### Connecting using persistent subscription\nIn order to connect for example applications with a long lifespan to the live data stream, the application needs to call Connect.\nThis method also tries to re-connect if the connection is broken for some reason.\nAny messages received while the listening application is disconnected will be stored on the server up to 14 days. This means that messages will not be lost during restarts and similar.\n\n#### Creating persistent subscription\nFirst, create the persistent subscription using the MasterloopServerConnection method \"CreateLivePersistentSubscription\".\nThe argument object of class LivePersistentSubscriptionRequest requires the following information to be specified:\nTID: Template identifier\nMIDs: If using a subset of template devices, specify an array of zero or more items, otherwise give this field value null. Devices can also be added/removed later.\nSubscriptionKey: A self-designed key of size between 8 and 16 characters that must be unique relative to user account being used.\n\n#### Connecting to a persistent subscription\nIf the call to CreateLivePersistentSubscription above was successful, login information can be obtained using MasterloopServerConnection method GetLivePersistentSubscriptionConnection.\n\nThen create a new MasterloopLiveConnection object, using the LiveConnectionDetails object obtained from the call above as the argument to the MasterloopLiveConnection constructor. \n\n#### Adding/removing devices to a persistent subscription\nDuring runtime, devices can be added and removed to/from a persistent subscription using the MasterloopServerConnection method AddLivePersistentSubscriptionDevice and RemoveLivePersistentSubscriptionDevice.\nIt is allowed to add devices multiple time (no duplicates will be created).\n\n#### Deleting a persistent subscription\nA no longer needed persistent subscription should be deleted using the MasterloopServerConnection method DeleteLivePersistentSubscription. \nThis will conserve server resources as well as keeping things clean on the server.\n\n#### Reconfiguring persistent subscriptions\nDevices can be added/removed using the MasterloopServerConnection AddLivePersistentSubscriptionDevice/RemoveLivePersistentSubscriptionDevice methods.\nIf observations/commands/pulses or other elements need to be reconfigured, the existing subscription should be deleted and recreated as described above.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterloop%2Fmasterloop.plugin.application","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasterloop%2Fmasterloop.plugin.application","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterloop%2Fmasterloop.plugin.application/lists"}