Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented automatic setting of clock display from network time. #6034

Merged
merged 3 commits into from Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions sonoff/_changelog.ino
@@ -1,4 +1,5 @@
/*********************************************************************************************\
* Add automatic setting of clock display from network time for AZ7798
* 6.6.0.1 20190707
* Add blend RGB leds with White leds for better whites #5895 #5704
*
Expand Down
28 changes: 26 additions & 2 deletions sonoff/xsns_38_az7798.ino
Expand Up @@ -118,7 +118,10 @@
#define CO2_HIGH 1200 // Above this CO2 value show red light
#endif

#define AZ_READ_TIMEOUT 400 // Must be way less than 1000 but enough to read 9 bytes at 9600 bps
#define AZ_READ_TIMEOUT 400 // Must be way less than 1000 but enough to read 25 bytes at 9600 bps

#define AZ_CLOCK_UPDATE_INTERVAL (24UL * 60 * 60) // periodically update clock display (24 hours)
#define AZ_EPOCH (946684800UL) // 2000-01-01 00:00:00

TasmotaSerial *AzSerial;

Expand All @@ -129,11 +132,14 @@ double az_temperature = 0;
double az_humidity = 0;
uint8_t az_received = 0;
uint8_t az_state = 0;
unsigned long az_clock_update = 10; // timer for periodically updating clock display

/*********************************************************************************************/

void AzEverySecond(void)
{
unsigned long start = millis();

az_state++;
if (5 == az_state) { // every 5 seconds
az_state = 0;
Expand All @@ -143,7 +149,6 @@ void AzEverySecond(void)
az_received = 0;

uint8_t az_response[32];
unsigned long start = millis();
uint8_t counter = 0;
uint8_t i, j;
uint8_t response_substr[16];
Expand Down Expand Up @@ -234,6 +239,25 @@ void AzEverySecond(void)
response_substr[j] = 0; // add null terminator
az_humidity = ConvertHumidity(CharToFloat((char*)response_substr));
}

// update the clock from network time
if ((az_clock_update == 0) && (local_time > AZ_EPOCH)) {
char tmpString[16];
sprintf(tmpString, "C %d\r", (int)(local_time - AZ_EPOCH));
AzSerial->write(tmpString);
// discard the response
do {
if (AzSerial->available() > 0) {
if(AzSerial->read() == 0x0d) { break; }
} else {
delay(5);
}
} while(((millis() - start) < AZ_READ_TIMEOUT));
az_clock_update = AZ_CLOCK_UPDATE_INTERVAL;
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "AZ7798 clock updated"));
} else {
az_clock_update--;
}
}

/*********************************************************************************************/
Expand Down