Commit 042810a9 by OuiAtichat

api

parent f6819f29
......@@ -8,6 +8,7 @@ import GetDataSelection from '../components/GetDataSelection/GetDataSelection';
import Mapbox from '../components/Mapbox';
import axios from 'axios';
import qs from 'qs';
import moment from 'moment';
const Data = [
{
......@@ -104,26 +105,66 @@ class Home extends Component {
currentWeight = async (ctx = '', traceback = '1y') => {
// let device_id = ctx.device_id;
const query_generator = (device_id, range, endtime) => {
// var mls = ms('1s');
let now = endtime ? endtime : new Date().getTime();
let q_data = {
start_absolute: now,
end_absolute: now,
metrics: [
{
name: device_id,
group_by: [
{
name: 'tag',
tags: ['attr'],
},
],
tags: {
attr: ['a12'],
},
aggregators: [
{
name: 'avg',
sampling: {
value: 1000,
unit: 'milliseconds',
},
},
],
},
],
};
return q_data;
};
let device_id = '3d2951a5-fa10-4d56-abae-bc471f3d2e1f';
let q_data = qs.stringify({ device_id, traceback });
// let q_data = qs.stringify({ device_id, traceback });
let q_data = query_generator(device_id, traceback);
console.log(q_data);
const userToken =
'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdHgiOnsib3duZXIiOiJVNDY0NzAxMzI2MjYwIn0sInNjb3BlIjpbXSwiaWF0IjoxNTY0OTc3MTY4LCJuYmYiOjE1NjQ5NzcxNjgsImV4cCI6MTYyODE0NDg5MSwiZXhwaXJlSW4iOjYzMTY3NzIzLCJqdGkiOiI3QzRNNUY1VyIsImlzcyI6ImNlcjp1c2VydG9rZW4ifQ.B0zXLSlsUucj4ohvH4lNVectCAt4hk--qMPEv-qhCUu82puCnNMsK2ZnnPeO_KE3up-vqVsjMVxLQ2jvmuspNg';
const kairos_url = 'https://feed.nexpie.io/api/v1/datapoints/query';
const options = {
url: kairos_url,
medthod: 'get',
headers: { 'Content-Type': 'application/json' },
data: q_data,
auth: {
username: userToken,
password: '',
},
};
// const options = {
// url: kairos_url,
// medthod: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// // Authorization: 'Bearer ' + userToken,
// },
// data: q_data,
// // data: q_data,
// auth: {
// username: userToken,
// password: '',
// },
// };
try {
// const response = await axios.post(kairos_url, options);
const response = await axios(options);
const response = await axios.post(kairos_url, q_data);
// const response = await axios(options);
console.log(response);
} catch (error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment