generated from spothings/spothings
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from spothings/dev-code
implement NTP time
- Loading branch information
Showing
5 changed files
with
85 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <NTPClient.h> | ||
#include <WiFiUdp.h> | ||
|
||
// Define NTP Client to get time | ||
WiFiUDP ntpUDP; | ||
NTPClient timeClient(ntpUDP, "pool.ntp.org"); | ||
|
||
void setupNTP() { | ||
// Initialize a NTPClient to get time | ||
timeClient.begin(); | ||
timeClient.setTimeOffset(28800); // add 3600 each 1 GMT (8*3600 = 28800) | ||
} | ||
|
||
int getTimeNTP() { | ||
timeClient.update(); | ||
int currentHour = timeClient.getHours(); // get current hours ntp time (24 hour) | ||
return currentHour; | ||
} | ||
|
||
bool GetTime() { | ||
int ntpTime = getTimeNTP(); | ||
if (ntpTime > 18 and ntpTime < 7) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
void SerialMonitor(int _potencia, int _waiting, int _maxldr, int _minldr, int _nilaimalam, bool _malam){ | ||
void PrintMonitor(int _potencia, int _waiting, int _maxldr, int _minldr, int _lightLimit, bool _relayStatus) { | ||
Serial.print(_potencia); | ||
Serial.print("\t"); | ||
Serial.print(_waiting/10); | ||
Serial.print(_waiting / 10); | ||
Serial.print("\t"); | ||
Serial.print(_maxldr); | ||
Serial.print("\t"); | ||
Serial.print(_minldr); | ||
Serial.print("\t"); | ||
Serial.print(_nilaimalam); | ||
Serial.print(_lightLimit); | ||
Serial.print("\t"); | ||
if (_malam){ | ||
Serial.print("gelap"); | ||
|
||
if (_potencia < _lightLimit) { | ||
Serial.print("dark"); | ||
} else { | ||
Serial.print("terang"); | ||
Serial.print("bright"); | ||
} | ||
|
||
Serial.print("\t"); | ||
|
||
if (_relayStatus) { | ||
Serial.print("On"); | ||
} else { | ||
Serial.print("Off"); | ||
} | ||
|
||
Serial.print("\n"); | ||
} |