Software part
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
.pio
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"terminal.integrated.env.osx": {
|
||||
"PATH": "/Users/monster/.platformio/penv/bin:/Users/monster/.platformio/penv:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin",
|
||||
"PLATFORMIO_CALLER": "vscode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
This directory is intended for the project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link to executable file.
|
||||
|
||||
The source code of each library should be placed in separate directory, like
|
||||
"lib/private_lib/[here are source files]".
|
||||
|
||||
For example, see how can be organized `Foo` and `Bar` libraries:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) http://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- readme.txt --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
Then in `src/main.c` you should use:
|
||||
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
// rest H/C/CPP code
|
||||
|
||||
PlatformIO will find your libraries automatically, configure preprocessor's
|
||||
include paths and build them.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- http://docs.platformio.org/page/librarymanager/ldf.html
|
||||
@@ -0,0 +1,24 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; http://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:d1_mini]
|
||||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
# Using a library name
|
||||
ArduinoJSON@5.10.0
|
||||
Homie@1.5.0,
|
||||
Bounce2
|
||||
|
||||
monitor_speed = 115200
|
||||
#upload_speed = 921600
|
||||
|
||||
#build_flags = -Wl,-Tesp8266.flash.4m1m.ld
|
||||
@@ -0,0 +1,111 @@
|
||||
#include <Arduino.h>
|
||||
#include <Homie.h>
|
||||
|
||||
#define NEST_Y1 D5 //#
|
||||
#define NEST_Y2 D6 //#
|
||||
#define NEST_G D7 //D3
|
||||
#define NEST_S D2
|
||||
#define NEST_W1 D1 //#
|
||||
#define NEST_W2 D0
|
||||
|
||||
|
||||
int lastState_W1 = -1;
|
||||
int lastState_W2 = -1;
|
||||
int lastState_Y1 = -1;
|
||||
int lastState_Y2 = -1;
|
||||
int lastState_S = -1;
|
||||
int lastState_G = -1;
|
||||
|
||||
bool state_w1 = false;
|
||||
bool state_w2 = false;
|
||||
bool state_y1 = false;
|
||||
bool state_y2 = false;
|
||||
bool state_s = false;
|
||||
bool state_g = false;
|
||||
|
||||
HomieNode nestNode("nest", "node");
|
||||
|
||||
bool resetHandler(String value) {
|
||||
//remove config =)
|
||||
SPIFFS.remove("/homie/config.json");
|
||||
|
||||
Homie.setNodeProperty(nestNode, "reset", value, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void setupHandler() {
|
||||
pinMode(NEST_W1, INPUT_PULLUP);
|
||||
pinMode(NEST_W2, INPUT_PULLUP);
|
||||
pinMode(NEST_Y1, INPUT_PULLUP);
|
||||
pinMode(NEST_Y2, INPUT_PULLUP);
|
||||
pinMode(NEST_S, INPUT_PULLUP);
|
||||
pinMode(NEST_G, INPUT_PULLUP);
|
||||
|
||||
nestNode.subscribe("reset", resetHandler);
|
||||
}
|
||||
|
||||
void loopHandler() {
|
||||
}
|
||||
|
||||
void setup() {
|
||||
SPIFFS.begin();
|
||||
Homie.disableResetTrigger();
|
||||
|
||||
Homie.setFirmware("nest-firmware", "1.0.0");
|
||||
Homie.setSetupFunction(setupHandler);
|
||||
Homie.setLoopFunction(loopHandler);
|
||||
Homie.registerNode(nestNode);
|
||||
Homie.setup();
|
||||
}
|
||||
|
||||
void read_pin(int pin, bool &pin_state) {
|
||||
int state = digitalRead(pin);
|
||||
// Serial.print(pin);
|
||||
// Serial.print("=");
|
||||
// Serial.println(state);
|
||||
if (state == 0) {
|
||||
pin_state = true;
|
||||
}
|
||||
}
|
||||
|
||||
void send_state(int state, int& lastState, const String name) {
|
||||
if (state != lastState) {
|
||||
Serial.print(name);
|
||||
Serial.print(" state changed from ");
|
||||
Serial.print(lastState);
|
||||
Serial.print(" to ");
|
||||
Serial.println(state);
|
||||
|
||||
Homie.setNodeProperty(nestNode, name, String(state), true);
|
||||
lastState = state;
|
||||
}
|
||||
}
|
||||
|
||||
void measure_pins() {
|
||||
state_w1 = false;
|
||||
state_w2 = false;
|
||||
state_y1 = false;
|
||||
state_y2 = false;
|
||||
state_s = false;
|
||||
state_g = false;
|
||||
for(int i = 0; i<250; i++) {
|
||||
read_pin(NEST_W1, state_w1);
|
||||
read_pin(NEST_W2, state_w2);
|
||||
read_pin(NEST_Y1, state_y1);
|
||||
read_pin(NEST_Y2, state_y2);
|
||||
read_pin(NEST_S, state_s);
|
||||
read_pin(NEST_G, state_g);
|
||||
Homie.loop();
|
||||
delay(1);
|
||||
}
|
||||
send_state(state_w1, lastState_W1, "w1");
|
||||
send_state(state_w2, lastState_W2, "w2");
|
||||
send_state(state_y1, lastState_Y1, "y1");
|
||||
send_state(state_y2, lastState_Y2, "y2");
|
||||
send_state(state_s, lastState_S, "s");
|
||||
send_state(state_g, lastState_G, "g");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
measure_pins();
|
||||
}
|
||||
Reference in New Issue
Block a user