Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

Version 1 Next »

Json 포멧으로 tag name, 시간, 다른 칼럼값들을 지정하여 입력하는 표준 입력 방법이다. 이 API는 모든 센서 데이터에 대해서 JSON포멧으로 칼럼 명을 지정해 주어야 하기 때문에 데이터 용량이 커져서 비용과 성능이 감소하는 문제가 있지만 입력하는 tag의 수가 적은 경우 간편하게 사용할 수 있다.

HTTP Request

POST https://${CloudVendor}.${CountryCode}.machlake.com/lakes/${lake_id}/values/standard
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
  
{
    "tag_name"      : "{name_of_tag}",
    "date_format"   : "{date_format}",
    "values"        : [["{time1}", {value1}], ["{time2}", {value2}], ... ]
}

Parameters

no parameters

Request Example

POST https://aws1.us.machlake.com/lakes/xbacd1234/values/standard
Content-Type: application/json; charset=utf8
x-api-key: {API Key}
{
    "tag_name"      : "tag_01",
    "date_format"   : "YYYY-MM-DD HH24:MI:SS",
    "values"        : [
        ["2021-07-06 12:12:22", 1234.0], 
        ["2021-07-06 12:12:23", 2345.0],
        ["2021-07-06 12:12:24", 2346.0]
    ]
}

Response Example

Status 200
 
{
    "status": "success",
    "data": {
        "fail": 0,
        "success": 3
    }
}

Sample Code

In this sample, value_schema in create lake is [time:datetime, value: double] so if value_schema is difference then result is different, and each record in values has same order to schema

 window(batch)

github

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

set API_KEY=YOUR_API_TOKEN

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%.machlake.com/lakes/values/standard

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

:: CASE - Insert Data with nano date time string format

set TAG_NAME=sensor1
set DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn\"
set VALUES=[[\"2021-01-06 17:00:00 001:000:000\", 1.0], [\"2021-01-06 17:00:00 002:000:000\", 1.5], [\"2021-01-06 17:00:00 003:000:000\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format 
:: {"data":{"fail":0,"success":3},"status":"success"}

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

:: CASE - Insert Data with time format is empty but data format in data is nano date time string

set TAG_NAME=sensor1
set DATE_FORMAT=\"\"
set VALUES=[[\"2021-01-06 17:00:00 004:000:000\", 1.0], [\"2021-01-06 17:00:00 005:000:000\", 1.5], [\"2021-01-06 17:00:00 006:000:000\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format
:: {"data":{"fail":0,"success":3},"status":"success"}

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

:: CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

set TAG_NAME=sensor1
set DATE_FORMAT=\"\"
set VALUES=[[\"2021-01-06 8:00:00 007:000:000\", 1.0], [\"2021-01-06 8:00:00 008:000:000\", 1.5], [\"2021-01-06 8:00:00 009:000:000\", 2.0]]

curl -k -X POST %URL% -H "Use-Timezone: Africa/Abidjan" -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format 
:: {"data":{"fail":0,"success":3},"status":"success"}

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

:: CASE - Insert Data with date time string format

set TAG_NAME=sensor2
set DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS\"
set VALUES=[[\"2021-01-06 17:00:00\", 1.0], [\"2021-01-06 17:00:01\", 1.5], [\"2021-01-06 17:00:02\", 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format 
:: {"data":{"fail":0,"success":3},"status":"success"}

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

:: CASE - Insert Data with nano-timestamp

set TAG_NAME=sensor2
set VALUES=[[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]

curl -k -X POST %URL% -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"sensor2\", \"values\": %VALUES%}"

:: Return Format  / timestamp 사용 예제
:: {"data":{"fail":0,"success":3},"status":"success"}

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

:: CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

set TAG_NAME=sensor2
set DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS\"
set VALUES=[[\"2021-01-06 17:00:00 007:000:000\", 1.0], [\"2021-01-06 17:00:00 008:000:000\", 1.5], [\"2021-01-06 17:00:00 009:000:000\", 2.0]]

curl -k -X POST %URL% -H "Use-Timezone: Africa/Abidjan" -H %CONTENT_HEADER% -H %API_HEADER%  -d "{\"tag_name\": \"%TAG_NAME%\", \"date_format\": %DATE_FORMAT%, \"values\": %VALUES%}"

:: Return Format / Time Zone 사용 (UTC-0)
:: {"data":{"fail":0,"success":3},"status":"success"}

:: ------------------------------------------------------------------------------------------------- ::
 linux(shell)

github

# Text Encoding to UTF-8 in CMD
# Example For Insert Standard 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/standard

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

# CASE - Insert Data with nano date time string format

TAG_NAME=sensor1
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn"
VALUES="[[\"2021-01-06 17:00:00 001:000:000\", 1.0], [\"2021-01-06 17:00:00 002:000:000\", 1.5], [\"2021-01-06 17:00:00 003:000:000\", 2.0]]"
curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format 
# {"data":{"fail":0,"success":3},"status":"success"}

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

# CASE - Insert Data with time format is empty but data format in data is nano date time string

TAG_NAME=sensor1
DATE_FORMAT=""
VALUES="[[\"2021-01-06 17:00:00 004:000:000\", 1.0], [\"2021-01-06 17:00:00 005:000:000\", 1.5], [\"2021-01-06 17:00:00 006:000:000\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format
# {"data":{"fail":0,"success":3},"status":"success"}

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

# CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

TAG_NAME=sensor1
DATE_FORMAT=""
VALUES="[[\"2021-01-06 8:00:00 007:000:000\", 1.0], [\"2021-01-06 8:00:00 008:000:000\", 1.5], [\"2021-01-06 8:00:00 009:000:000\", 2.0]]"

curl -k -X POST $URL -H "Use-Timezone:Africa/Abidjan" -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format 
# {"data":{"fail":0,"success":3},"status":"success"}

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

# CASE - Insert Data with date time string format

TAG_NAME=sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
VALUES="[[\"2021-01-06 17:00:00\", 1.0], [\"2021-01-06 17:00:01\", 1.5], [\"2021-01-06 17:00:02\", 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format 
# {"data":{"fail":0,"success":3},"status":"success"}

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

# CASE - Insert Data with nano-timestamp

TAG_NAME=sensor2
VALUES="[[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]"

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER  -d "{\"tag_name\": \"sensor2\", \"values\": $VALUES}"

# Return Format  / timestamp 사용 예제
# {"data":{"fail":0,"success":3},"status":"success"}

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

# CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

TAG_NAME=sensor2
DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
VALUES="[[\"2021-01-06 17:00:00 007:000:000\", 1.0], [\"2021-01-06 17:00:00 008:000:000\", 1.5], [\"2021-01-06 17:00:00 009:000:000\", 2.0]]"

curl -k -X POST $URL -H "Use-Timezone:Africa/Abidjan" -H $CONTENT_HEADER -H $API_HEADER -d "{\"tag_name\": \"$TAG_NAME\", \"date_format\": \"$DATE_FORMAT\", \"values\": $VALUES}"

# Return Format / Time Zone 사용 (UTC-0)
# {"data":{"fail":0,"success":3},"status":"success"}

# ------------------------------------------------------------------------------------------------- #
 javascript

github

// Example For Insert Standard Data for tag API by using request in nodejs
// 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/standard";

// CASE - Insert Data with nano date time string format

app.get(
    '/insert_standard_with_nano_date_time_string', function(req, res) {
        const Data = {
            tag_name: 'sensor1',
            date_format: 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
            values: [["2021-01-06 17:00:00 001:000:000", 1.0], ["2021-01-06 17:00:00 002:000:000", 1.5], ["2021-01-06 17:00:00 003:000:000", 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Insert Data with time format is empty but data format in data is nano date time string

app.get(
    '/insert_standard_with_nano_date_time_string_diff_setting', function(req, res) {
        const Data = {
            tag_name: 'sensor1',
            values: [["2021-01-06 17:00:00 004:000:000", 1.0], ["2021-01-06 17:00:00 005:000:000", 1.5], ["2021-01-06 17:00:00 006:000:000", 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

app.get(
    '/insert_standard_with_nano_date_time_string_utc0', function(req, res) {
        const Data = {
            tag_name: 'sensor1',
            values: [["2021-01-06 8:00:00 007:000:000", 1.0], ["2021-01-06 8:00:00 008:000:000", 1.5], ["2021-01-06 8:00:00 009:000:000", 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY,
                'Use-Timezone': 'Africa/Abidjan'
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Insert Data with date time string format

app.get(
    '/insert_standard_with_date_time_string', function(req, res) {
        const Data = {
            tag_name: 'sensor2',
            date_format: 'YYYY-MM-DD HH24:MI:SS',
            values: [["2021-01-06 17:00:00", 1.0], ["2021-01-06 17:00:01", 1.5], ["2021-01-06 17:00:02", 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY,
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

// CASE - Insert Data with nano-timestamp

app.get(
    '/insert_standard_with_nano_timestamp', function(req, res) {
        const Data = {
            tag_name: 'sensor2',
            values: [[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY,
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)


// CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

app.get(
    '/insert_standard_with_date_time_string_diff_setting_utc0', function(req, res) {
        const Data = {
            tag_name: 'sensor2',
            date_format: 'YYYY-MM-DD HH24:MI:SS',
            values: [["2021-01-06 17:00:00 007:000:000", 1.0], ["2021-01-06 17:00:00 008:000:000", 1.5], ["2021-01-06 17:00:00 009:000:000", 2.0]]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY,
                "Use-Timezone": "Africa/Abidjan"
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)







app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/insert_standard_with_nano_date_time_string is result for insert standard data with nano date time string')
    console.log('http://127.0.0.1:8888/insert_standard_with_nano_date_time_string_diff_setting is result for insert standard data with nano date time string with diff settings')
    console.log('http://127.0.0.1:8888/insert_standard_with_nano_date_time_string_utc0 is result for insert standard data with nano date time string with diff settings with utc-0')
    console.log('http://127.0.0.1:8888/insert_standard_with_date_time_string is result for insert standard data with date time string')
    console.log('http://127.0.0.1:8888/insert_standard_with_nano_timestamp is result for insert standard data with nano timestamp')
    console.log('http://127.0.0.1:8888/insert_standard_with_date_time_string_diff_setting_utc0 is result for insert standard data with date time string with utc-0')
})
 python

github

"""
Example For Insert Standard 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/standard"

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

# CASE - Insert Data with nano date time string format

params = {
    'tag_name': 'sensor1',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'values': [["2021-01-06 17:00:00 001:000:000", 1.0], ["2021-01-06 17:00:00 002:000:000", 1.5], ["2021-01-06 17:00:00 003:000:000", 2.0]]
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"fail":0,"success":3},"status":"success"}

# CASE - Insert Data with time format is empty but data format in data is nano date time string

params = {
    'tag_name': 'sensor1',
    'values': [["2021-01-06 17:00:00 004:000:000", 1.0], ["2021-01-06 17:00:00 005:000:000", 1.5], ["2021-01-06 17:00:00 006:000:000", 2.0]]
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"fail":0,"success":3},"status":"success"}


# CASE - Insert Data with utc-0 time zone and time format is empty but data format in data is nano date time string

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

params = {
    'tag_name': 'sensor1',
    'values': [["2021-01-06 8:00:00 007:000:000", 1.0], ["2021-01-06 8:00:00 008:000:000", 1.5], ["2021-01-06 8:00:00 009:000:000", 2.0]]
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"fail":0,"success":3},"status":"success"}


# CASE - Insert Data with date time string format

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

params = {
    'tag_name': 'sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS',
    'values': [["2021-01-06 17:00:00", 1.0], ["2021-01-06 17:00:01", 1.5], ["2021-01-06 17:00:02", 2.0]]
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"fail":0,"success":3},"status":"success"}


# CASE - Insert Data with nano-timestamp

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

params = {
    'tag_name': 'sensor2',
    'values': [[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"fail":0,"success":3},"status":"success"}


# CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY,
    "Use-Timezone": "Africa/Abidjan"
}

params = {
    'tag_name': 'sensor2',
    'date_format': 'YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn',
    'values': [["2021-01-06 17:00:00 007:000:000", 1.0], ["2021-01-06 17:00:00 008:000:000", 1.5], ["2021-01-06 17:00:00 009:000:000", 2.0]]
}

response = requests.post(URL, headers=headers,  json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":{"fail":0,"success":3},"status":"success"}

 

  • No labels