자유게시판

  • 제   목 serial
  • 작성자 관리자 등록일 2025-07-28/15:42 조회수 1
#include <HardwareSerial.h>


//HardwareSerial SIM7670Serial(16, 17); // RX, TX
#define SIM7670Serial Serial2


void setup() {
Serial.begin(115200);
SIM7670Serial.begin(115200);



}

void loop() {
sendCMD();
delay(2000);
}


void sendCMD() {
String res="";
res= sendATCommand("AT\n" , "OK", 1000);
Serial.println(res);
res= sendATCommand("AT+CGSN=1\n", "OK", 1000);
Serial.println(res);
res= sendATCommand("AT%XICCID\n", "OK", 1000);
Serial.println(res);
res= sendATCommand("AT+CFUN?\n", "OK", 1000);
Serial.println(res);




}

String sendATCommand(String cmd, String expectedResponse, int timeout) {
SIM7670Serial.print(cmd);
Serial.println(cmd);
String response = "";
long timeStart = millis();
while (millis() - timeStart < timeout) {
while (SIM7670Serial.available() > 0) {
char c = SIM7670Serial.read();
response += c;
}
if (response.indexOf(expectedResponse) != -1)
break;
else expectedResponse="";
}




// Serial.println(response);
return expectedResponse;
}
타인의 명예를 훼손 또는 비방, 개인정보 유출 및 광고성 게시물을 삼가해 주세요.
이전글 ▲ :
이전글이 없습니다.
다음글 ▼ :
visual studio