From eaa6374e25e423676048af167ab2f2b202919df5 Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Tue, 13 Dec 2022 19:15:17 +0100 Subject: [PATCH] Improved message receiving --- client/client.ino | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/client/client.ino b/client/client.ino index 92997f9..2022f85 100644 --- a/client/client.ino +++ b/client/client.ino @@ -162,8 +162,8 @@ String decodeMsg(String hexEncoded) { } } -void receiveMsg() { - String recvMsg = LoRaWAN.waitMsg(100); +void receiveMsg(int wait) { + String recvMsg = LoRaWAN.waitMsg(wait); recvMsg.trim(); if(recvMsg.length() != 0 && recvMsg.substring(0, 8) == "OK+RECV:") { String decodedMsg = decodeMsg(split(recvMsg, ',', 3)); @@ -172,7 +172,7 @@ void receiveMsg() { clearDepartures(); } else if(decodedMsg.substring(0,5) == "TIME|") { - unixtime = (decodedMsg.substring(5,30).toInt()) - last_update*6; + unixtime = (decodedMsg.substring(5,30).toInt()) - seconds; } else { addDeparture(decodedMsg); } @@ -193,12 +193,13 @@ String displayedDate; // Display functions -void displayTimeDate(int lines) { +void displayTimeDate() { char date[20]; char time[20]; - unsigned long timestamp = unixtime + last_update*6; + unsigned long timestamp = unixtime + seconds; unixToDate(timestamp, date); unixToTime(timestamp, time); + int lines = 7; if(displayedDate != date) { displayedDate = date; M5.Lcd.setTextDatum(TL_DATUM); @@ -256,8 +257,9 @@ void displayDeparture(struct departure d, int y) { } -void displayDepartures(int lines) { +void displayDepartures() { String displayed[50]; + int lines = 7; int displayedIndex = 0; for(int i=0; i < departureIndex; i++) { if(departures[i].departure < -3) removeDeparture(i); @@ -334,26 +336,23 @@ void addDeparture(String s) { - // Main loop with time counting void loop() { seconds = time(NULL); if(seconds / 6 > last_update) { last_update++; - int lines = 7; sortDepartures(); - displayDepartures(lines); - displayTimeDate(lines); + displayDepartures(); + displayTimeDate(); } - delay(500); + delay(900); } // Additional task for receiving LoRaWAN messages void task1(void* pvParameters) { while(true) { - receiveMsg(); - delay(1); + receiveMsg(1); } -} +} \ No newline at end of file