pipesg,
After looking closer at your code, I think I see a potential issue.
If you look at this code fragment:
Serial.print("AT+QPOWD=1\r\n");
while (timeout > millis()){
if (Serial.find("NORMAL POWER DOWN")){
nss.println ("Module AT off");
break;
}
This has a different behavior on softserial vs HardwareSerial particularly with Arduino 1.x and beyond.
With a softserial library, when Serial.print() returns, ALL of the characters, (every single bit) will have been sent
out the TX line. With HardwareSerial NONE of the characters will have been fully sent out the
TX line. They have been buffered up and the 'A' will still be in the process of transmitting.
Serial.find() will now start looking for characters. In the case of HardwareSerial, the receiving device
will not even see the AT string for another 10-12 ms much less have responded to anything.
I also think the while timeout loop you are using may not be doing what you think.
While it will provide a timeout, it won't give you a 3 second timeout to find the string.
The while loop will abort if it sees 3 seconds has passed, but that is after the call to Serial.find()
which has its own inter character timeout to search for the target string.
The issue with calling Serial.find() in a loop is that as it looks for the string it is swallowing
each character and throwing it away.
Depending on timing, it may be possible that you never see the target string
even though you call Serial.find() in a loop.
Without knowing the response timing of the target device or seeing the AltSoftSerial code
it is hard to say exactly what is happening or if this is even an issue.
(Maybe AltSoftSerial.read() waits forever for received characters vs buffering them in the background?)
You could bump the stream timeout and eliminate the while/timeout loop you have.
For example:
Serial.print("AT+QPOWD=1\r\n");
Serial.setTimeout(3000); // max delay for each character
if (Serial.find("NORMAL POWER DOWN")){
nss.println ("Module AT off");
}
Do you have a link for AltSoftSerial?
And what version of the IDE are you using?
--- bill