@@ -16,4 +16,82 @@ File bugs on [Masterloop Home](https://github.com/orgs/Masterloop/projects/1).
1616
1717## License
1818
19- Unless explicitly stated otherwise all files in this repository are licensed under the License in the root repository.
19+ Unless explicitly stated otherwise all files in this repository are licensed under the License in the root repository.
20+
21+ ## Using the Masterloop IoT Platform HTTP(S) REST interface
22+
23+ ### Creating a server connection object
24+ ```
25+ IMasterloopServerConnection mcs = new MasterloopServerConnection("hostname", "username", "password");
26+ ```
27+ where
28+ - "hostname" is the name of your Masterloop server
29+ - "username" is your user name
30+ - "password" is your password
31+
32+
33+ ### Get list of devices
34+ ```
35+ Device[] devices = mcs.GetDevices();
36+ ```
37+
38+ ### Get device history for a double observation
39+ ```
40+ DoubleObservation[] observations = mcs.GetObservations("mid", "obsId", DataType.Double, fromDate, toDate) as DoubleObservation[];
41+ ```
42+ where
43+ - "mid" is the device identifier (short for Masterloop Id)
44+ - "obsId" is the observation identifier (according to device template)
45+ - fromDate is the start date in the history query
46+ - toDate is the end date in the history query
47+
48+ The result will be all observations of id "obsId" between fromDate and toDate for device "mid", sorted chronologically.
49+
50+
51+ ## Using the Masterloop IoT Platform AMQP live messaging interface
52+
53+ ### Creating a live connection object
54+ ```
55+ IMasterloopLiveConnection mlc = new MasterloopLiveConnection("hostname", "username", "password", true);
56+ ```
57+ where
58+ - "hostname" is the name of your Masterloop server
59+ - "username" is your user name
60+ - "password" is your password
61+
62+ ### Registering observation callback
63+ As soon as a message is received, it is decoded and dispatched to any listening processes using callbacks.
64+ Registration of callbacks are required in order to be informed when a message arrives.
65+ ```
66+ mlc.RegisterObservationHandler("mid", obsId, handler);
67+ ```
68+
69+ A callback handler should have the signature of (example for Double observation type):
70+ ```
71+ private void OnReceivedObservationValue(string mid, int observationId, DoubleObservation o)
72+ {
73+ Console.WriteLine($"{mid} : {observationId} with value {o.Value} at {o.Timestamp}");
74+ }
75+ ```
76+
77+ ### Connecting
78+ In order to connect to the live data stream, the application needs to call Connect.
79+ This method also tries to re-connect if the connection is broken for some reason.
80+ ```
81+ LiveAppRequest lar = new LiveAppRequest()
82+ {
83+ MID = "mid",
84+ ObservationIds = new int[] { 100, 101, 102 },
85+ CommandIds = new int[] { 1, 2, 3 },
86+ InitObservationValues = true,
87+ ReceiveDevicePulse = true
88+ };
89+ bool success = mlc.Connect(new LiveAppRequest[] { lar });
90+ ```
91+
92+ ### Disconnecting
93+ When a connection should be closed, the following method should always be called:
94+ ```
95+ mlc.Disconnect();
96+ ```
97+
0 commit comments