-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.nut
More file actions
50 lines (39 loc) · 1.26 KB
/
Copy pathDevice.nut
File metadata and controls
50 lines (39 loc) · 1.26 KB
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
// Læser Pulser på Emernet E420
// 10.000 pulser/kwh
// Dong El Pris gælder 1. kvt 2014 228,04 øre
queue <- [];
count <- hardware.pin1;
count.configure(PULSE_COUNTER, 20); // Tæller i x sekunder
Frekvens <- 0;
WattHour <-0;
WattMinut <-0;
const PulsePrKWH = 10000;
const elpris = 228.04
function sendQueuedData() {
agent.send("queueddata", queue);
queue = [];
}
function GetApproximateFrequency() {
local numPulses = count.read();
local approxFreq = numPulses * 3.0; // ganger med x for at få et minut
return approxFreq;
}
function SendDataToCloud() {
Frekvens = GetApproximateFrequency() ;
local t = time();
queue.push({ timestamp = t, sensorvalue = Frekvens });
// if it is midnight
if (t % 86400 == 0) {
sendQueuedData();
}
Frekvens = GetApproximateFrequency() ;
WattHour = (36000000 / Frekvens) / PulsePrKWH; // Antal blink for en KHh 60 x 60 x 10.000
server.log("The signal on pin1 is about" + Frekvens + "Hz");
//agent.send("Xively", Frekvens);
local jsonString="{power:"+Frekvens+",WattHour:"+WattHour+"}";
agent.send("EmonCms",jsonString); // Sending data to "agent"
}
imp.onidle(function() {
SendDataToCloud();
server.sleepfor(60 - (time() % 60));
});