문자열 (특히 PC에서 입력 한 11 자리 숫자의 휴대폰 번호)이 arduino로 보내질 예정입니다. 나는 문자열을 입력하고 직렬 버퍼에 인쇄하는데 아무런 문제가 없다. 혼란 스럽다는 것은 arduino가 방금 입력 한 핸드폰 번호를 정확하게 읽은 것인가? 또한 arduino가 이미 문자열을 읽었다 고 가정 해 봅시다. arduino 코드에 문자열을 올바르게 삽입하고 모든 것을 처리하여 SMS를 보낼 수있는 방법을 가정 해 봅시다. GSMSMS 코드 만 사용하여 SMS를 보낼 수있었습니다. 수동으로 특정 핸드폰 번호를 입력하여 작업을 수행 할 수있었습니다. 하지만 아래의 첫 번째 arduino 코드에서 오류가 발생했습니다. 내가 뭔가 놓친거야? 나는 약간의 제안과 암시가 절실히 필요하다. 미리 감사드립니다! + CMGS = "S"PC에서 arduino로 문자열 보내기
귀하의 샘플을 성공
char text[11];
int bufferIndex = 0;
char Rx_data[50];
unsigned char Rx_index = 0;
int i = 0;
char msg[160];
int sig;
void setup(){
Serial.begin(38400);
initGSM();
loop_Serial();
send_msg(text, "Your sample has been tested. You may now get your result. Thank you.");
}
void loop_Serial()
{
if(Serial.available())
{
char ch = (char)Serial.read();
if(ch == '\n') // is this the terminating carriage return
{
text[ bufferIndex ] = 0; // terminate the string with a 0
bufferIndex = 0; // reset the index ready for another string
// do something with the string
Serial.println(text);
}
else
text[ bufferIndex++ ] = ch; // add the character into the buffer
}
}
void loop() {
//none
}
void send_msg(char *number, char *msg)
{
char at_cmgs_cmd[30] = {'\0'};
char msg1[160] = {'\0'};
char ctl_z = 0x1A;
sprintf(msg1, "%s%c", msg, ctl_z);
sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
sendGSM(at_cmgs_cmd);
delay(100);
delay(100);
delay(100);
sendGSM(msg1);
delay(100);
}
void sendGSM(char *string){
Serial.write(string);
delay(90);
}
void clearString(char *strArray) {
int j;
for (j = 100; j > 0; j--)
strArray[j] = 0x00;
}
void send_cmd(char *at_cmd, char clr){
char *stat = '\0';
while(!stat){
sendGSM(at_cmd);
delay(90);
readSerialString(Rx_data);
stat = strstr(Rx_data, "OK");
}
if (clr){
clearString(Rx_data);
delay(200);
stat = '\0';
}
}
void initGSM(){
send_cmd("AT\r\n",1);
// send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module
send_cmd("AT+CMGF=1\r\n",1); // Set message format to text mode
//Sucess
Serial.println("Success");
delay(1000);
delay(1000);
delay(1000);
}
void readSerialString (char *strArray) {
if(!Serial.available()) {
return;
}
while(Serial.available()) {
strArray[i] = Serial.read();
i++;
}
}
AT + CMGF AT = 1
: :))) 여기 내 아두 이노 코드입니다 테스트를 마쳤습니다. 이제 결과를 얻을 수 있습니다. 고맙습니다.
"S"는 어디에서 왔습니까? 그리고 입력 한 문자열은 어디에 있습니까?
안녕하세요, 코드를 업데이트했습니다. 친절하게 위의 확인하십시오 .. 지금 나는 "S"를 어디서 왔는지 모른다. : – Van
당신은 아직 11 문자 모두를 기다리지 않고 ++도 옮겨야 만합니다. – Lesto
loop_Serial 부분은 11 문자에 도달 할 때까지 반복되고 반복됩니다. m so confused : ((((((((((( – Van