یعنی با کامند می تونید زنگ بزنید؟
ببینید تو کنسول سریال کنار جایی که baude rateرو انتخاب می کنید به لیست کشویی دیگه هم هست
اون روی آیتم آخر بزارید ببینید چی میشه
یعنی با کامند می تونید زنگ بزنید؟
ببینید تو کنسول سریال کنار جایی که baude rateرو انتخاب می کنید به لیست کشویی دیگه هم هست
اون روی آیتم آخر بزارید ببینید چی میشه
ویرایش توسط sinanisco@yahoo.com : 12-11-2015 در ساعت 04:00 PM
سلام من این برنامه رو استفاده کردم و نتیجه هم گرفتم.
باهاش میتونید یک LED رو کنترل کنید. اگه LED ON رو بهش SMS کنید LED روشن میشه و اگه LED OFF رو ارسال کنید LED خاموش میشه:
[RIGHT][LEFT]#include <gprs.h>
#include <softwareserial.h>
#define TIMEOUT 5000
#define LED_PIN 13
bool ledStatus;
GPRS gprs;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
while (!Serial);
Serial.println("Starting SIM800 SMS Command Processor");
gprs.preInit();
delay(1000);
while (0 != gprs.init()) {
delay(1000);
Serial.print("init error\r\n");
}
//Set SMS mode to ASCII
if (0 != gprs.sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", TIMEOUT)) {
ERROR("ERROR:CNMI");
return;
}
//Start listening to New SMS Message Indications
if (0 != gprs.sendCmdAndWaitForResp("AT+CNMI=1,2,0,0,0\r\n" , "OK", TIMEOUT)) {
ERROR("ERROR:CNMI");
return;
}
Serial.println("Init success");
}
//Variable to hold last line of serial output from SIM800
char currentLine[500] = "";
int currentLineIndex = 0;
//Boolean to be set to true if message notificaion was found and next
//line of serial output is the actual SMS message content
bool nextLineIsMessage = false;
void loop() {
//Write current status to LED pin
digitalWrite(LED_PIN, ledStatus);
//If there is serial output from SIM800
if (gprs.serialSIM800.available()) {
char lastCharRead = gprs.serialSIM800.read();
//Read each character from serial output until \r or \n is reached (which denotes end of line)
if (lastCharRead == '\r' || lastCharRead == '\n') {
String lastLine = String(currentLine);
//If last line read +CMT, New SMS Message Indications was received.
//Hence, next line is the message content.
if (lastLine.startsWith("+CMT:")) {
Serial.println(lastLine);
nextLineIsMessage = true;
} else if (lastLine.length() > 0) {
if (nextLineIsMessage) {
lastLine.toUpperCase();
Serial.println(lastLine);
//Read message content and set status according to SMS content
if (lastLine.indexOf("LED ON") >= 0) {
ledStatus = 1;
} else if (lastLine.indexOf("LED OFF") >= 0) {
ledStatus = 0;
nextLineIsMessage = false;
}
}
//Clear char array for next line of read
for ( int i = 0; i < sizeof(currentLine); ++i ) {
currentLine[i] = (char)0;
}
currentLineIndex = 0;
} else {
currentLine[currentLineIndex++] = lastCharRead;
}
}
}
آدرس کتابخونه اش هم :
https://github.com/Seeed-Studio/Seeeduino_GPRS
اگه مشکلی داشتید با ID زیر تماس بگیرید:
https://telegram.me/ArduinoKaraneJavan
موفق باشید.
کد:#include <gprs.h> #include <softwareserial.h> #define TIMEOUT 5000 #define LED_PIN 13 bool ledStatus; GPRS gprs; void setup() { Serial.begin(9600); pinMode(LED_PIN, OUTPUT); while (!Serial); Serial.println("Starting SIM800 SMS Command Processor"); gprs.preInit(); delay(1000); while (0 != gprs.init()) { delay(1000); Serial.print("init error\r\n"); } //Set SMS mode to ASCII if (0 != gprs.sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", TIMEOUT)) { ERROR("ERROR:CNMI"); return; } //Start listening to New SMS Message Indications if (0 != gprs.sendCmdAndWaitForResp("AT+CNMI=1,2,0,0,0\r\n", "OK", TIMEOUT)) { ERROR("ERROR:CNMI"); return; } Serial.println("Init success"); } //Variable to hold last line of serial output from SIM800 char currentLine[500] = ""; int currentLineIndex = 0; //Boolean to be set to true if message notificaion was found and next //line of serial output is the actual SMS message content bool nextLineIsMessage = false; void loop() { //Write current status to LED pin digitalWrite(LED_PIN, ledStatus); //If there is serial output from SIM800 if (gprs.serialSIM800.available()) { char lastCharRead = gprs.serialSIM800.read(); //Read each character from serial output until \r or \n is reached (which denotes end of line) if (lastCharRead == '\r' || lastCharRead == '\n') { String lastLine = String(currentLine); //If last line read +CMT, New SMS Message Indications was received. //Hence, next line is the message content. if (lastLine.startsWith("+CMT:")) { Serial.println(lastLine); nextLineIsMessage = true; } else if (lastLine.length() > 0) { if (nextLineIsMessage) { lastLine.toUpperCase(); Serial.println(lastLine); //Read message content and set status according to SMS content if (lastLine.indexOf("LED ON") >= 0) { ledStatus = 1; } else if (lastLine.indexOf("LED OFF") >= 0) { ledStatus = 0; } nextLineIsMessage = false; } } //Clear char array for next line of read for ( int i = 0; i < sizeof(currentLine); ++i ) { currentLine[i] = (char)0; } currentLineIndex = 0; } else { currentLine[currentLineIndex++] = lastCharRead; } } }
برای مثال بالا که یک LED رو با دریافت SMS کنترل میکنه از کتابخونه https://github.com/Seeed-Studio/Seeeduino_GPRS استفاده شده است و اگر سوالی داشتید به ID من در تلگرام ارسال کنید: https://telegram.me/ArduinoKaraneJavan