Sorry, here are the code:
#include <AltSoftSerial.h>
#define NETWORK_SEARCH_DELAY 10000
#define POWER_ON_OFF_DELAY 15000
#define FTP_DELAY 10000
#define REPLY_TIMEOUT 3000
#define ON_OFF 2
#define STATUSPIN 3
boolean STATUS;
AltSoftSerial nss;
void setup (){
nss.begin (9600);
byte success;
delay (5000);
nss.println ("vamos");
delay(5000);
nss.println ("on push");
if (powerOn ()){
nss.println ("power on");
success = 0;
unsigned long timeout;
timeout = millis() + POWER_ON_OFF_DELAY;
Serial.flush();
while (timeout > millis()){
if (Serial.find("Call Ready")){
success = 1;
nss.println ("Module ready");
break;
}
else {
nss.println ("No call ready found");
}
}
}
if (success == 1) {
nss.println ("success =1");
timeout = millis() + REPLY_TIMEOUT;
Serial.flush();
Serial.print("AT+QPOWD=1\r\n");
while (timeout > millis()){
if (Serial.find("NORMAL POWER DOWN")){
nss.println ("Module AT off");
break;
}
}
timeout = millis () + POWER_ON_OFF_DELAY;
while (timeout > millis ()){
if (digitalRead (STATUSPIN) == LOW){
success= 0;
nss.println ("Module off");
break;
}
}
}
} // final setup
void loop (){
}
boolean powerOn(){
bool success = false;
pinMode (ON_OFF, OUTPUT);
//set on/off pin
pinMode (STATUSPIN, INPUT); //set status pin
digitalWrite (ON_OFF, LOW); // power on M95
delay (1500); // min high to power on 1000
digitalWrite (ON_OFF, HIGH);
if (digitalRead (STATUSPIN) == HIGH){
success = true;
nss.println ("on a la primera");
}
else{
digitalWrite (ON_OFF, LOW); // power on M95
delay (1500); // min high to power on 1000
digitalWrite (ON_OFF, HIGH);
if (digitalRead (STATUSPIN) == HIGH){
STATUS = true;
success = true;
nss.println ("on a la segunda");
}
}
return (success);
}
When altsoftserial is used to communicate with the gprs (quectel m95 evb kit), I directly attach arduino altsoftserial rx and tx pins with tx and rx pins of the module. An sparkfun ftdi basic is connected to the arduino and the outcome of the serial port is displayed in the serial monitor. With this configuration all goes ok.
When I use the harware serial port to connect with the gprs, hardware serial rx and tx pins are connected to the tx and rx pins of the module and I connect the ftdi rx and tx pins to the tx and rx pins of the arduino altsoftwareSerial and also the positive and negative output of the ftdi to the arduino to power it. And of course I change the Serial instances to nss (altsoftserial) and viceversa. I use serial monitor to see the outcome of the program. In this case the module power on without problems and the serial harware "detects" it because I can see in the serial monitor "Module ready". Afterwards the module do not switch off instead I know the program enters in the ( if (success == 1)).
I'm a newbie in programming. I use the Serial.flush to "clean" the serial buffer,in this programs pehaps it is not neccesary baut in other functions with the gprs module I think is neccesary because different AT commands have the same response ("ok"). I suppose I'm wrong with it use.
Thank you very much!!