Improved message receiving
This commit is contained in:
parent
c11960321f
commit
eaa6374e25
|
@ -162,8 +162,8 @@ String decodeMsg(String hexEncoded) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void receiveMsg() {
|
void receiveMsg(int wait) {
|
||||||
String recvMsg = LoRaWAN.waitMsg(100);
|
String recvMsg = LoRaWAN.waitMsg(wait);
|
||||||
recvMsg.trim();
|
recvMsg.trim();
|
||||||
if(recvMsg.length() != 0 && recvMsg.substring(0, 8) == "OK+RECV:") {
|
if(recvMsg.length() != 0 && recvMsg.substring(0, 8) == "OK+RECV:") {
|
||||||
String decodedMsg = decodeMsg(split(recvMsg, ',', 3));
|
String decodedMsg = decodeMsg(split(recvMsg, ',', 3));
|
||||||
|
@ -172,7 +172,7 @@ void receiveMsg() {
|
||||||
clearDepartures();
|
clearDepartures();
|
||||||
} else
|
} else
|
||||||
if(decodedMsg.substring(0,5) == "TIME|") {
|
if(decodedMsg.substring(0,5) == "TIME|") {
|
||||||
unixtime = (decodedMsg.substring(5,30).toInt()) - last_update*6;
|
unixtime = (decodedMsg.substring(5,30).toInt()) - seconds;
|
||||||
} else {
|
} else {
|
||||||
addDeparture(decodedMsg);
|
addDeparture(decodedMsg);
|
||||||
}
|
}
|
||||||
|
@ -193,12 +193,13 @@ String displayedDate;
|
||||||
|
|
||||||
// Display functions
|
// Display functions
|
||||||
|
|
||||||
void displayTimeDate(int lines) {
|
void displayTimeDate() {
|
||||||
char date[20];
|
char date[20];
|
||||||
char time[20];
|
char time[20];
|
||||||
unsigned long timestamp = unixtime + last_update*6;
|
unsigned long timestamp = unixtime + seconds;
|
||||||
unixToDate(timestamp, date);
|
unixToDate(timestamp, date);
|
||||||
unixToTime(timestamp, time);
|
unixToTime(timestamp, time);
|
||||||
|
int lines = 7;
|
||||||
if(displayedDate != date) {
|
if(displayedDate != date) {
|
||||||
displayedDate = date;
|
displayedDate = date;
|
||||||
M5.Lcd.setTextDatum(TL_DATUM);
|
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];
|
String displayed[50];
|
||||||
|
int lines = 7;
|
||||||
int displayedIndex = 0;
|
int displayedIndex = 0;
|
||||||
for(int i=0; i < departureIndex; i++) {
|
for(int i=0; i < departureIndex; i++) {
|
||||||
if(departures[i].departure < -3) removeDeparture(i);
|
if(departures[i].departure < -3) removeDeparture(i);
|
||||||
|
@ -334,26 +336,23 @@ void addDeparture(String s) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Main loop with time counting
|
// Main loop with time counting
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
seconds = time(NULL);
|
seconds = time(NULL);
|
||||||
if(seconds / 6 > last_update) {
|
if(seconds / 6 > last_update) {
|
||||||
last_update++;
|
last_update++;
|
||||||
int lines = 7;
|
|
||||||
sortDepartures();
|
sortDepartures();
|
||||||
displayDepartures(lines);
|
displayDepartures();
|
||||||
displayTimeDate(lines);
|
displayTimeDate();
|
||||||
}
|
}
|
||||||
delay(500);
|
delay(900);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional task for receiving LoRaWAN messages
|
// Additional task for receiving LoRaWAN messages
|
||||||
|
|
||||||
void task1(void* pvParameters) {
|
void task1(void* pvParameters) {
|
||||||
while(true) {
|
while(true) {
|
||||||
receiveMsg();
|
receiveMsg(1);
|
||||||
delay(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue