-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayground.js
178 lines (158 loc) · 4.22 KB
/
playground.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// in this file I play with code snippets and ideas
// 'use strict'
// var Duration = require('js-joda').Duration
// var LocalDateTime = require('js-joda').LocalDateTime
// obtain a Duration of 10 hours
// console.log(Duration.parse("PT10H")) // "PT10H"
// var dt = LocalDateTime.parse('2012-12-24T12:00')
// console.log(LocalDateTime.now().toString())
// var PythonShell = require('python-shell')
//
// PythonShell.run('devices/scripts/valve/open.py', function (err, results) {
// if (err) throw err
// if(results.indexOf('true') === 0) {
// console.log('true results ', results)
// } else {
// console.log('not true results ', results)
// }
// })
// var v1 = new Promise((resolve, reject) => {
// resolve('v1')
// })
//
// var v2 = new Promise((resolve, reject) => {
// resolve('v2')
// })
//
// var x;
// v1.then(str => {
// console.log(str)
// x = 11
// console.log(x);
// return v2
// })
// .then(x1 => {
// console.log(x)
// })
// while (true) {
// console.log("ENV: "+process.env.PI_GARDEN_ENV);
// console.log("NODE_PATH: "+process.env.NODE_PATH);
// var Connection = require('util/connection');
//
// }
//
// var test = function(){
// return new Promise( (resolve, reject) => {
// new Promise( (r, rj) => {
// setTimeout(r, 500)
// })
// .then(() => {
// return new Promise( (r, rj) => {
// setTimeout(r, 500)
// })
// })
// .then(() => {
// new Promise( (r, rj) => {
// setTimeout(r, 500)
// })
// .then(() => {
// resolve('saasa');
// })
// })
// })
// }
//
// var run = function myself () {
// test()
// .then(response => {
// console.log('--response: ', response)
// myself()
// })
// .catch(reason => {
// console.log('--reason: ', reason)
// myself()
// })
// }
//
//
// try {
// run()
// } catch (e) {
// throw e
// }
// group by hour and minute
// SELECT date_format(date, "%H %i") AS `Day of the week`, AVG(value) FROM stats WHERE type = 'TEMPERATURE' AND device_id = 1 AND date >= now() - INTERVAL 3 HOUR GROUP BY `Day of the week` ORDER BY date_format(date, "%H %i");
// group by HOUR
// SELECT date_format(date, "%H") AS `Day of the week`, AVG(value) FROM stats WHERE type = 'TEMPERATURE' AND device_id = 2 AND date >= now() - INTERVAL 12 HOUR GROUP BY `Day of the week` ORDER BY date_format(date, "%H");
// SELECT
// DATE_FORMAT(
// MIN(date),
// '%d/%m/%Y %H:%i:00'
// ) AS tmstamp,
// AVG(value) AS value
// FROM
// stats
// WHERE device_id = 1 AND date > '2016-11-22T09:07:26'
// GROUP BY ROUND(UNIX_TIMESTAMP(date) / 300)
//
//
//
// var Connection = require('./util/connection')
// Connection.init()
//
//
// let AreaDeviceModel = require('./db_models/AreaDeviceModel.js')
// areaDevice = new AreaDeviceModel()
// areaDevice.setAreaId(1)
// areaDevice.readAllByAreaId()
// .then(areaDevice => {
// var i = 0;
// while (areaDevice.getDeviceId() && i < 15) {
// i++
// console.log('result ', areaDevice.getDeviceId())
// areaDevice = areaDevice.getNextResult()
// console.log(areaDevice.getDeviceId());
// }
// })
// .catch(reason => {
// console.log('reason ', reason)
// })
// pin 18
//
// const Gpio = require('gpio-js')
//
// let led = new Gpio(18, 'out')
// // led ON
// led.val(1)
//
// // after one sec
// setTimeout(() => {
// // led OFF
// led.val(0)
// }, 1000)
// update devices set options = '{"js_file":"gpio/md-rd/read","GPIOpin":"23"}' where id = 6;
const Influx = require('influx')
const influx = new Influx.InfluxDB({
host: '127.0.0.1',
database: 'piGarden',
schema: [
{
measurement: 'temperature',
fields: {
value: Influx.FieldType.INTEGER
},
tags: [
'device',
'area'
]
}
]
})
influx.writePoints([{
measurement: 'temperature',
tags: { device: 1, area: 1 },
fields: { value: 24 },
timestamp: 1487148030
}]).catch(err => {
console.error(`Error saving data to InfluxDB! ${err.stack}`)
})