该库应该可以处理几乎所有带有M10模块的东西。
我只有SIM900模块的经验。在eBay上找到最便宜的一个。
虽然与这些东西的接口起初可能是一个挑战,但实际上您只需要阅读所有AT命令的手册并执行它们即可。我编写了一些可能会有所帮助的函数:
注意:您可以安全地替换的所有实例DEBUG_PRINT
,并DEBUG_PRINTLN
与Serial.print
和Serial.println
。
SoftwareSerial SIM900(7, 8);
/*
Sends AT commands to SIM900 module.
Parameter Description
command String containing the AT command to send to the module
timeout A timeout, in milliseconds, to wait for the response
Returns a string containing the response. Returns NULL on timeout.
*/
String SIMCommunication::sendCommand(String command, int timeout) {
SIM900.listen();
// Clear read buffer before sending new command
while(SIM900.available()) { SIM900.read(); }
SIM900.println(command);
if (responseTimedOut(timeout)) {
DEBUG_PRINT(F("sendCommand Timed Out: "));DEBUG_PRINTLN(command);
return NULL;
}
String response = "";
while(SIM900.available()) {
response.concat((char)SIM900.read());
delayMicroseconds(500);
}
return response;
}
/*
Waits for a response from SIM900 for <ms> milliseconds
Returns true if timed out without response. False otherwise.
*/
bool SIMCommunication::responseTimedOut(int ms) {
SIM900.listen();
int counter = 0;
while(!SIM900.available() && counter < ms) {
counter++;
delay(1);
}
// Timed out, return null
if (counter >= ms) {
return true;
}
counter = 0;
return false;
}