کتابخانه gsm برای ardunio
برنامه دریافت sms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
/* SMS receiver */ // include the GSM library #include <GSM.h> // PIN Number for the SIM #define PINNUMBER "" // initialize the library instances GSM gsmAccess; GSM_SMS sms; // Array to hold the number a SMS is retreived from char senderNumber[20]; void setup() { // initialize serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.println("SMS Messages Receiver"); // connection state boolean notConnected = true; // Start GSM connection while(notConnected) { if(gsmAccess.begin(PINNUMBER)==GSM_READY) notConnected = false; else { Serial.println("Not connected"); delay(1000); } } Serial.println("GSM initialized"); Serial.println("Waiting for messages"); } void loop() { char c; // If there are any SMSs available() if (sms.available()) { Serial.println("Message received from:"); // Get remote number sms.remoteNumber(senderNumber, 20); Serial.println(senderNumber); // An example of message disposal // Any messages starting with # should be discarded if(sms.peek()=='#') { Serial.println("Discarded SMS"); sms.flush(); } // Read message bytes and print them while(c=sms.read()) Serial.print(c); Serial.println("\nEND OF MESSAGE"); // Delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); } delay(1000); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include "SIM900.h" #include <SoftwareSerial.h> #include "sms.h" SMSGSM sms; boolean started=false; void setup() { //Serial connection. Serial.begin(9600); Serial.println("GSM Shield testing."); if (gsm.begin(2400)){ Serial.println("\nstatus=READY"); started=true; } else Serial.println("\nstatus=IDLE"); if(started){ if (sms.SendSMS("number", "SMS from Arduino")) Serial.println("\nSMS sent OK"); } }; void loop() { } |