Don't arm lockout if green button is pressed
This commit is contained in:
parent
914ad9bcf2
commit
3388e86d3d
|
@ -3,11 +3,6 @@
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
// Move to function:
|
|
||||||
// Generated with: https://arduinojson.org/assistant/
|
|
||||||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 50;
|
|
||||||
DynamicJsonBuffer jsonBuffer(bufferSize);
|
|
||||||
|
|
||||||
const char* WIFI_SSID = "Protospace";
|
const char* WIFI_SSID = "Protospace";
|
||||||
const char* WIFI_PASS = "yycmakers";
|
const char* WIFI_PASS = "yycmakers";
|
||||||
char wifiMACAddr[18];
|
char wifiMACAddr[18];
|
||||||
|
@ -30,7 +25,7 @@ const String API_ROUTE = String("http://tools.protospace.ca:8080/api/lockout/");
|
||||||
#define LOGGING true
|
#define LOGGING true
|
||||||
|
|
||||||
#define DELAY_TIME 10
|
#define DELAY_TIME 10
|
||||||
#define COMM_IDLE_TIME 1000 / DELAY_TIME
|
#define COMM_IDLE_TIME 500 / DELAY_TIME
|
||||||
|
|
||||||
enum wifiStates
|
enum wifiStates
|
||||||
{
|
{
|
||||||
|
@ -178,19 +173,30 @@ void processLockState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JSON functions to prevent memory leaking
|
||||||
String serializeJson(int lockState) {
|
String serializeJson(int lockState) {
|
||||||
// Generated with: https://arduinojson.org/assistant/
|
// Generated with: https://arduinojson.org/assistant/
|
||||||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 50;
|
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 50;
|
||||||
DynamicJsonBuffer jsonBuffer(bufferSize);
|
DynamicJsonBuffer jsonBuffer(bufferSize);
|
||||||
|
|
||||||
JsonObject& rootSerializer = jsonBuffer.createObject();
|
JsonObject& root = jsonBuffer.createObject();
|
||||||
rootSerializer["lockState"] = (int) lockState;
|
root["lockState"] = (int) lockState;
|
||||||
String postData = String();
|
String postData = String();
|
||||||
rootSerializer.printTo(postData);
|
root.printTo(postData);
|
||||||
|
|
||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String deserializeJson(String input) {
|
||||||
|
// Generated with: https://arduinojson.org/assistant/
|
||||||
|
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 50;
|
||||||
|
DynamicJsonBuffer jsonBuffer(bufferSize);
|
||||||
|
JsonObject& root = jsonBuffer.parseObject(input);
|
||||||
|
|
||||||
|
String action = root["action"];
|
||||||
|
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
void processCommState()
|
void processCommState()
|
||||||
{
|
{
|
||||||
|
@ -226,11 +232,9 @@ void processCommState()
|
||||||
if (LOGGING) Serial.print("[INFO] Resource found, parsing response: ");
|
if (LOGGING) Serial.print("[INFO] Resource found, parsing response: ");
|
||||||
String payload = http.getString();
|
String payload = http.getString();
|
||||||
if (LOGGING) Serial.println(payload);
|
if (LOGGING) Serial.println(payload);
|
||||||
JsonObject& rootDeserializer = jsonBuffer.parseObject(payload);
|
String action = deserializeJson(payload);
|
||||||
|
|
||||||
String action = rootDeserializer["action"];
|
if (action == "arm" && lockState == LOCK_OFF && digitalRead(ON_BUTTON_PIN) == BUTTON_OPEN) {
|
||||||
|
|
||||||
if (action == "arm" && lockState == LOCK_OFF) {
|
|
||||||
lockState = LOCK_ARMED;
|
lockState = LOCK_ARMED;
|
||||||
} else if (action == "disarm" && lockState == LOCK_ARMED) {
|
} else if (action == "disarm" && lockState == LOCK_ARMED) {
|
||||||
lockState = LOCK_OFF;
|
lockState = LOCK_OFF;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user