Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Paste code macro
languagejson
themeSunburst
Status 200

// return format = 0
{
    "success": true,
    "reason": "success",
    "data": {
        "columns": [
            {"name": "NAME", "type": 5, "length": 80},
            {"name": "TIME", "type": 5, "length": 4096},
            {"name": "MyVal", "type": 20, "length": 17}
        ],
        "samplesrows": [
            ["tag_01","2021-07-06 12:12:27", 1629],
            ["tag_02","2021-07-06 12:12:25", 1625]
        ]
    }
}
 

...

Expand
titlewindow(batch)

github

Code Block
chcp 65001 
:: Text Encoding to UTF-8 in CMD
:: Example For Select Current Data for tag API by using curl in window script
:: written by yeony kim

set API_KEY=YOUR_API_TOKEN_KEY
set LAKE_ID=YOUR_LAKE_ID
set CLOUD_VENDOR=YOUR_CLOUD_VENDOR
set CLOUD_REGION=YOUR_CLOUD_REGION

set CONTENT_HEADER="Content-Type: application/json"
set API_HEADER="x-api-key: %API_KEY%"
set LAKE_ID=YOUR_LAKE_ID
set URL="https://%LAKE_ID%%CLOUD_VENDOR%.%CLOUD_REGION%.machlake.com/v1/lakes/%LAKE_ID%/values/current"

set SELECT_TYPE=current

:: ------------------------------------------------------------------------------------------------- ::

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% \
    --data-urlencode "type=%SELECT_TYPE%" \
    --data-urlencode "tag_name=%TAG_NAME%" \
    --data-urlencode "date_format=%DATE_FORMAT%"

:: Return Format
:: {"data":{"calc_mode":"raw","columns":[
::     "success": true,
::     "reason": "success",
::     "data":{
::         "columns":[
::             {"name":"TIMENAME","type":5,"length":409680},
::             {"name":"VALUETIME","type":205,"length":174096}],"samples":[{"tag_
::             {"name":"sensor2VALUE","datatype":[{20,"TIMElength":"2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":17}
::         ],
::         "rows":[
::             ["sensor2","2021-01-0607 2002:00:0600 000009:000:000","VALUE":2}]}]},"status":"success"}
::   :: ------------------------------------------------------------------------------------------------- ::

:: CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set TAG_NAME=sensor1,sensor2
set DATE_FORMAT=YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
set VALUE_RETURN_FORM=1

curl -k -G %URL% -H %CONTENT_HEADER% -H %API_HEADER% --data-urlencode "tag_name=%TAG_NAME%" --data-urlencode "date_format=%DATE_FORMAT%" --data-urlencode "value_return_form=%VALUE_RETURN_FORM%"

:: Return Format
:: {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":{"TIME":["2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000:000:000"],"VALUE":[2]}}]},"status":"success"}

:: ---          ["sensor1","2021-01-06 20:00:06 000:000:000",2]
::         ]
::     }
:: }
Expand
titlelinux(shell)

github

Code Block
languagebash
# Text Encoding to UTF-8 in CMD
# Example For Select Current Data for tag API by using curl in ubuntu

LAKE_ID=$YOUR_LAKE_ID
API_KEY=$YOUR_API_KEY
CLOUD_VENDOR=$YOUR_CLOUD_VENDOR
CLOUD_REGION=$YOUR_CLOUD_REGION
TAG_NAME=$YOUR_TAG_NAME

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
URL=https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/${LAKE_ID}/values

SELECT_TYPE=current

# ------------------------------------------------------------------------------------------------------ ::
Expand
titlelinux(shell)

github

Code Block
#
Text
Encoding# toCASE UTF-8 inCurrent CMDDATA #GET Examplewith Fordate Select Current Data for tag API by using curl in ubuntu
# written by yeony kim

API_KEY=YOUR_API_TOKEN

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY
LAKE_ID=YOUR_LAKE_ID
URL=https://$LAKE_ID.machlake.com/lakes/values/current

# ------------------------------------------------------------------------------------------------- #

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {"data":{"calc_mode":"raw","columns":[format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER \
    --data-urlencode "type=$SELECT_TYPE" \
    --data-urlencode "tag_name=$TAG_NAME" \
    --data-urlencode "date_format=$DATE_FORMAT"

# Return Format
# {
#     "success": true,
#     "reason": "success",
#     "data":{
#         "columns":[
#             {"name":"NAME","type":5,"length":80},
#             {"name":"TIME","type":5,"length":4096},{"name"
#             {"name":"VALUE","type":20,"length":17}
#         ],"samples":[{"tag_name":"sensor2","data":[{"TIME":"2021-01-
#         "rows":[
#             ["sensor2","2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":",
#             ["sensor1","data":[{"TIME":"2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}

# ------------------------------------------------------------------------------------------------- #

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn
TAG_NAME=sensor1,sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
VALUE_RETURN_FORM=1

curl -k -G $URL -H $CONTENT_HEADER -H $API_HEADER --data-urlencode "tag_name=$TAG_NAME" --data-urlencode "date_format=$DATE_FORMAT" --data-urlencode "value_return_form=$VALUE_RETURN_FORM"

# Return Format
# {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":{"TIME":["2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000:000:000"],"VALUE":[2]}}]},"status":"success"}

# 
#         ]
#     }
# }
Expand
titlejavascript

github

Code Block
languagejs
// Example For Select Current Data for tag API by using request in node js
// written by yeony kim
// sensor1, sensor2 is applied in lake

// process.env.NODE_TLS_REJECT_UNAUTHORIZED ="0";

const API_KEY ="YOUR_API_TOKEN";
const LAKE_ID ="YOUR_LAKE_ID";
const CLOUD_VENDOR="CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
const URL = `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/v1/lakes/${LAKE_ID}/values`;

var request = require('request');

const TAG_NAME = "sensor1,sensor2";
const SELECT_TYPE="current";


/* ------------------------------------------------------------------------------------------------------- #
Expand
titlejavascript

github

Code Block
languagejs
 */

// ExampleCASE For Select Current Data for tag API by using request in node js
// written by yeony kim
// sensor1, sensor2 is applied in lake

process.env.NODE_TLS_REJECT_UNAUTHORIZED ="0";

const express = require('express');
const app = express();
const API_KEY ="YOUR_API_TOKEN";
const LAKE_ID ="YOUR_LAKE_ID"
const URL ="https://" + LAKE_ID +".machlake.com/lakes/values/current";

// CASE - Current DATA GET with date format - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

request.get({
    url: URL, 
    qs: {
        type: SELECT_TYPE,
        tag_name: TAG_NAME,
        date_format: "YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
    },
app.get(     '/select_current_date_with_nano_time_date_string', function(req, res) {
   headers: {
        "x-api-key": API_KEY
    var}}, 
request = require('request');  function(error, response, body) {
    const QueryParams = new URLSearchParamsconsole.log(body);
        // Return Format
      QueryParams.set('tag_name', 'sensor1,sensor2')
  // {
      QueryParams.set('date_format', 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn') //     "success": true,
    var option = { //     "reason": "success",
     url: URL + "?"// + QueryParams.toString(),   "data":{
        // headers:   {     "columns":[
        //   'Content-Type': 'application/json',         {"name":"NAME","type":5,"length":80},
       'x-api-key': API_KEY //             {"name":"TIME","type":5,"length":4096},
        };//         request.get( option, function(error, response, body) {
        {"name":"VALUE","type":20,"length":17}
    if (!error) {  //         ],
     res.writeHead(200);   //         "rows":[
    res.end(body);    //             console.log(body) // {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":[{"TIME":"2021-01-07 02:00:00 009["sensor2","2021-01-07 02:00:00 009:000:000",2],
        //             ["sensor1","2021-01-06 20:00:06 000:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":"2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}
]
        //         ]
  } else {    //     }
       console.log(error)
  // }
    })
Expand
titlepython

gitgub

Code Block
languagepy
"""
Example For Select Current }Data for tag API by using request in python
})written by yeony kim
 }"""
)
import //requests
CASE
-API_KEY Current DATA GET with another value form

app.get(
    '/select_current_date_with_nano_time_date_string_another_form', function(req, res)= "YOUR_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
CLOUD_VENDOR="CLOUD_VENDOR"
CLOUD_REGION="CLOUD_REGION"

URL = f"https://{CLOUD_VENDOR}.{CLOUD_REGION}.machlake.com/v1/lakes/{LAKE_ID}/values"

SELECT_TYPE="current"
TAG_NAME="sensor1,sensor2"

headers = {
    "Content-Type": "application/json",
  var request = require('request');

        const QueryParams = new URLSearchParams()
        
        QueryParams.set('tag_name', 'sensor1,sensor2')
        QueryParams.set('date_format', 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn')
        QueryParams.set('value_return_form', 1)

        var option = {
            url: URL + "?" + QueryParams.toString(),
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
        };
        request.get( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":{"TIME":["2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000:000:000"],"VALUE":[2]}}]},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/select_current_date_with_nano_time_date_string is result for select current data with nano date time string')
    console.log('http://127.0.0.1:8888/select_current_date_with_nano_time_date_string_another_form is result for select current data with nano date time string with value return form = 1')
})
Expand
titlepython

gitgub

Code Block
languagepy
"""
Example For Select Current Data for tag API by using request in python
written by yeony kim
sensor1, sensor2 is applied in lake
"""

import requests

API_KEY = "YOUR_API_TOKEN"
LAKE_ID = "YOUR_LAKE_ID"
URL = f"https://{LAKE_ID}.machlake.com/lakes/values/current"

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

params = {
    'tag_name': 'sensor1,sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"calc_mode":"raw","columns":[{"name":"TIME","type":5,"length":4096},{"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor2","data":[{"TIME":"2021-01-07 02:00:00 009:000:000","VALUE":2}]},{"tag_name":"sensor1","data":[{"TIME":"2021-01-06 20:00:06 000:000:000","VALUE":2}]}]},"status":"success"}


# CASE - Current DATA GET with another value form

params = {
    'tag_name': 'sensor1,sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'value_return_form': 1
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"calc_mode":"raw","columns":[ "x-api-key": API_KEY
}


# ------------------------------------------------------------------------------------------------- #

# CASE - Current DATA GET with date format YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn

params = {
    "type": SELECT_TYPE,
    "tag_name": TAG_NAME,
    "date_format": "YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn",
}

response = requests.get(URL, headers=headers,  params=params, verify=False)
print(response.content.decode("utf-8"))

# Return Format
# {
#     "success": true,
#     "reason": "success",
#     "data":{
#         "columns":[
#             {"name":"NAME","type":5,"length":80},
#             {"name":"TIME","type":5,"length":4096},
#             {"name":"VALUE","type":20,"length":17}],"samples":[{"tag_name":"sensor1","data":{"TIME":["2021-01-06 20:00:06 000
#         ],
#         "rows":[
#             ["sensor2","2021-01-07 02:00:00 009:000:000"],"VALUE":[2]}},{"tag_name":"sensor2","data":{"TIME":[",
#             ["sensor1","2021-01-0706 0220:00:0006 009000:000:000"],"VALUE":[2]}}]},"status":"success"}2]
#         ]
#     }
# }