-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfusor-esp-power-meter.ino
67 lines (49 loc) · 1.67 KB
/
fusor-esp-power-meter.ino
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
/*
* Power metering node
* See readme.md for more details
*/
// Uncomment and rebuild libraries for debug messages
// #define SM_DEBUGGER
#include <Arduino.h>
#include <StateMachine.h>
#include <StateMachineDebug.h>
#include <NodeConnector.h>
#include <Bme280Plugin.h>
#include <InterruptPlugin.h>
#include <PowerSensorPlugin.h>
#include <DSCAlarmSystemPlugin.h>
#include "display.h"
NodeConnector nodeConnector("pm");
// sensor for ambient temperature, humidity and pressure
Bme280Plugin bme250Plugin = Bme280Plugin("bme", true, D2, D1);
// button to turn on display when needed
InterruptPlugin interruptPlugin = InterruptPlugin("d5", D5);
// SCT-013 current sensor used for consumed power measurement
PowerSensorPlugin powerSensorPlugin = PowerSensorPlugin("pow", A0);
void setup() {
Serial.begin(1000000);
delay(100);
pinMode(D5, INPUT); // digital input for control button
displayInit();
displayPrintStr("Loading...");
if (nodeConnector.setup(D5, false, 3000)) {
Serial.println(F("State Machine Definition loaded"));
} else {
Serial.println(F("No SMD. Halt."));
while(true) delay(100000);
}
nodeConnector.sm.registerAction("display_off", displayOff);
nodeConnector.sm.registerAction("display_on", displayOn);
nodeConnector.sm.registerAction("display_update", updateDisplay);
nodeConnector.sm.registerPlugin(&bme250Plugin);
nodeConnector.sm.registerPlugin(&interruptPlugin);
nodeConnector.sm.registerPlugin(&powerSensorPlugin);
Serial.println(F("Actions and plugins registered"));
nodeConnector.start();
Serial.println(F("State machine initialized"));
displayPrintStr("Loaded");
delay(2000);
}
void loop() {
nodeConnector.loop();
}