I'm using a Mega with an mDot Lora radio. When I send commands and requests to the mDot, the data is displayed in random order. Network Join is the last command in Setup, but all of the other Setup commands are displayed AFTER the Join and after the Loop has started. Any ideas?
Mega code
String response="";
String joinResponse="";
String message1="AT+SEND=Test Arduino";
String message2="AT+SEND=2.35 mgd";
void setup(){
Serial.begin(115200);
Serial1.begin(115200);
Serial.println("Begin setup");
Serial1.println("AT+NJM=1");
Serial1.flush();
Serial1.println("AT+FSB=1"); //Sub band=1
Serial1.flush();
Serial1.println("AT+TXDR=DR2");
Serial1.flush();
Serial1.println("AT+NI=0,AABBCCDDEEFF0011");
Serial1.flush();
Serial1.println("AT+NK=0,00112233445566778899AABBCCDDEEFF");
Serial1.println("AT+NK=1,MTCDT-19544846");
Serial1.flush();
Serial1.println("AT+JD=5"); //Join delay=5 for private LoRaWAN
Serial1.flush();
Serial.println("\n\nJoin network");
Serial1.println("AT+JOIN");
Serial1.flush();
delay(15000);
}
void loop(){
Serial.println("Start loop");
Serial.println("Network Joined?");
Serial1.println("AT+NJS?");
Serial1.flush();
delay(1000);
while (Serial1.available()){
joinResponse=Serial1.readString();
delay(5000);
Serial.print("Join Response: ");
Serial.println(joinResponse);
Serial.flush();
joinResponse="";
}
delay(1000);
Serial1.println("AT+RSSI");
Serial1.flush();
delay(5000);
while (Serial1.available()){
response=Serial1.readString();
Serial.flush();
delay(5000);
Serial.print("RSSI Response: ");
Serial.println(response);
response="";
}
Serial.println("\n\nSend messages");
Serial1.println(message1);
Serial1.flush();
Serial1.println(message2);
Serial1.flush();
Serial.println("End Loop");
delay(60000);
}
------------------------------------------------------------------------------------------------------------
Serial Monitor output
Begin setup
Join network
Start loop
Network Joined?
Join Response: AT+NJM=1
OK
AT+FSB=1
OK
AT
Send messages
End Loop
Start loop
Network Joined?
Join Response: AT+SEND=Test Arduino
Network not joined
ERROR
AT+SEND=
Send messages
End Loop
[\Code]