我试图在声级阈值激活时使用Arduino UNO和SIM800L GSM模块发送SMS消息。除了一方面,我已经能够完成这一切。我有发送短信的电话号码存储在SD卡上的CONFIG.BAT文件中,我需要解决的问题是如何将SD卡中的号码添加到指定电话的AT命令中短信发送到的号码。我目前使用的代码如下:将存储在SD卡上的电话号码插入短信发送AT命令Arduino
以下代码位于选择启动设备时调用的函数中,该过程从读取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!");
}
}
我需要我如何得到这是在“MYFILE”变量在该位的代码举行的SD卡中的电话号码,帮助或建议
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");
但这并没有奏效。
任何帮助将非常感激
我已经试过这个,并得到错误没有匹配函数调用''SoftwareSerial :: write(StringSumHelper&)''在代码行'serialSIM800.write(“AT + CMGS = \”+ 44“+ number + “\”\ r \ n“);' – Tiny
如果您对号码进行硬编码,您可以发送一些内容?我的意思是,如果你考虑读取文件的一部分并在代码中写入AT命令。我写这个答案,期望你做了一些单一的测试。 – jabujavi
我有一个硬编码的电话号码,当超过门槛时,短信被发送,你提供的代码我可以看到数字用char表示(每个数字都用ASCII代码表示,尽管从我可以告诉的是,在电话号码的一部分代码的末尾添加),所以通过使用'Serial.println(number);'我可以看到ascii号码。我一直在想如何编写AT代码,以便读取ascii代码并自动将其作为电话号码读取,但我还没有能够理解或识别该过程。 – Tiny