How can I let Arduino GSM shield respond only to authorized numbers? -
i working on project send '1' arduino gsm shield switch on led connected pin 13 , switch off sending '0', modify code in order gsm shield respond number specified. here code, in case used example phone number. when send message adminnumber led not switch on nor off.
// include gsm library #include <gsm.h> // pin number sim #define pinnumber "" // initialize library instances gsm gsmaccess; gsm_sms sms; // array hold number sms retreived char sendernumber[20]; char adminnumber[20]="+123456789234"; void setup() { // initialize digital pin 13 output. pinmode(13, output); // initialize serial communications , wait port open: serial.begin(9600); while (!serial) { ; // wait serial port connect. needed leonardo } 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 messages"); } void loop() { char c; sms.remotenumber(sendernumber, 20); sms.remotenumber(adminnumber, 20); // if there smss available() if (sms.available()) { serial.println("message received from:"); // remote number sms.remotenumber(sendernumber, 20); serial.println(sendernumber); // number besides admin number not change state of pin while(adminnumber == sendernumber){ // messages starting 1 set pin 13 high if (sms.peek() == '1'){ digitalwrite(13, high); sms.flush(); } // messages starting 0 set pin 13 low else if(sms.peek() == '0'){ digitalwrite(13, low); sms.flush() } } // read message bytes , print them while (c = sms.read()) serial.print(c); serial.println("\nend of message"); // delete message modem memory sms.flush(); serial.println("message deleted"); } delay(1000); }
array comparison can donne kurz7 https://cboard.cprogramming.com/c-programming/41972-how-do-i-compare-two-arrays.html
// include gsm library #include <gsm.h> #include <string.h> // pin number sim #define pinnumber "xxxx" // initialize library instances gsm gsmaccess; gsm_sms sms; // array hold number sms retreived char sendernumber[20]; char adminnumber[20]="+xxxxxxxxxxx"; void setup() { // initialize digital pin 13 output. pinmode(13, output); // initialize serial communications , wait port open: serial.begin(9600); 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 messages"); } void loop() { char c; // if there smss available() if (sms.available()) { serial.println("message received from:"); sms.remotenumber(sendernumber,20); // remote number serial.println(sendernumber); // number besides admin number not change state of pin if (strcmp( adminnumber, sendernumber ) == 0 ) { // messages starting 1 set pin 13 high if (sms.peek() == '1') {digitalwrite(13, high); } // messages starting 0 set pin 13 low else if(sms.peek() == '0') {digitalwrite(13, low); } // read message bytes , print them while (c = sms.read()) serial.print(c); serial.println("\nend of message"); // delete message modem memory sms.flush(); serial.println("message deleted"); } delay(1000); }}
Comments
Post a Comment