Buenas,
soy nuevo en arduino y estaba intentando realizar un modem para Cat-NB1 que realizase mediciones y devolviese el nivel de señal RSSI en cada instante. Para realizarlo, debo implementar un sketch que se comunique con el shield mediente comandos AT. Tengo un problema y es que lo que estoy viendo en el monitor serie no tiene ningún sentido. El programa tan solo es capaz de responderme un solo comando AT, y muchas veces son símbolos y letras sin sentido.
He estado investigando y el principal problema apuntaba a ser algún problema con el 'baud rate'. He probado de todo y parece que no tiene mucho que ver con ello.
Estoy usando una Arduino UNO junto al QUECTEL BG96 de Dragino y conectándolo a través del COM3. El código lo presento a continuación:
#include <SoftwareSerial.h>
#include <ATcommands.h>
#define RST 4 // Reset PIN module
#define UART_RX 10 // Serial PIN RX connection
#define UART_TX 11 // Serial PIN TX connection
SoftwareSerial mySerial(UART_RX, UART_TX);
//ATcommands module = ATcommands(RST,false);
String IP = "IP";
String APN = "m2m.movistar.es";
void setup() {
Serial.begin(9600);
mySerial.begin(115200);
//module.begin(mySerial);
while (!Serial) {}
Serial.println("Welcome to use NB-IoT Shield QG96");
ATresponse("ATI", 1000);
ATresponse("AT+GSN", 1000);
ATresponse("AT+CFUN=1", 1000);
ATresponse("AT+QCCID", 1000);
ATresponse("AT+COPS=0", 1000);
ATresponse("AT+CSQ", 1000);
ATresponse("AT+COPS?", 1000);
ATresponse("AT+CGDCONT=1,IP,APN,,0,0", 1000);
ATresponse("AT+CGATT=1", 1000);
ATresponse("AT+CGDCONT?", 1000);
ATresponse("AT+CGACT=1,1", 1000);
ATresponse("AT+CGPADDR=1", 1000);
}
void loop() {
//Nothing here
}
void ATresponse(String AT, int wait){
// The function extract the AT command response and specified
// a delay between different commands
mySerial.flush();
delay(wait);
mySerial.println(AT+"\r\n");
updateSerial();
char ATresponse[200];
for(int i = 0 ; i < 200 && mySerial.available()>0 ; i++){
ATresponse[i++] = mySerial.read();
}
Serial.println(ATresponse);
}
void updateSerial(){
while (mySerial.available()) {
Serial.write(mySerial.read()); //Forward what Serial received to Software Serial Port
}
while (Serial.available()) {
mySerial.write(Serial.read()); //Forward what Software Serial received to Serial Port
}
}