mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-08 13:10:29 +00:00
Correct some typos and fix condition in LoRa gateway code
This commit is contained in:
parent
6ba88a52a9
commit
9839e746aa
@ -120,7 +120,7 @@ void beginFDRS()
|
||||
Serial.begin(115200);
|
||||
UART_IF.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
||||
#endif
|
||||
#if defined(USE_OLED) || defined(USE_DS3231) || defined(USE_RTC_DS1307)
|
||||
#if defined(USE_OLED) || defined(USE_RTC_DS3231) || defined(USE_RTC_DS1307)
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
#endif
|
||||
#if defined(USE_RTC_DS3231) || defined(USE_RTC_DS1307)
|
||||
|
@ -392,8 +392,8 @@ crcResult getLoRa()
|
||||
{
|
||||
unsigned int ln = (packetSize - 6) / sizeof(SystemPacket);
|
||||
SystemPacket receiveData[ln];
|
||||
|
||||
if (calcCRC == packetCRC)
|
||||
// SystemPacket data type do not require ACKs so we don't care which of the two CRC calculations are used
|
||||
if (packetCRC == calcCRC || packetCRC == crc16_update(calcCRC, 0xA1))
|
||||
{
|
||||
memcpy(receiveData, &packet[4], packetSize - 6); // Split off data portion of packet (N bytes)
|
||||
if (ln == 1 && receiveData[0].cmd == cmd_ack)
|
||||
@ -427,7 +427,7 @@ crcResult getLoRa()
|
||||
timeMaster.tmLastTimeSet = millis();
|
||||
}
|
||||
else {
|
||||
DBGF("LoRa 0x" + String(sourceMAC, HEX) + " is not time master, discarding request");
|
||||
DBG("LoRa 0x" + String(sourceMAC, HEX) + " is not time master, discarding request");
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -648,7 +648,7 @@ uint32_t pingFDRSLoRa(uint16_t *address, uint32_t timeout)
|
||||
SystemPacket sys_packet = {.cmd = cmd_ping, .param = 0};
|
||||
|
||||
transmitLoRa(address, &sys_packet, 1);
|
||||
DBGF("LoRa ping sent to address: 0x" + String(*address, HEX));
|
||||
DBG("LoRa ping sent to address: 0x" + String(*address, HEX));
|
||||
uint32_t ping_start = millis();
|
||||
pingFlagLoRa = false;
|
||||
// JL - future: figure out how to handle this asynchronously so we are not taking up processor time
|
||||
@ -660,12 +660,12 @@ uint32_t pingFDRSLoRa(uint16_t *address, uint32_t timeout)
|
||||
#endif
|
||||
if (pingFlagLoRa)
|
||||
{
|
||||
DBGF("LoRa Ping Returned: " + String(millis() - ping_start) + "ms.");
|
||||
DBG("LoRa Ping Returned: " + String(millis() - ping_start) + "ms.");
|
||||
pingFlagLoRa = false;
|
||||
return (millis() - ping_start);
|
||||
}
|
||||
}
|
||||
DBGF("No LoRa ping returned within " + String(timeout) + "ms.");
|
||||
DBG("No LoRa ping returned within " + String(timeout) + "ms.");
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ void begin_rtc() {
|
||||
// 1) first time you ran and the device wasn't running yet
|
||||
// 2) the battery on the device is low or even missing
|
||||
|
||||
DBGF("RTC error: Date and Time not valid! Err: " + String(err));
|
||||
DBG("RTC error: Date and Time not valid! Err: " + String(err));
|
||||
validRtcFlag = false;
|
||||
}
|
||||
}
|
||||
@ -78,7 +78,7 @@ void begin_rtc() {
|
||||
if(!rtc.GetIsRunning()) {
|
||||
uint8_t err = rtc.LastError();
|
||||
if(err != 0) {
|
||||
DBGF("RTC was not actively running, starting now. Err: " + String(err));
|
||||
DBG("RTC was not actively running, starting now. Err: " + String(err));
|
||||
rtc.SetIsRunning(true);
|
||||
validRtcFlag = false;
|
||||
}
|
||||
@ -86,7 +86,7 @@ void begin_rtc() {
|
||||
|
||||
if(validRtcFlag) {
|
||||
// Set date and time on the system
|
||||
DBGF("Using Date and Time from RTC.");
|
||||
DBG("Using Date and Time from RTC.");
|
||||
setTime(rtc.GetDateTime().Unix32Time());
|
||||
printTime();
|
||||
}
|
||||
@ -101,7 +101,7 @@ void begin_rtc() {
|
||||
bool validTime() {
|
||||
if(now < 1672000000 || (millis() - lastNTPFetchSuccess > (24*60*60*1000))) {
|
||||
if(validTimeFlag) {
|
||||
DBGF("Time no longer reliable.");
|
||||
DBG("Time no longer reliable.");
|
||||
validTimeFlag = false;
|
||||
}
|
||||
return false;
|
||||
@ -186,7 +186,7 @@ void checkDST() {
|
||||
dstEnd.tm_mday = dstEnd.tm_mday + ((7 - dstEnd.tm_wday) % 7);
|
||||
// mktime(&dstEnd); // recalculate tm_dow
|
||||
// strftime(buf, sizeof(buf), "%c", &dstEnd);
|
||||
// DBGFST("DST Ends: " + String(buf) + " local");
|
||||
// DBG("DST Ends: " + String(buf) + " local");
|
||||
time_t tdstEnd = mktime(&dstEnd);
|
||||
if(tdstEnd != -1 && (time(NULL) - tdstEnd >= 0) && isDST == true) { // DST -> STD
|
||||
dstFlag = 0;
|
||||
@ -214,7 +214,7 @@ void checkDST() {
|
||||
dstEnd.tm_mday = dstEnd.tm_mday + ((7 - dstEnd.tm_wday) % 7);
|
||||
// mktime(&dstEnd); // recalculate tm_dow
|
||||
// strftime(buf, sizeof(buf), "%c", &dstEnd);
|
||||
// DBGFST("DST Ends: " + String(buf) + " local");
|
||||
// DBG("DST Ends: " + String(buf) + " local");
|
||||
time_t tdstEnd = mktime(&dstEnd) - dstOffset;
|
||||
if(tdstEnd != -1 && (time(NULL) - tdstEnd >= 0) && isDST == true) { // DST -> STD
|
||||
dstFlag = 0;
|
||||
@ -237,14 +237,14 @@ void checkDST() {
|
||||
}
|
||||
if(dstFlag == 1) {
|
||||
isDST = true;
|
||||
DBGF("Time change from STD -> DST");
|
||||
DBG("Time change from STD -> DST");
|
||||
}
|
||||
else if(dstFlag == 0) {
|
||||
isDST = false;
|
||||
// Since we are potentially moving back an hour we need to prevent flip flopping back and forth
|
||||
// 2AM -> 1AM, wait 70 minutes -> 2:10AM then start DST checks again.
|
||||
lastDstCheck += ((65-timeinfo.tm_min) * 60); // skip checks until after beginning of next hour
|
||||
DBGF("Time change from DST -> STD");
|
||||
DBG("Time change from DST -> STD");
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -253,7 +253,7 @@ void checkDST() {
|
||||
// Periodically send time to ESP-NOW or LoRa nodes associated with this gateway/controller
|
||||
void sendTime() {
|
||||
if(validTime()) { // Only send time if it is valid
|
||||
DBGF("Sending out time");
|
||||
DBG("Sending out time");
|
||||
// Only send via Serial interface if WiFi is enabled to prevent loops
|
||||
#if defined(USE_WIFI) || defined (USE_RTC_DS3231) || defined(USE_RTC_DS1307) // do not remove this line
|
||||
sendTimeSerial();
|
||||
@ -270,7 +270,7 @@ bool setTime(time_t currentTime) {
|
||||
if(currentTime != 0) {
|
||||
now = currentTime;
|
||||
slewSecs = now - previousTime;
|
||||
DBGF("Time adjust " + String(slewSecs) + " secs");
|
||||
DBG("Time adjust " + String(slewSecs) + " secs");
|
||||
}
|
||||
|
||||
// time(&now);
|
||||
@ -337,6 +337,6 @@ void adjTimeforNetDelay(time_t newOffset) {
|
||||
if(newOffset < UINT32_MAX && validTimeFlag) {
|
||||
now = now + newOffset - previousOffset;
|
||||
previousOffset = newOffset;
|
||||
DBGF("Time adj by " + String(newOffset) + " secs");
|
||||
DBG("Time adj by " + String(newOffset) + " secs");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user