// 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 API_KEY ="YOUR_API_TOKEN";
const LAKE_ID ="YOUR_LAKE_ID";
const CLOUD_VENDOR="CLOUD_VENDOR";
const CLOUD_REGION="CLOUD_REGION";
var request = require('request');
// CASE - Insert Data with nano date time string format
var 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]]
}
request.post({
url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/standard`,
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY
},
body: JSON.stringify(Data)
},
function(error, response, body) {
console.log(body)
})
// CASE - Insert Data with time format is empty but data format in data is nano date time string
var 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]]
}
request.post({
url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/standard`,
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
},
body: JSON.stringify(Data)
};,
request.post( option, function(error, response, body) {
if (!errorconsole.log(body)
{ })
// CASE - Insert Data with utc-0 time zone res.writeHead(200);
res.end(body);
and time format is empty but data format in data is nano date time string
var Data = {
tag_name: 'sensor1',
console.log(body) // {"data":{"fail":0,"success":3},"status":"success"}
} else 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]]
}
request.post({
url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/standard`,
headers: {
console.log(error) 'Content-Type': 'application/json',
} 'x-api-key': API_KEY,
}) }
)'Use-Timezone': 'Africa/Abidjan'
// 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 = {
body: JSON.stringify(Data)
},
function(error, response, body) {
console.log(body)
})
// CASE - Insert Data with date time string format
var 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:00001", 1.5], ["2021-01-06 17:00:00 009:000:00002", 2.0]]
}
request.post({
}
var request = require('request');url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/standard`,
var option =headers: {
url: URL'Content-Type': 'application/json',
headers: {'x-api-key': API_KEY
},
body: JSON.stringify(Data)
'Content-Type': 'application/json'},
function(error, response, body) {
'x-api-key': API_KEY,
console.log(body)
})
// CASE "Use-Timezone": "Africa/Abidjan"
Insert Data with nano-timestamp
var Data = {
}tag_name: 'sensor2',
values: [[1609920003000000000, 1.0], [1609920004000000000, 1.5], [1609920005000000000, 2.0]]
}
body: JSON.stringify(Data)request.post({
};url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/standard`,
request.post( option, function(error, response, body) headers: {
'Content-Type': 'application/json',
if (!error) { 'x-api-key': API_KEY
},
body: resJSON.writeHeadstringify(200Data);
},
res.end(body);
function(error, response, 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')
})
})
// CASE - Insert Data with utc-0 time zone and date time string format but data format in data is nano date time string
var 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]]
}
request.post({
url: `https://${CLOUD_VENDOR}.${CLOUD_REGION}.machlake.com/lakes/${LAKE_ID}/values/standard`,
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
"Use-Timezone": "Africa/Abidjan"
},
body: JSON.stringify(Data)
},
function(error, response, body) {
console.log(body)
}) |