Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
en:mervis-db:10-api [2017/07/13 14:48] m.chlupac |
en:mervis-db:10-api [2024/05/08 10:42] (current) |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| Mervis DB supports open [[https:// | Mervis DB supports open [[https:// | ||
| - | * {{ : | ||
| - | Contact [[:en:help:support|technical support]] for other non-public APIs that can be used for your projects. | + | * {{:en:mervis-db:mervisdb_wsdl-2017-07-12.xml|mervisdb_wsdl-2017-07-12.xml}} |
| + | Contact [[: | ||
| ===== List of supported functions ===== | ===== List of supported functions ===== | ||
| Line 25: | Line 25: | ||
| ^CheckCredentials| | | ^CheckCredentials| | | ||
| + | ===== Object Properties ===== | ||
| + | * (UTC)TimeStamp - UTC time stamp of the record | ||
| + | * GoodThrough - UTC time stamp of the end of validity of particular record | ||
| + | * Interval - period of time (in seconds) when next value should be recorded | ||
| + | ===== Examples ===== | ||
| + | ==== C# ==== | ||
| + | {{ : | ||
| + | === Download === | ||
| + | {{ : | ||
| + | {{ : | ||
| + | === Code === | ||
| - | ===== Examples ===== | + | <code csharp MervisDB_GetData_Example.cs> |
| + | using System; | ||
| + | using System.Linq; | ||
| + | using System.Threading.Tasks; | ||
| + | using MervisDb_GetData_Example.MervisDbService; | ||
| - | ==== C# ==== | + | namespace MervisDb_GetData_Example { |
| - | FIXME | + | class Program { |
| + | static void Main(string[] args) { | ||
| + | // | ||
| + | // Demo of asynchronous methods. | ||
| + | // | ||
| + | var task = Task.Run(async() | ||
| + | // | ||
| + | // Create access to the real server. | ||
| + | // Without SSL connections, | ||
| + | // The client is automatically generated from the WSDL file available here: https:// | ||
| + | // | ||
| + | using(HistoryDbAccessClient client | ||
| + | // Authentication credetials in the database. | ||
| + | | ||
| + | Name = " | ||
| + | }; | ||
| + | // Specification of the variables through Key-Value. | ||
| + | // Here we use 2 variables. | ||
| + | | ||
| + | new KeyValuePair[] { | ||
| + | new KeyValuePair { | ||
| + | Key = " | ||
| + | }, new KeyValuePair { | ||
| + | Key = " | ||
| + | } | ||
| + | }, | ||
| + | new KeyValuePair[] { | ||
| + | new KeyValuePair { | ||
| + | Key = " | ||
| + | }, new KeyValuePair { | ||
| + | Key = " | ||
| + | } | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | // From-To dates. The dates must be specified in the UTC time zone. | ||
| + | | ||
| + | | ||
| + | |||
| + | // Retrieving the data goes through cycling of values and variables. The server returns recommended values needed for the the next cycle. | ||
| + | int variableOffset = 0; // the offset of the variable | ||
| + | int variableCount = 10; // maximal number of variables returned in one request | ||
| + | int valueOffset; | ||
| + | int valueCount = 1000; // maximal values in on request | ||
| + | |||
| + | | ||
| + | |||
| + | do { | ||
| + | valueOffset = 0; | ||
| + | do { | ||
| + | // Execute the request. | ||
| + | var result = await client.GetDataAsyncAsync(credentials, | ||
| + | |||
| + | // Check the return code. " | ||
| + | if (!result.ReturnCode.StartsWith(" | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | // Cycle through the data and print it out. | ||
| + | | ||
| + | Console.WriteLine(" | ||
| + | | ||
| + | }))); | ||
| + | |||
| + | foreach(var value in valRecord.Vals) { | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | |||
| + | | ||
| + | | ||
| + | } | ||
| + | while (valueOffset != -1); | ||
| + | } | ||
| + | while (variableOffset != -1); | ||
| + | } | ||
| + | }); | ||
| + | |||
| + | | ||
| + | |||
| + | try { | ||
| + | task.Wait(); | ||
| + | } catch (Exception exc) { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | } | ||
| + | } | ||
| + | }</ | ||
| + | |||
| + | <code csharp MervisDB_SaveData_Example.cs> | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | using System.Threading.Tasks; | ||
| + | using MervisDb_SaveData_Example.MervisDbService; | ||
| + | |||
| + | namespace MervisDb_SaveData_Example | ||
| + | { | ||
| + | class Program | ||
| + | { | ||
| + | static void Main(string[] args) | ||
| + | { | ||
| + | // | ||
| + | // Demo of asynchronous methods. | ||
| + | // | ||
| + | var task = Task.Run(async () => | ||
| + | { | ||
| + | // | ||
| + | // Create access to the real server. | ||
| + | // Without SSL connections, | ||
| + | // The client is automatically generated from the WSDL file available here: https:// | ||
| + | // | ||
| + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(" | ||
| + | { | ||
| + | // Authentication credetials in the database. | ||
| + | Credentials credentials = new Credentials { Name = " | ||
| + | |||
| + | // Adding records... | ||
| + | List< | ||
| + | |||
| + | DateTime utcTimeStamp = new DateTime(2018, | ||
| + | |||
| + | // Each value is stored in a ValueRecord structure | ||
| + | ValueRecord rec = new ValueRecord(); | ||
| + | |||
| + | rec.UtcTimeStamp = utcTimeStamp; | ||
| + | rec.HistoryValueType = HistoryValueType.Double; | ||
| + | rec.DoubleValue = 23.4; // value itself | ||
| + | rec.Interval = 60.0; // sampling period in seconds. When the difference of timestamps of subsequent values if greater than 1.1 multiple of the interval, the data should be considered incomplete. | ||
| + | rec.Keys = new KeyValuePair[] // | ||
| + | { | ||
| + | new KeyValuePair { IsKey = true, Key = " | ||
| + | new KeyValuePair { IsKey = true, Key = " | ||
| + | new KeyValuePair { IsKey = false, Key = " | ||
| + | new KeyValuePair { IsKey = false, Key = " | ||
| + | new KeyValuePair { IsKey = false, Key = " | ||
| + | new KeyValuePair { IsKey = false, Key = " | ||
| + | new KeyValuePair { IsKey = false, Key = " | ||
| + | }; | ||
| + | |||
| + | records.Add(rec); | ||
| + | |||
| + | // Save data method returns the number of stored records | ||
| + | int recordsSaved = await client.SaveDataAsync(credentials, | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | }); | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | try | ||
| + | { | ||
| + | task.Wait(); | ||
| + | } | ||
| + | catch (Exception exc) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | Console.ReadLine(); | ||
| + | } | ||
| + | } | ||
| + | }</ | ||
| ==== Matlab ==== | ==== Matlab ==== | ||
| + | |||
| + | {{ : | ||
| + | |||
| === Supported functions === | === Supported functions === | ||
| + | |||
| ^Function^Description| | ^Function^Description| | ||
| ^SaveData|Save one or multiple records from one or multiple variables| | ^SaveData|Save one or multiple records from one or multiple variables| | ||
| Line 50: | Line 237: | ||
| ^GetRequiredTimestamp|Get time stamp depending on input options.| | ^GetRequiredTimestamp|Get time stamp depending on input options.| | ||
| + | === Toolbox === | ||
| - | You need to import specialized toolbox to communicate with Mervis DB from Matlab: | + | You need to import specialized toolbox to communicate with Mervis DB from Matlab: |
| - | There is a help available for all toolbox functions. | + | * {{: |
| + | * There is a help available for all toolbox functions. | ||
| - | To display the help use: | + | <code matlab> |
| - | <code matlab> | + | help MervisDatabase.supported_function_name |
| + | </ | ||
| - | <code matlab MervisDB_GetData_example.m> | + | === Code === |
| - | mervisDB = MerbonDatabase(' | + | |
| + | |||
| + | |||
| + | <code matlab MervisDB_GetData_example.m> | ||
| + | % Instance of Mervis DB | ||
| + | mervisDB = MervisDatabase(' | ||
| % Time interval definition | % Time interval definition | ||
| Line 72: | Line 267: | ||
| varKeys2 = {' | varKeys2 = {' | ||
| ' | ' | ||
| - | |||
| - | variable1 = MerbonDbVariable(varKeys1); | ||
| - | variable2 = MerbonDbVariable(varKeys2); | ||
| - | arrayOfVarKeys = [variable1; variable2]; % array of MerbonDbVariables | + | variable1 = MervisDbVariable(varKeys1); |
| - | + | variable2 = MervisDbVariable(varKeys2); | |
| + | |||
| + | arrayOfVarKeys = [variable1; variable2]; % array of MervisDbVariables | ||
| % help for function getData | % help for function getData | ||
| - | help MerbonDatabase.getData | + | help MervisDatabase.getData |
| % Download required data | % Download required data | ||
| Line 85: | Line 280: | ||
| % Get all variables with defined keys | % Get all variables with defined keys | ||
| - | allVaribales = db.getAllVars(varKeys1);</ | + | allVaribales = db.getAllVars(varKeys1); |
| + | </ | ||
| ==== PHP ==== | ==== PHP ==== | ||
| + | === Code === | ||
| - | + | ||
| - | <code php MervisDB_GetData_example.php><? | + | <code php MervisDB_GetData_example.php> |
| + | <?php | ||
| /* | /* | ||
| Mervis DB PHP example - getdata | Mervis DB PHP example - getdata | ||
| */ | */ | ||
| try { | try { | ||
| - | | + | |
| $soapClient = new SoapClient(' | $soapClient = new SoapClient(' | ||
| ' | ' | ||
| Line 104: | Line 301: | ||
| )); | )); | ||
| $soapClient-> | $soapClient-> | ||
| - | | + | |
| $credentials = array( | $credentials = array( | ||
| ' | ' | ||
| ' | ' | ||
| ); | ); | ||
| - | | + | |
| $utcTZ | $utcTZ | ||
| $utcFrom = new DateTime(' | $utcFrom = new DateTime(' | ||
| $utcTo | $utcTo | ||
| - | | + | |
| $valOffset = 0; | $valOffset = 0; | ||
| $valCount | $valCount | ||
| $varOffset = 0; | $varOffset = 0; | ||
| $varCount | $varCount | ||
| - | + | ||
| - | | + | |
| $variablesKey = array( | $variablesKey = array( | ||
| array( | array( | ||
| Line 146: | Line 342: | ||
| ) | ) | ||
| ); | ); | ||
| - | + | ||
| - | | + | |
| echo " | echo " | ||
| - | | + | |
| $counter = 0; | $counter = 0; | ||
| - | | + | |
| do { | do { | ||
| $response | $response | ||
| Line 168: | Line 363: | ||
| $valOffset = $response-> | $valOffset = $response-> | ||
| $varOffset = $response-> | $varOffset = $response-> | ||
| - | + | ||
| - | | + | |
| foreach ($response-> | foreach ($response-> | ||
| foreach ($varArray-> | foreach ($varArray-> | ||
| Line 178: | Line 372: | ||
| } | } | ||
| } | } | ||
| - | + | ||
| - | | + | |
| if (isset($varArray-> | if (isset($varArray-> | ||
| foreach ($varArray-> | foreach ($varArray-> | ||
| Line 187: | Line 380: | ||
| echo " | echo " | ||
| } | } | ||
| - | | + | |
| } | } | ||
| - | | + | |
| - | } while ($response-> | + | } while ($response-> |
| } while ($response-> | } while ($response-> | ||
| } | } | ||
| Line 196: | Line 389: | ||
| print_r($e); | print_r($e); | ||
| } | } | ||
| - | ?></ | + | ?> |
| + | </ | ||
| + | |||
| + | \\ | ||