Skip to content

Commit

Permalink
See changlog
Browse files Browse the repository at this point in the history
  • Loading branch information
omersiar committed Sep 1, 2018
1 parent a5e9699 commit b9678a2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ All notable changes to this project will be documented in this file.
- [webui] available flash space calculation
- [webui] #143 duplicate records on User Data backup
- [firmware] #140 MQTT Heartbeat
- [webui] official board's hardware settings did not populate

#### Changed
- [firmware] do not initialize serial output unless we are debugging
- [build] slice main.cpp to multiple parts for better readability
- [webui] Access Type Active to Always
- [firmware] more reliable activation of relay

## [0.8.0]
#### Breaking Changes
Expand Down
55 changes: 38 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ const char *http_username = "admin";
char *http_pass = NULL;
unsigned long previousMillis = 0;
unsigned long previousLoopMillis = 0;
unsigned long currentMillis = 0;
unsigned long cooldown = 0;
unsigned long deltaTime = 0;
unsigned long uptime = 0;
bool shouldReboot = false;
bool activateRelay = false;
bool deactivateRelay = false;
bool inAPMode = false;
bool isWifiConnected = false;
unsigned long autoRestartIntervalSeconds = 0;
Expand Down Expand Up @@ -173,14 +177,40 @@ void ICACHE_FLASH_ATTR setup() {
}

void ICACHE_RAM_ATTR loop() {
unsigned long currentMillis = millis();
unsigned long deltaTime = currentMillis - previousLoopMillis;
unsigned long uptime = NTP.getUptimeSec();
currentMillis = millis();
deltaTime = currentMillis - previousLoopMillis;
uptime = NTP.getUptimeSec();
previousLoopMillis = currentMillis;

if (currentMillis >= cooldown) {
rfidloop();
}

if (activateRelay) {
#ifdef DEBUG
Serial.print("mili : ");
Serial.println(millis());
Serial.println("activating relay now");
#endif
digitalWrite(relayPin, !relayType);
previousMillis = millis();
activateRelay = false;
deactivateRelay = true;
writeEvent("INFO", "sys", "Activated Relay", "");
} else if((currentMillis - previousMillis >= activateTime) && (deactivateRelay)) {
#ifdef DEBUG
Serial.println(currentMillis);
Serial.println(previousMillis);
Serial.println(activateTime);
Serial.println(activateRelay);
Serial.println("deactivate relay after this");
Serial.print("mili : ");
Serial.println(millis());
#endif
digitalWrite(relayPin, relayType);
deactivateRelay = false;
writeEvent("INFO", "sys", "De-Activated Relay", "");
}

if (formatreq) {
#ifdef DEBUG
Expand Down Expand Up @@ -213,16 +243,6 @@ void ICACHE_RAM_ATTR loop() {
ESP.restart();
}

if (currentMillis - previousMillis >= activateTime && activateRelay) {
activateRelay = false;
digitalWrite(relayPin, relayType);
}

if (activateRelay) {
digitalWrite(relayPin, !relayType);

}

if (isWifiConnected) {
wiFiUptimeMillis += deltaTime;
}
Expand All @@ -244,10 +264,10 @@ void ICACHE_RAM_ATTR loop() {
enableWifi();
}
}

if (mqttClient.connected()) {
if (mqttenabled == 1) {
if ((unsigned)now() > nextbeat) {
if (mqttenabled == 1) {
if (mqttClient.connected()) {
if ((unsigned)now() > nextbeat) {
mqtt_publish_heartbeat(now());
nextbeat = (unsigned)now() + interval;
#ifdef DEBUG
Expand All @@ -257,4 +277,5 @@ void ICACHE_RAM_ATTR loop() {
}
}
}

}
2 changes: 0 additions & 2 deletions src/rfid.esp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ void ICACHE_FLASH_ATTR rfidloop() {
#endif
if (AccType == 1) {
activateRelay = true;
previousMillis = millis();
ws.textAll("{\"command\":\"giveAccess\"}");
#ifdef DEBUG
Serial.println(" have access");
Expand All @@ -110,7 +109,6 @@ void ICACHE_FLASH_ATTR rfidloop() {
mqtt_publish_access(now(), "true", "Always", username, uid);
}
} else if (AccType == 99) {
previousMillis = millis();
doEnableWifi = true;
activateRelay = true;
ws.textAll("{\"command\":\"giveAccess\"}");
Expand Down
Loading

0 comments on commit b9678a2

Please sign in to comment.