Improved message receiving
This commit is contained in:
parent
c11960321f
commit
eaa6374e25
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue