Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@
Defs.h
*.cpp~
*.h~
*.zip
*.gz
11 changes: 11 additions & 0 deletions EServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "HTTPSP.h"
//#include <WiFiClientSecure.h>
//#include <StreamString.h>
#include <ESP32Ping.h>
#include "EServer.h"
#include "Defs.h"
#include "Oled.h"
Expand Down Expand Up @@ -257,6 +258,7 @@ bool EmlaServer::WPost(const String url, const String request, String & payload,
return result;
}

/*
// ------------------------------------------------------------------------
bool EmlaServer::WDelete(const String url, const String request, String & payload)
{
Expand Down Expand Up @@ -339,6 +341,7 @@ bool EmlaServer::WDelete(const String url, const String request, String & payloa
}
return result;
}
*/


// ------------------------------------------------------------------------
Expand Down Expand Up @@ -368,4 +371,12 @@ String EmlaServer::UrlEncode(const char *src)
return String(d);
}


// ------------------------------------------------------------------------
bool ePing(const char *hostname)
{
bool success = Ping.ping("192.168.1.67", 10);
return success;
}

//
5 changes: 4 additions & 1 deletion EServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "Oled.h"


bool ePing(const char *hostname);


class EmlaServer
{
private:
Expand All @@ -34,7 +37,7 @@ class EmlaServer
void SetCookieFromHeader(String rawCookie);
bool WGet(const String url, String & payload);
bool WPost(const String url, const String request, String & payload, bool getSessionCookie = false);
bool WDelete(const String url, const String request, String & payload);
// bool WDelete(const String url, const String request, String & payload);
String UrlEncode(const char *src);
};

Expand Down
36 changes: 33 additions & 3 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ void setup()

// Pins
pinMode(SHOCK_PIN, OUTPUT);
pinMode(SHOCK1_PIN, OUTPUT);
digitalWrite(SHOCK1_PIN, HIGH);
pinMode(SHOCK2_PIN, OUTPUT);
digitalWrite(SHOCK2_PIN, HIGH);
pinMode(SHOCK3_PIN, OUTPUT);
digitalWrite(SHOCK3_PIN, HIGH);
pinMode(SHOCK4_PIN, OUTPUT);
digitalWrite(SHOCK4_PIN, HIGH);
// pin controlling the cover state
pinMode(COVER_OPEN_PIN, INPUT_PULLUP);

Expand Down Expand Up @@ -142,7 +150,6 @@ void setup()
tasklist.Init();
verification.Init();
message.Init();
session.InfoChastikey();
session.SetTimeOfLast5sInterval(timeFunc.GetTimeInSeconds());
//
session.SetTimeOfLast5sInterval(timeFunc.GetTimeInSeconds());
Expand All @@ -164,7 +171,7 @@ void loop()
{
oledDisplay.PrintDisplay();
message.MessageCoverStateChange();
message.WriteCommandsAndSettings();
message.WriteCommandsAndSettings("loop() coverStateChanged");
oldCoverState = coverState;
}

Expand All @@ -185,6 +192,25 @@ void loop()
// every 1 minute
if (timeFunc.GetTimeInSeconds() >= (session.GetTimeOfLast1minInterval() + 60))
{
if (ePing(""))
{
// Wearer is at home
if (session.GetAwayCounter() > AWAY_LIMIT)
{
message.SendMessage("Wearer returned home.", GROUP_CHAT_ID);
message.WriteCommandsAndSettings("loop() Wearer returned home");
}
session.SetAwayCounter(0);
}
else
{
// Wearer cannot be reached
if (session.GetAwayCounter() == AWAY_LIMIT)
message.SendMessage("Wearer is away from home since " + String(AWAY_LIMIT, DEC) + " minutes.", GROUP_CHAT_ID);
if (session.GetAwayCounter() == (AWAY_LIMIT + 1))
message.WriteCommandsAndSettings("loop() Wearer is away");
session.SetAwayCounter(session.GetAwayCounter() + 1);
}
verification.ProcessVerification(GROUP_CHAT_ID);
timeFunc.ProcessSleepTime();
// this method calls tasklist.ProcessTasks() in the morning and evening
Expand All @@ -202,9 +228,13 @@ void loop()
{
session.SetEmergencyReleaseCounter(session.GetEmergencyReleaseCounter() + 1);
if (session.GetEmergencyReleaseCounter() < 2)
message.SendMessageAll("The first emergency release request has been accepted, but it needs to be raised again for confirmation.");
message.SendMessageAll("The first emergency release request has been accepted, but it needs to be raised again for confirmation. If the second request is raised successfully, the safe will be unlocked and the holder role will be removed.");
else
{
message.UnlockAction(users.GetWearer()->GetId(), GROUP_CHAT_ID, FORCE);
message.GuestAction(users.GetHolder()->GetId(), GROUP_CHAT_ID, FORCE);
session.SetEmergencyReleaseCounterRequest(false);
}
}
else
{
Expand Down
Loading