我正在尝试通过 sim800 gsm 模块将传感器数据推送到 aws 云数据库。
我可以通过串行监视器手动输入 at 命令来做到这一点,但是当我将 at 命令合并到代码中以自动执行该过程时,我不必手动输入命令,我得到了 cme 错误 3。
请指导如何解决或识别问题。
代码
#include <Arduino.h> //Arduino librabry...optional
#include <SPI.h>//SPI communication library
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>//library with GSM commands
HardwareSerial SerialGSM(1);
TinyGsm modemGSM(SerialGSM);
const int BAUD_RATE = 115200;
//Pin definition for RX and TX GPIO2 and GPIO4 are the pins in ESP32 Wroom
const int RX_PIN = 4, TX_PIN = 2;
//const char *APN = "";
//const char *USER = "";
//const char *PASSWORD = "";
//Initialize the gsm
void setupGSM() {
SerialGSM.begin(BAUD_RATE, SERIAL_8N1, RX_PIN, TX_PIN, false);
delay(3000);
Serial.println(modemGSM.getModemInfo());
delay(1000);
}
String sendAT(String command)
{
String response = "";
SerialGSM.println(command);
// aguardamos até que haja resposta do SIM800L
while(!SerialGSM.available());
response = SerialGSM.readString();
Serial.println(response);
return response;
}
void setup() {
Serial.begin(BAUD_RATE);
Serial.println("Starting the device");
Serial.println("Initializing GSM device");
setupGSM();
delay(5000);
SerialGSM.println("AT+CMEE=1");
}
unsigned long start;
void loop() {
//SerialGSM.println("AT+CMEE?");
sendAT("AT+CMEE?");
// SerialGSM.write("AT+COPS?\r\n");
delay(100);
//SerialGSM.println("AT+CSQ");
sendAT("AT+CSQ");
// if(SerialGSM.available()){
// Serial.write(SerialGSM.read());
// }
delay(100);
// SerialGSM.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
sendAT("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(1000);
// SerialGSM.println("AT+SAPBR=3,1,\"APN\",\"www\"");
sendAT("AT+SAPBR=3,1,\"APN\",\"www\"");
delay(1000);
//SerialGSM.println("AT+SAPBR=1,1");
sendAT("AT+SAPBR=1,1");
delay(2000);
//SerialGSM.println("AT+HTTPINIT");
sendAT("AT+HTTPINIT");
delay(1000);
//SerialGSM.println("AT+HTTPPARA=\"CID\",1");
sendAT("AT+HTTPPARA=\"CID\",1");
delay(1000);
//SerialGSM.println("AT+HTTPPARA=\"URL\",\"http://ec2-18-217-119-145.us-east-2.compute.amazonaws.com:8000/?light=0&var=1&var2=2&var3=3&var4=4\"");
sendAT("AT+HTTPPARA=\"URL\",\"http://ec2-18-217-119-145.us-east-2.compute.amazonaws.com:8000/?light=0&var=1&var2=2&var3=3&var4=4\"");
delay(1000);
//SerialGSM.println("AT+HTTPACTION=0");
sendAT("AT+HTTPACTION=0");
delay(2000);
//start=millis();
//
// while(millis()-start<1000)
// {
// if(SerialGSM.available()){
// Serial.write(SerialGSM.read());
// }
// }
}