gpt4 book ai didi

c++ - 将SD卡上存储的电话号码插入短信发送AT命令Arduino

转载 作者:行者123 更新时间:2023-11-30 17:04:21 25 4
gpt4 key购买 nike

当激活声级阈值时,我尝试使用 Arduino UNO 和 SIM800L GSM 模块发送短信。除了一个方面之外,我在所有方面都能够完成这项工作。我将要发送短信的电话号码存储在 SD 卡上的 CONFIG.BAT 文件中,我需要解决的问题是如何将 SD 卡中的号码添加到指定电话的 AT 命令中短信发送到的号码。到目前为止我的代码如下:

以下代码位于选择启动设备时调用的函数中,该过程从读取 A0 引脚上的输出开始,以识别声音何时超过阈值 int 中设置的级别,然后设置引脚13 到高,然后进程启动 SD 卡,检查卡上是否有 CONFIG.BAT,如果没有 CONFIG.BAT 文件,则告诉用户进行设置并设置警报电话号码。如果 CONFIG.BAT 确实存在,则该过程将继续读取 CONFIG.BAT 文件的内容。下一步是将短信设置为 ASCII 格式,然后设置电话号码,然后设置消息内容。

void sound_detect(){

int sensorValue = analogRead(A0);//use A0 to read the electrical signal

if(sensorValue > thresholdvalue) {

digitalWrite(ledPin1,HIGH);//if the value read from A0 is larger than 400,then light the LED
delay(10);
digitalWrite(ledPin1,LOW);

Serial.print("Initializing SD card...");

pinMode(10, OUTPUT);

if (!SD.begin(SD_CS_PIN)) {
Serial.println("initialization failed!");
return;
}

Serial.println("initialization done.");

if (!SD.exists("CONFIG.DAT")) {

Serial.println("No Number Exists! Please go to Setup Device to add Number for Alert");

}else{

// open the file for reading:
myFile = SD.open("CONFIG.DAT");

if (myFile) {

Serial.println("CONFIG.DAT:");

// read from the file until there's nothing else in it:
while (myFile.available()) {

Serial.write(myFile.read());

}

//Serial.println(myFile);

// close the file:
myFile.close();

} else {

// if the file didn't open, print an error:
Serial.println("error opening CONFIG.DAT");

}

}


//Set SMS format to ASCII
serialSIM800.write("AT+CMGF=1\r\n");
delay(1000);

//Send new SMS command and message number
serialSIM800.write("AT+CMGS=\"+44*************\"\r\n");
delay(1000);

//Send SMS content
serialSIM800.write("TEST SMS NOISE DETECT");
delay(1000);

//Send Ctrl+Z / ESC to denote SMS message is complete
serialSIM800.write((char)26);
delay(1000);

Serial.println("SMS Sent!");


}

}

我需要有关如何从 SD 卡获取电话号码的帮助或建议,该电话号码保存在这段代码的“myFile”变量中

while (myFile.available()) {

Serial.write(myFile.read());

}

在这里替换AT命令中的电话号码

  //Send new SMS command and message number
serialSIM800.write("AT+CMGS=\"+44*************\"\r\n");

我查看了 AT 命令,看看是否有明确的方法可以做到这一点,但没有成功,我尝试将“myFile”变量放在大括号 {myFile} 内

  //Send new SMS command and message number
serialSIM800.write("AT+CMGS=\"{myFile}\"\r\n");

但这没有用。

任何帮助将不胜感激

最佳答案

在loop()中声明一个字符串:

String number ="";

连接从文件中读取的字符:

while (myFile.available()) {

number.concat(myFile.read());

}

将号码连接到 AT-comand:

serialSIM800.write("AT+CMGS=\"+44"+number+"\"\r\n");

这就是想法,但您可以通过多种方式实现它。

关于c++ - 将SD卡上存储的电话号码插入短信发送AT命令Arduino,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35843869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com