├── src ├── GSM.h ├── GSM3ShieldV1.h ├── GSM3SMSService.h ├── GSM3ShieldV1.cpp ├── GSM3SoftSerial.h ├── GSM3SMSService.cpp ├── GSM3SoftSerial.cpp ├── GSM3CircularBuffer.h ├── GSM3CircularBuffer.cpp ├── GSM3MobileSMSProvider.h ├── GSM3VoiceCallService.cpp ├── GSM3VoiceCallService.h ├── GSM3MobileAccessProvider.h ├── GSM3MobileCellManagement.h ├── GSM3MobileClientProvider.h ├── GSM3MobileClientService.h ├── GSM3MobileMockupProvider.h ├── GSM3MobileServerProvider.h ├── GSM3MobileServerService.h ├── GSM3MobileVoiceProvider.h ├── GSM3ShieldV1BaseProvider.h ├── GSM3ShieldV1SMSProvider.h ├── GSM3ShieldV1ScanNetworks.h ├── GSM3MobileClientService.cpp ├── GSM3MobileMockupProvider.cpp ├── GSM3MobileNetworkProvider.cpp ├── GSM3MobileNetworkProvider.h ├── GSM3MobileNetworkRegistry.cpp ├── GSM3MobileNetworkRegistry.h ├── GSM3MobileServerService.cpp ├── GSM3ShieldV1AccessProvider.h ├── GSM3ShieldV1BandManagement.h ├── GSM3ShieldV1CellManagement.h ├── GSM3ShieldV1ClientProvider.h ├── GSM3ShieldV1PinManagement.cpp ├── GSM3ShieldV1PinManagement.h ├── GSM3ShieldV1ScanNetworks.cpp ├── GSM3ShieldV1ServerProvider.h ├── GSM3ShieldV1VoiceProvider.h ├── GSM3MobileDataNetworkProvider.h ├── GSM3ShieldV1ModemVerification.h ├── GSM3ShieldV1DataNetworkProvider.h ├── GSM3ShieldV1DirectModemProvider.h ├── GSM3ShieldV1ModemVerification.cpp ├── GSM3ShieldV1MultiClientProvider.h ├── GSM3ShieldV1MultiServerProvider.h ├── GSM3ShieldV1DirectModemProvider.cpp ├── GSM3MobileCellManagement.cpp ├── GSM3MobileSMSProvider.cpp ├── GSM3MobileVoiceProvider.cpp ├── GSM3MobileAccessProvider.cpp ├── GSM3MobileClientProvider.cpp ├── GSM3MobileDataNetworkProvider.cpp ├── GSM3MobileServerProvider.cpp ├── GSM3ShieldV1BaseProvider.cpp ├── GSM3IO.h ├── GSM3ShieldV1BandManagement.cpp ├── GSM3ShieldV1CellManagement.cpp ├── GSM3ShieldV1ModemCore.cpp ├── GSM3ShieldV1ServerProvider.cpp ├── GSM3ShieldV1VoiceProvider.cpp ├── GSM3ShieldV1ModemCore.h ├── GSM3ShieldV1SMSProvider.cpp ├── GSM3ShieldV1ClientProvider.cpp ├── GSM3ShieldV1AccessProvider.cpp ├── GSM3ShieldV1MultiServerProvider.cpp ├── GSM3ShieldV1DataNetworkProvider.cpp └── GSM3ShieldV1MultiClientProvider.cpp ├── library.properties ├── README.adoc ├── examples ├── Tools │ ├── TestModem │ │ └── TestModem.ino │ ├── TestWebServer │ │ └── TestWebServer.ino │ ├── GsmScanNetworks │ │ └── GsmScanNetworks.ino │ ├── BandManagement │ │ └── BandManagement.ino │ ├── PinManagement │ │ └── PinManagement.ino │ └── TestGPRS │ │ └── TestGPRS.ino ├── ReceiveSMS │ └── ReceiveSMS.ino ├── SendSMS │ └── SendSMS.ino ├── ReceiveVoiceCall │ └── ReceiveVoiceCall.ino ├── GsmWebClient │ └── GsmWebClient.ino ├── MakeVoiceCall │ └── MakeVoiceCall.ino └── GsmWebServer │ └── GsmWebServer.ino ├── keywords.txt └── extras └── License.txt /src/GSM.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1.h -------------------------------------------------------------------------------- /src/GSM3SMSService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3SMSService.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1.cpp -------------------------------------------------------------------------------- /src/GSM3SoftSerial.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3SoftSerial.h -------------------------------------------------------------------------------- /src/GSM3SMSService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3SMSService.cpp -------------------------------------------------------------------------------- /src/GSM3SoftSerial.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3SoftSerial.cpp -------------------------------------------------------------------------------- /src/GSM3CircularBuffer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3CircularBuffer.h -------------------------------------------------------------------------------- /src/GSM3CircularBuffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3CircularBuffer.cpp -------------------------------------------------------------------------------- /src/GSM3MobileSMSProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileSMSProvider.h -------------------------------------------------------------------------------- /src/GSM3VoiceCallService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3VoiceCallService.cpp -------------------------------------------------------------------------------- /src/GSM3VoiceCallService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3VoiceCallService.h -------------------------------------------------------------------------------- /src/GSM3MobileAccessProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileAccessProvider.h -------------------------------------------------------------------------------- /src/GSM3MobileCellManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileCellManagement.h -------------------------------------------------------------------------------- /src/GSM3MobileClientProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileClientProvider.h -------------------------------------------------------------------------------- /src/GSM3MobileClientService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileClientService.h -------------------------------------------------------------------------------- /src/GSM3MobileMockupProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileMockupProvider.h -------------------------------------------------------------------------------- /src/GSM3MobileServerProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileServerProvider.h -------------------------------------------------------------------------------- /src/GSM3MobileServerService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileServerService.h -------------------------------------------------------------------------------- /src/GSM3MobileVoiceProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileVoiceProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1BaseProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1BaseProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1SMSProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1SMSProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1ScanNetworks.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1ScanNetworks.h -------------------------------------------------------------------------------- /src/GSM3MobileClientService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileClientService.cpp -------------------------------------------------------------------------------- /src/GSM3MobileMockupProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileMockupProvider.cpp -------------------------------------------------------------------------------- /src/GSM3MobileNetworkProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileNetworkProvider.cpp -------------------------------------------------------------------------------- /src/GSM3MobileNetworkProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileNetworkProvider.h -------------------------------------------------------------------------------- /src/GSM3MobileNetworkRegistry.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileNetworkRegistry.cpp -------------------------------------------------------------------------------- /src/GSM3MobileNetworkRegistry.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileNetworkRegistry.h -------------------------------------------------------------------------------- /src/GSM3MobileServerService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileServerService.cpp -------------------------------------------------------------------------------- /src/GSM3ShieldV1AccessProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1AccessProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1BandManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1BandManagement.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1CellManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1CellManagement.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1ClientProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1ClientProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1PinManagement.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1PinManagement.cpp -------------------------------------------------------------------------------- /src/GSM3ShieldV1PinManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1PinManagement.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1ScanNetworks.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1ScanNetworks.cpp -------------------------------------------------------------------------------- /src/GSM3ShieldV1ServerProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1ServerProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1VoiceProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1VoiceProvider.h -------------------------------------------------------------------------------- /src/GSM3MobileDataNetworkProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3MobileDataNetworkProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1ModemVerification.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1ModemVerification.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1DataNetworkProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1DataNetworkProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1DirectModemProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1DirectModemProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1ModemVerification.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1ModemVerification.cpp -------------------------------------------------------------------------------- /src/GSM3ShieldV1MultiClientProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1MultiClientProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1MultiServerProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1MultiServerProvider.h -------------------------------------------------------------------------------- /src/GSM3ShieldV1DirectModemProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino-libraries/GSM/HEAD/src/GSM3ShieldV1DirectModemProvider.cpp -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=GSM 2 | version=1.0.6 3 | author=Arduino 4 | maintainer=Arduino 5 | sentence=Enables GSM/GRPS network connection using the Arduino GSM Shield. 6 | paragraph=Use this library to make/receive voice calls, to send and receive SMS with the Quectel M10 GSM module.
This library also allows you to connect to internet through the GPRS networks. You can either use web Clients and Servers.
7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/GSM 9 | architectures=avr 10 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = GSM Library for Arduino = 2 | 3 | With the Arduino GSM Shield, this library enables an Arduino board to do most of the operations you can do with a GSM phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/GSM 7 | 8 | == License == 9 | Copyright (c) 2012 Telefónica Digital - PDI - Physical Internet Lab 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation; either 14 | version 2.1 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | -------------------------------------------------------------------------------- /src/GSM3MobileCellManagement.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | -------------------------------------------------------------------------------- /src/GSM3MobileSMSProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | GSM3MobileSMSProvider* theGSM3SMSProvider; 37 | -------------------------------------------------------------------------------- /src/GSM3MobileVoiceProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | GSM3MobileVoiceProvider* theGSM3MobileVoiceProvider; 37 | -------------------------------------------------------------------------------- /src/GSM3MobileAccessProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | GSM3MobileAccessProvider* theGSM3MobileAccessProvider; 37 | -------------------------------------------------------------------------------- /src/GSM3MobileClientProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | GSM3MobileClientProvider* theGSM3MobileClientProvider; 37 | -------------------------------------------------------------------------------- /src/GSM3MobileDataNetworkProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | // GSM3MobileDataNetworkProvider* theGSM3MobileDataNetworkProvider; 37 | -------------------------------------------------------------------------------- /src/GSM3MobileServerProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | 35 | #include 36 | 37 | GSM3MobileServerProvider* theGSM3MobileServerProvider; 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/Tools/TestModem/TestModem.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example tests to see if the modem of the 4 | GSM shield is working correctly. You do not need 5 | a SIM card for this example. 6 | 7 | Circuit: 8 | * GSM shield attached 9 | 10 | Created 12 Jun 2012 11 | by David del Peral 12 | modified 21 Nov 2012 13 | by Tom Igoe 14 | 15 | http://www.arduino.cc/en/Tutorial/GSMToolsTestModem 16 | 17 | This sample code is part of the public domain 18 | 19 | */ 20 | 21 | // libraries 22 | #include 23 | 24 | // modem verification object 25 | GSMModem modem; 26 | 27 | // IMEI variable 28 | String IMEI = ""; 29 | 30 | void setup() { 31 | // initialize serial communications and wait for port to open: 32 | Serial.begin(9600); 33 | while (!Serial) { 34 | ; // wait for serial port to connect. Needed for Leonardo only 35 | } 36 | 37 | // start modem test (reset and check response) 38 | Serial.print("Starting modem test..."); 39 | if (modem.begin()) { 40 | Serial.println("modem.begin() succeeded"); 41 | } else { 42 | Serial.println("ERROR, no modem answer."); 43 | } 44 | } 45 | 46 | void loop() { 47 | // get modem IMEI 48 | Serial.print("Checking IMEI..."); 49 | IMEI = modem.getIMEI(); 50 | 51 | // check IMEI response 52 | if (IMEI != NULL) { 53 | // show IMEI in serial monitor 54 | Serial.println("Modem's IMEI: " + IMEI); 55 | // reset modem to check booting: 56 | Serial.print("Resetting modem..."); 57 | modem.begin(); 58 | // get and check IMEI one more time 59 | if (modem.getIMEI() != NULL) { 60 | Serial.println("Modem is functoning properly"); 61 | } else { 62 | Serial.println("Error: getIMEI() failed after modem.begin()"); 63 | } 64 | } else { 65 | Serial.println("Error: Could not get IMEI"); 66 | } 67 | // do nothing: 68 | while (true); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For GSM 3 | ####################################### 4 | # Class 5 | ####################################### 6 | 7 | GSM KEYWORD1 GSM 8 | GSMVoiceCall KEYWORD1 GSMVCSConstructor 9 | GSM_SMS KEYWORD1 GSMSMSConstructor 10 | GPRS KEYWORD1 GPRSConstructor 11 | GSMClient KEYWORD1 GSMClientConstructor 12 | GSMServer KEYWORD1 GSMServerConstructor 13 | GSMModem KEYWORD1 GSMModemConstructor 14 | GSMScanner KEYWORD1 GSMScannerConstructor 15 | GSMPIN KEYWORD1 GSMPINConstructor 16 | GSMBand KEYWORD1 GSMBandConstructor 17 | 18 | ####################################### 19 | # Methods and Functions 20 | ####################################### 21 | 22 | begin KEYWORD2 23 | shutdown KEYWORD2 24 | gatVoiceCallStatus KEYWORD2 25 | ready KEYWORD2 26 | voiceCall KEYWORD2 27 | answerCall KEYWORD2 28 | hangCall KEYWORD2 29 | retrieveCallingNumber KEYWORD2 30 | beginSMS KEYWORD2 31 | endSMS KEYWORD2 32 | remoteNumber KEYWORD2 33 | attachGPRS KEYWORD2 34 | begnWrite KEYWORD2 35 | endWrite KEYWORD2 36 | getIMEI KEYWORD2 37 | getCurrentCarrier KEYWORD2 38 | getSignalStrength KEYWORD2 39 | readNetworks KEYWORD2 40 | isPIN KEYWORD2 41 | checkPIN KEYWORD2 42 | checkPUK KEYWORD2 43 | changePIN KEYWORD2 44 | switchPIN KEYWORD2 45 | checkReg KEYWORD2 46 | getPINUsed KEYWORD2 47 | setPINUsed KEYWORD2 48 | getBand KEYWORD2 49 | setBand KEYWORD2 50 | getvoiceCallStatus KEYWORD2 51 | 52 | ####################################### 53 | # Constants 54 | ####################################### 55 | 56 | ERROR LITERAL1 57 | IDLE LITERAL1 58 | CONNECTING LITERAL1 59 | GSM_READY LITERAL1 60 | GPRS_READY LITERAL1 61 | TRANSPARENT_CONNECTED LITERAL1 62 | IDLE_CALL LITERAL1 63 | CALLING LITERAL1 64 | RECEIVINGCALL LITERAL1 65 | TALKING LITERAL1 66 | GSM_MODE_UNDEFINED LITERAL1 67 | GSM_MODE_EGSM LITERAL1 68 | GSM_MODE_DCS LITERAL1 69 | GSM_MODE_PCS LITERAL1 70 | GSM_MODE_EGSM_DCS LITERAL1 71 | GSM_MODE_GSM850_PCS LITERAL1 72 | GSM_MODE_GSM850_EGSM_DCS_PCS LITERAL1 73 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1BaseProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | #include 37 | 38 | // Returns 0 if last command is still executing 39 | // 1 if success 40 | // >1 if error 41 | int GSM3ShieldV1BaseProvider::ready() 42 | { 43 | theGSM3ShieldV1ModemCore.manageReceivedData(); 44 | 45 | return theGSM3ShieldV1ModemCore.getCommandError(); 46 | }; 47 | 48 | void GSM3ShieldV1BaseProvider::prepareAuxLocate(PGM_P str, char auxLocate[]) 49 | { 50 | int i=0; 51 | char c; 52 | 53 | do 54 | { 55 | c=pgm_read_byte_near(str + i); 56 | auxLocate[i]=c; 57 | i++; 58 | } while (c!=0); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/GSM3IO.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #ifdef TTOPEN_V1 35 | #define __POWERPIN__ 5 36 | #define __RESETPIN__ 6 37 | #else 38 | #define __RESETPIN__ 7 39 | #endif 40 | 41 | #if defined(__AVR_ATmega328P__) 42 | #ifdef TTOPEN_V1 43 | #define __TXPIN__ 3 44 | #define __RXPIN__ 4 45 | #define __RXINT__ 3 46 | #else 47 | #define __TXPIN__ 3 48 | #define __RXPIN__ 2 49 | #define __RXINT__ 3 50 | #endif 51 | #elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) 52 | #define __TXPIN__ 3 53 | #define __RXPIN__ 10 54 | #define __RXINT__ 4 55 | #elif defined(__AVR_ATmega32U4__) 56 | #define __TXPIN__ 3 57 | #define __RXPIN__ 8 58 | #define __RXINT__ 3 59 | #endif 60 | -------------------------------------------------------------------------------- /examples/Tools/TestWebServer/TestWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic Web Server 3 | 4 | A simple web server that replies with nothing, but prints the client's request 5 | and the server IP address. 6 | 7 | Circuit: 8 | * GSM shield attached 9 | 10 | created 11 | by David Cuartielles 12 | modified 21 Nov 2012 13 | by Tom Igoe 14 | 15 | http://www.arduino.cc/en/Tutorial/GSMToolsTestWebServer 16 | 17 | This example code is part of the public domain 18 | */ 19 | #include 20 | 21 | // PIN Number 22 | #define PINNUMBER "" 23 | 24 | // APN data 25 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN 26 | #define GPRS_LOGIN "login" // replace with your GPRS login 27 | #define GPRS_PASSWORD "password" // replace with your GPRS password 28 | 29 | 30 | // initialize the library instance 31 | GPRS gprs; 32 | GSM gsmAccess; // include a 'true' parameter for debug enabled 33 | GSMServer server(80); // port 80 (http default) 34 | 35 | // timeout 36 | const unsigned long __TIMEOUT__ = 10 * 1000; 37 | 38 | void setup() { 39 | // initialize serial communications and wait for port to open: 40 | Serial.begin(9600); 41 | while (!Serial) { 42 | ; // wait for serial port to connect. Needed for Leonardo only 43 | } 44 | 45 | Serial.println("starting,.."); 46 | // connection state 47 | bool connected = true; 48 | 49 | // Start GSM shield 50 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 51 | while (!connected) { 52 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & 53 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { 54 | connected = true; 55 | } else { 56 | Serial.println("Not connected"); 57 | delay(1000); 58 | } 59 | } 60 | 61 | Serial.println("Connected to GPRS network"); 62 | 63 | // start server 64 | server.begin(); 65 | 66 | //Get IP. 67 | IPAddress LocalIP = gprs.getIPAddress(); 68 | Serial.println("Server IP address="); 69 | Serial.println(LocalIP); 70 | } 71 | 72 | void loop() { 73 | GSMClient client = server.available(); 74 | 75 | if (client) { 76 | if (client.available()) { 77 | Serial.write(client.read()); 78 | } 79 | } 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /examples/ReceiveSMS/ReceiveSMS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SMS receiver 3 | 4 | This sketch, for the Arduino GSM shield, waits for a SMS message 5 | and displays it through the Serial port. 6 | 7 | Circuit: 8 | * GSM shield attached to and Arduino 9 | * SIM card that can receive SMS messages 10 | 11 | created 25 Feb 2012 12 | by Javier Zorzano / TD 13 | 14 | This example is in the public domain. 15 | 16 | http://www.arduino.cc/en/Tutorial/GSMExamplesReceiveSMS 17 | 18 | */ 19 | 20 | // include the GSM library 21 | #include 22 | 23 | // PIN Number for the SIM 24 | #define PINNUMBER "" 25 | 26 | // initialize the library instances 27 | GSM gsmAccess; 28 | GSM_SMS sms; 29 | 30 | // Array to hold the number a SMS is retreived from 31 | char senderNumber[20]; 32 | 33 | void setup() { 34 | // initialize serial communications and wait for port to open: 35 | Serial.begin(9600); 36 | while (!Serial) { 37 | ; // wait for serial port to connect. Needed for native USB port only 38 | } 39 | 40 | Serial.println("SMS Messages Receiver"); 41 | 42 | // connection state 43 | bool notConnected = true; 44 | 45 | // Start GSM connection 46 | while (notConnected) { 47 | if (gsmAccess.begin(PINNUMBER) == GSM_READY) { 48 | notConnected = false; 49 | } else { 50 | Serial.println("Not connected"); 51 | delay(1000); 52 | } 53 | } 54 | 55 | Serial.println("GSM initialized"); 56 | Serial.println("Waiting for messages"); 57 | } 58 | 59 | void loop() { 60 | char c; 61 | 62 | // If there are any SMSs available() 63 | if (sms.available()) { 64 | Serial.println("Message received from:"); 65 | 66 | // Get remote number 67 | sms.remoteNumber(senderNumber, 20); 68 | Serial.println(senderNumber); 69 | 70 | // An example of message disposal 71 | // Any messages starting with # should be discarded 72 | if (sms.peek() == '#') { 73 | Serial.println("Discarded SMS"); 74 | sms.flush(); 75 | } 76 | 77 | // Read message bytes and print them 78 | while (c = sms.read()) { 79 | Serial.print(c); 80 | } 81 | 82 | Serial.println("\nEND OF MESSAGE"); 83 | 84 | // Delete message from modem memory 85 | sms.flush(); 86 | Serial.println("MESSAGE DELETED"); 87 | } 88 | 89 | delay(1000); 90 | 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /examples/Tools/GsmScanNetworks/GsmScanNetworks.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | GSM Scan Networks 4 | 5 | This example prints out the IMEI number of the modem, 6 | then checks to see if it's connected to a carrier. If so, 7 | it prints the phone number associated with the card. 8 | Then it scans for nearby networks and prints out their signal strengths. 9 | 10 | Circuit: 11 | * GSM shield 12 | * SIM card 13 | 14 | Created 8 Mar 2012 15 | by Tom Igoe, implemented by Javier Carazo 16 | Modified 4 Feb 2013 17 | by Scott Fitzgerald 18 | 19 | http://www.arduino.cc/en/Tutorial/GSMToolsGsmScanNetworks 20 | 21 | This example code is part of the public domain 22 | */ 23 | 24 | // libraries 25 | #include 26 | 27 | // PIN Number 28 | #define PINNUMBER "" 29 | 30 | // initialize the library instance 31 | GSM gsmAccess; // include a 'true' parameter to enable debugging 32 | GSMScanner scannerNetworks; 33 | GSMModem modemTest; 34 | 35 | // Save data variables 36 | String IMEI = ""; 37 | 38 | // serial monitor result messages 39 | String errortext = "ERROR"; 40 | 41 | void setup() { 42 | // initialize serial communications and wait for port to open: 43 | Serial.begin(9600); 44 | while (!Serial) { 45 | ; // wait for serial port to connect. Needed for Leonardo only 46 | } 47 | 48 | Serial.println("GSM networks scanner"); 49 | scannerNetworks.begin(); 50 | 51 | // connection state 52 | bool notConnected = true; 53 | 54 | // Start GSM shield 55 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 56 | while (notConnected) { 57 | if (gsmAccess.begin(PINNUMBER) == GSM_READY) { 58 | notConnected = false; 59 | } else { 60 | Serial.println("Not connected"); 61 | delay(1000); 62 | } 63 | } 64 | 65 | // get modem parameters 66 | // IMEI, modem unique identifier 67 | Serial.print("Modem IMEI: "); 68 | IMEI = modemTest.getIMEI(); 69 | IMEI.replace("\n", ""); 70 | if (IMEI != NULL) { 71 | Serial.println(IMEI); 72 | } 73 | } 74 | 75 | void loop() { 76 | // scan for existing networks, displays a list of networks 77 | Serial.println("Scanning available networks. May take some seconds."); 78 | Serial.println(scannerNetworks.readNetworks()); 79 | 80 | // currently connected carrier 81 | Serial.print("Current carrier: "); 82 | Serial.println(scannerNetworks.getCurrentCarrier()); 83 | 84 | // returns strength and ber 85 | // signal strength in 0-31 scale. 31 means power > 51dBm 86 | // BER is the Bit Error Rate. 0-7 scale. 99=not detectable 87 | Serial.print("Signal Strength: "); 88 | Serial.print(scannerNetworks.getSignalStrength()); 89 | Serial.println(" [0-31]"); 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /examples/SendSMS/SendSMS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SMS sender 3 | 4 | This sketch, for the Arduino GSM shield,sends an SMS message 5 | you enter in the serial monitor. Connect your Arduino with the 6 | GSM shield and SIM card, open the serial monitor, and wait for 7 | the "READY" message to appear in the monitor. Next, type a 8 | message to send and press "return". Make sure the serial 9 | monitor is set to send a newline when you press return. 10 | 11 | Circuit: 12 | * GSM shield 13 | * SIM card that can send SMS 14 | 15 | created 25 Feb 2012 16 | by Tom Igoe 17 | 18 | This example is in the public domain. 19 | 20 | http://www.arduino.cc/en/Tutorial/GSMExamplesSendSMS 21 | 22 | */ 23 | 24 | // Include the GSM library 25 | #include 26 | 27 | #define PINNUMBER "" 28 | 29 | // initialize the library instance 30 | GSM gsmAccess; 31 | GSM_SMS sms; 32 | 33 | void setup() { 34 | // initialize serial communications and wait for port to open: 35 | Serial.begin(9600); 36 | while (!Serial) { 37 | ; // wait for serial port to connect. Needed for native USB port only 38 | } 39 | 40 | Serial.println("SMS Messages Sender"); 41 | 42 | // connection state 43 | bool notConnected = true; 44 | 45 | // Start GSM shield 46 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 47 | while (notConnected) { 48 | if (gsmAccess.begin(PINNUMBER) == GSM_READY) { 49 | notConnected = false; 50 | } else { 51 | Serial.println("Not connected"); 52 | delay(1000); 53 | } 54 | } 55 | 56 | Serial.println("GSM initialized"); 57 | } 58 | 59 | void loop() { 60 | 61 | Serial.print("Enter a mobile number: "); 62 | char remoteNum[20]; // telephone number to send sms 63 | readSerial(remoteNum); 64 | Serial.println(remoteNum); 65 | 66 | // sms text 67 | Serial.print("Now, enter SMS content: "); 68 | char txtMsg[200]; 69 | readSerial(txtMsg); 70 | Serial.println("SENDING"); 71 | Serial.println(); 72 | Serial.println("Message:"); 73 | Serial.println(txtMsg); 74 | 75 | // send the message 76 | sms.beginSMS(remoteNum); 77 | sms.print(txtMsg); 78 | sms.endSMS(); 79 | Serial.println("\nCOMPLETE!\n"); 80 | } 81 | 82 | /* 83 | Read input serial 84 | */ 85 | int readSerial(char result[]) { 86 | int i = 0; 87 | while (1) { 88 | while (Serial.available() > 0) { 89 | char inChar = Serial.read(); 90 | if (inChar == '\n') { 91 | result[i] = '\0'; 92 | Serial.flush(); 93 | return 0; 94 | } 95 | if (inChar != '\r') { 96 | result[i] = inChar; 97 | i++; 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /examples/ReceiveVoiceCall/ReceiveVoiceCall.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Receive Voice Call 3 | 4 | This sketch, for the Arduino GSM shield, receives voice calls, 5 | displays the calling number, waits a few seconds then hangs up. 6 | 7 | Circuit: 8 | * GSM shield 9 | * Voice circuit. Refer to to the GSM shield getting started guide 10 | at http://www.arduino.cc/en/Guide/ArduinoGSMShield#toc11 11 | * SIM card that can accept voice calls 12 | 13 | With no voice circuit the call will connect, but will not send or receive sound 14 | 15 | created Mar 2012 16 | by Javier Zorzano 17 | 18 | This example is in the public domain. 19 | 20 | http://www.arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall 21 | 22 | */ 23 | 24 | // Include the GSM library 25 | #include 26 | 27 | // PIN Number 28 | #define PINNUMBER "" 29 | 30 | // initialize the library instance 31 | GSM gsmAccess; 32 | GSMVoiceCall vcs; 33 | 34 | // Array to hold the number for the incoming call 35 | char numtel[20]; 36 | 37 | void setup() { 38 | // initialize serial communications and wait for port to open: 39 | Serial.begin(9600); 40 | while (!Serial) { 41 | ; // wait for serial port to connect. Needed for native USB port only 42 | } 43 | 44 | Serial.println("Receive Voice Call"); 45 | 46 | // connection state 47 | bool notConnected = true; 48 | 49 | // Start GSM shield 50 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 51 | while (notConnected) { 52 | if (gsmAccess.begin(PINNUMBER) == GSM_READY) { 53 | notConnected = false; 54 | } else { 55 | Serial.println("Not connected"); 56 | delay(1000); 57 | } 58 | } 59 | 60 | // This makes sure the modem correctly reports incoming events 61 | vcs.hangCall(); 62 | 63 | Serial.println("Waiting for a call"); 64 | } 65 | 66 | void loop() { 67 | // Check the status of the voice call 68 | switch (vcs.getvoiceCallStatus()) { 69 | case IDLE_CALL: // Nothing is happening 70 | 71 | break; 72 | 73 | case RECEIVINGCALL: // Yes! Someone is calling us 74 | 75 | Serial.println("RECEIVING CALL"); 76 | 77 | // Retrieve the calling number 78 | vcs.retrieveCallingNumber(numtel, 20); 79 | 80 | // Print the calling number 81 | Serial.print("Number:"); 82 | Serial.println(numtel); 83 | 84 | // Answer the call, establish the call 85 | vcs.answerCall(); 86 | break; 87 | 88 | case TALKING: // In this case the call would be established 89 | 90 | Serial.println("TALKING. Press enter to hang up."); 91 | while (Serial.read() != '\n') { 92 | delay(100); 93 | } 94 | vcs.hangCall(); 95 | Serial.println("Hanging up and waiting for the next call."); 96 | break; 97 | } 98 | delay(1000); 99 | } 100 | 101 | 102 | -------------------------------------------------------------------------------- /examples/GsmWebClient/GsmWebClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web client 3 | 4 | This sketch connects to a website through a GSM shield. Specifically, 5 | this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and 6 | prints it to the Serial monitor. 7 | 8 | Circuit: 9 | * GSM shield attached to an Arduino 10 | * SIM card with a data plan 11 | 12 | created 8 Mar 2012 13 | by Tom Igoe 14 | 15 | http://www.arduino.cc/en/Tutorial/GSMExamplesWebClient 16 | 17 | */ 18 | 19 | // libraries 20 | #include 21 | 22 | // PIN Number 23 | #define PINNUMBER "" 24 | 25 | // APN data 26 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN 27 | #define GPRS_LOGIN "login" // replace with your GPRS login 28 | #define GPRS_PASSWORD "password" // replace with your GPRS password 29 | 30 | // initialize the library instance 31 | GSMClient client; 32 | GPRS gprs; 33 | GSM gsmAccess; 34 | 35 | // URL, path & port (for example: arduino.cc) 36 | char server[] = "arduino.cc"; 37 | char path[] = "/asciilogo.txt"; 38 | int port = 80; // port 80 is the default for HTTP 39 | 40 | void setup() { 41 | // initialize serial communications and wait for port to open: 42 | Serial.begin(9600); 43 | while (!Serial) { 44 | ; // wait for serial port to connect. Needed for native USB port only 45 | } 46 | 47 | Serial.println("Starting Arduino web client."); 48 | // connection state 49 | bool notConnected = true; 50 | 51 | // After starting the modem with GSM.begin() 52 | // attach the shield to the GPRS network with the APN, login and password 53 | while (notConnected) { 54 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & 55 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { 56 | notConnected = false; 57 | } else { 58 | Serial.println("Not connected"); 59 | delay(1000); 60 | } 61 | } 62 | 63 | Serial.println("connecting..."); 64 | 65 | // if you get a connection, report back via serial: 66 | if (client.connect(server, port)) { 67 | Serial.println("connected"); 68 | // Make a HTTP request: 69 | client.print("GET "); 70 | client.print(path); 71 | client.println(" HTTP/1.1"); 72 | client.print("Host: "); 73 | client.println(server); 74 | client.println("Connection: close"); 75 | client.println(); 76 | } else { 77 | // if you didn't get a connection to the server: 78 | Serial.println("connection failed"); 79 | } 80 | } 81 | 82 | void loop() { 83 | // if there are incoming bytes available 84 | // from the server, read them and print them: 85 | if (client.available()) { 86 | char c = client.read(); 87 | Serial.print(c); 88 | } 89 | 90 | // if the server's disconnected, stop the client: 91 | if (!client.available() && !client.connected()) { 92 | Serial.println(); 93 | Serial.println("disconnecting."); 94 | client.stop(); 95 | 96 | // do nothing forevermore: 97 | for (;;) 98 | ; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /examples/MakeVoiceCall/MakeVoiceCall.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Make Voice Call 3 | 4 | This sketch, for the Arduino GSM shield, puts a voice call to 5 | a remote phone number that you enter through the serial monitor. 6 | To make it work, open the serial monitor, and when you see the 7 | READY message, type a phone number. Make sure the serial monitor 8 | is set to send a just newline when you press return. 9 | 10 | Circuit: 11 | * GSM shield 12 | * Voice circuit. 13 | With no voice circuit the call will send nor receive any sound 14 | 15 | 16 | created Mar 2012 17 | by Javier Zorzano 18 | 19 | This example is in the public domain. 20 | */ 21 | 22 | // libraries 23 | #include 24 | 25 | // PIN Number 26 | #define PINNUMBER "" 27 | 28 | // initialize the library instance 29 | GSM gsmAccess; // include a 'true' parameter for debug enabled 30 | GSMVoiceCall vcs; 31 | 32 | String remoteNumber = ""; // the number you will call 33 | char charbuffer[20]; 34 | 35 | void setup() { 36 | 37 | // initialize serial communications and wait for port to open: 38 | Serial.begin(9600); 39 | while (!Serial) { 40 | ; // wait for serial port to connect. Needed for native USB port only 41 | } 42 | 43 | Serial.println("Make Voice Call"); 44 | 45 | // connection state 46 | bool notConnected = true; 47 | 48 | // Start GSM shield 49 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 50 | while (notConnected) { 51 | if (gsmAccess.begin(PINNUMBER) == GSM_READY) { 52 | notConnected = false; 53 | } else { 54 | Serial.println("Not connected"); 55 | delay(1000); 56 | } 57 | } 58 | 59 | Serial.println("GSM initialized."); 60 | Serial.println("Enter phone number to call."); 61 | 62 | } 63 | 64 | void loop() { 65 | 66 | // add any incoming characters to the String: 67 | while (Serial.available() > 0) { 68 | char inChar = Serial.read(); 69 | // if it's a newline, that means you should make the call: 70 | if (inChar == '\n') { 71 | // make sure the phone number is not too long: 72 | if (remoteNumber.length() < 20) { 73 | // let the user know you're calling: 74 | Serial.print("Calling to : "); 75 | Serial.println(remoteNumber); 76 | Serial.println(); 77 | 78 | // Call the remote number 79 | remoteNumber.toCharArray(charbuffer, 20); 80 | 81 | 82 | // Check if the receiving end has picked up the call 83 | if (vcs.voiceCall(charbuffer)) { 84 | Serial.println("Call Established. Enter line to end"); 85 | // Wait for some input from the line 86 | while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING)); 87 | // And hang up 88 | vcs.hangCall(); 89 | } 90 | Serial.println("Call Finished"); 91 | remoteNumber = ""; 92 | Serial.println("Enter phone number to call."); 93 | } else { 94 | Serial.println("That's too long for a phone number. I'm forgetting it"); 95 | remoteNumber = ""; 96 | } 97 | } else { 98 | // add the latest character to the message to send: 99 | if (inChar != '\r') { 100 | remoteNumber += inChar; 101 | } 102 | } 103 | } 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1BandManagement.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | GSM3ShieldV1BandManagement::GSM3ShieldV1BandManagement(bool trace): modem(trace) 37 | { 38 | quectelStrings[UNDEFINED]=""; 39 | quectelStrings[EGSM_MODE]="\"EGSM_MODE\""; 40 | quectelStrings[DCS_MODE]="\"DCS_MODE\""; 41 | quectelStrings[PCS_MODE]="\"PCS_MODE\""; 42 | quectelStrings[EGSM_DCS_MODE]="\"EGSM_DCS_MODE\""; 43 | quectelStrings[GSM850_PCS_MODE]="\"GSM850_PCS_MODE\""; 44 | quectelStrings[GSM850_EGSM_DCS_PCS_MODE]="\"GSM850_EGSM_DCS_PCS_MODE\""; 45 | } 46 | 47 | GSM3_NetworkStatus_t GSM3ShieldV1BandManagement::begin() 48 | { 49 | // check modem response 50 | modem.begin(); 51 | 52 | // reset hardware 53 | modem.restartModem(); 54 | 55 | return IDLE; 56 | } 57 | 58 | String GSM3ShieldV1BandManagement::getBand() 59 | { 60 | String modemResponse=modem.writeModemCommand("AT+QBAND?", 2000); 61 | 62 | for(GSM3GSMBand i=GSM850_EGSM_DCS_PCS_MODE;i>UNDEFINED;i=(GSM3GSMBand)((int)i-1)) 63 | { 64 | if(modemResponse.indexOf(quectelStrings[i])>=0) 65 | return quectelStrings[i]; 66 | } 67 | 68 | Serial.print("Unrecognized modem answer:"); 69 | Serial.println(modemResponse); 70 | 71 | return ""; 72 | } 73 | 74 | bool GSM3ShieldV1BandManagement::setBand(String band) 75 | { 76 | String command; 77 | String modemResponse; 78 | bool found=false; 79 | 80 | command="AT+QBAND="; 81 | for(GSM3GSMBand i=EGSM_MODE;((i<=GSM850_EGSM_DCS_PCS_MODE)&&(!found));i=(GSM3GSMBand)((int)i+1)) 82 | { 83 | String aux=quectelStrings[i]; 84 | if(aux.indexOf(band)>=0) 85 | { 86 | command+=aux; 87 | found=true; 88 | } 89 | } 90 | 91 | if(!found) 92 | return false; 93 | // Quad-band takes an awful lot of time 94 | modemResponse=modem.writeModemCommand(command, 15000); 95 | 96 | if(modemResponse.indexOf("QBAND")>=0) 97 | return true; 98 | else 99 | return false; 100 | } 101 | -------------------------------------------------------------------------------- /examples/GsmWebServer/GsmWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | GSM Web Server 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using a GSM shield. 6 | 7 | Circuit: 8 | * GSM shield attached 9 | * Analog inputs attached to pins A0 through A5 (optional) 10 | 11 | created 8 Mar 2012 12 | by Tom Igoe 13 | */ 14 | 15 | // libraries 16 | #include 17 | 18 | // PIN Number 19 | #define PINNUMBER "" 20 | 21 | // APN data 22 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN 23 | #define GPRS_LOGIN "login" // replace with your GPRS login 24 | #define GPRS_PASSWORD "password" // replace with your GPRS password 25 | 26 | 27 | // initialize the library instance 28 | GPRS gprs; 29 | GSM gsmAccess; // include a 'true' parameter for debug enabled 30 | GSMServer server(80); // port 80 (http default) 31 | 32 | // timeout 33 | const unsigned long __TIMEOUT__ = 10 * 1000; 34 | 35 | void setup() { 36 | // initialize serial communications and wait for port to open: 37 | Serial.begin(9600); 38 | while (!Serial) { 39 | ; // wait for serial port to connect. Needed for native USB port only 40 | } 41 | 42 | // connection state 43 | bool notConnected = true; 44 | 45 | // Start GSM shield 46 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 47 | while (notConnected) { 48 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) & 49 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { 50 | notConnected = false; 51 | } else { 52 | Serial.println("Not connected"); 53 | delay(1000); 54 | } 55 | } 56 | 57 | Serial.println("Connected to GPRS network"); 58 | 59 | // start server 60 | server.begin(); 61 | 62 | //Get IP. 63 | IPAddress LocalIP = gprs.getIPAddress(); 64 | Serial.println("Server IP address="); 65 | Serial.println(LocalIP); 66 | } 67 | 68 | void loop() { 69 | 70 | 71 | // listen for incoming clients 72 | GSMClient client = server.available(); 73 | 74 | 75 | 76 | if (client) { 77 | while (client.connected()) { 78 | if (client.available()) { 79 | Serial.println("Receiving request!"); 80 | bool sendResponse = false; 81 | while (char c = client.read()) { 82 | if (c == '\n') { 83 | sendResponse = true; 84 | } 85 | } 86 | 87 | // if you've gotten to the end of the line (received a newline 88 | // character) 89 | if (sendResponse) { 90 | // send a standard http response header 91 | client.println("HTTP/1.1 200 OK"); 92 | client.println("Content-Type: text/html"); 93 | client.println(); 94 | client.println(""); 95 | // output the value of each analog input pin 96 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 97 | client.print("analog input "); 98 | client.print(analogChannel); 99 | client.print(" is "); 100 | client.print(analogRead(analogChannel)); 101 | client.println("
"); 102 | } 103 | client.println(""); 104 | //necessary delay 105 | delay(1000); 106 | client.stop(); 107 | } 108 | } 109 | } 110 | } 111 | } 112 | 113 | 114 | -------------------------------------------------------------------------------- /examples/Tools/BandManagement/BandManagement.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Band Management 3 | 4 | This sketch, for the Arduino GSM shield, checks the band 5 | currently configured in the modem and allows you to change 6 | it. 7 | 8 | Please check http://www.worldtimezone.com/gsm.html 9 | Usual configurations: 10 | Europe, Africa, Middle East: E-GSM(900)+DCS(1800) 11 | USA, Canada, South America: GSM(850)+PCS(1900) 12 | Mexico: PCS(1900) 13 | Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900) 14 | 15 | 16 | Circuit: 17 | * GSM shield 18 | 19 | created 12 June 2012 20 | by Javier Zorzano, Scott Fitzgerald 21 | 22 | This example is in the public domain. 23 | */ 24 | 25 | // libraries 26 | #include 27 | 28 | // initialize the library instance 29 | GSMBand band; 30 | 31 | void setup() { 32 | // initialize serial communications and wait for port to open: 33 | Serial.begin(9600); 34 | while (!Serial) { 35 | ; // wait for serial port to connect. Needed for Leonardo only 36 | } 37 | 38 | // Beginning the band manager restarts the modem 39 | Serial.println("Restarting modem..."); 40 | band.begin(); 41 | Serial.println("Modem restarted."); 42 | 43 | }; 44 | 45 | 46 | void loop() { 47 | // Get current band 48 | String bandName = band.getBand(); // Get and print band name 49 | Serial.print("Current band:"); 50 | Serial.println(bandName); 51 | Serial.println("Want to change the band you’re on?"); 52 | String newBandName; 53 | newBandName = askUser(); 54 | // Tell the user what we are about to do… 55 | Serial.print("\nConfiguring band "); 56 | Serial.println(newBandName); 57 | // Change the band 58 | bool operationSuccess; 59 | operationSuccess = band.setBand(newBandName); 60 | // Tell the user if the operation was OK 61 | if (operationSuccess) { 62 | Serial.println("Success"); 63 | } else { 64 | Serial.println("Error while changing band"); 65 | } 66 | 67 | if (operationSuccess) { 68 | while (true); 69 | } 70 | } 71 | 72 | // This function offers the user different options 73 | // through the Serial interface 74 | // The user selects one 75 | String askUser() { 76 | String newBand; 77 | Serial.println("Select band:"); 78 | // Print the different options 79 | Serial.println("1 : E-GSM(900)"); 80 | Serial.println("2 : DCS(1800)"); 81 | Serial.println("3 : PCS(1900)"); 82 | Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe"); 83 | Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am."); 84 | Serial.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)"); 85 | 86 | // Empty the incoming buffer 87 | while (Serial.available()) { 88 | Serial.read(); 89 | } 90 | 91 | // Wait for an answer, just look at the first character 92 | while (!Serial.available()); 93 | char c = Serial.read(); 94 | if (c == '1') { 95 | newBand = GSM_MODE_EGSM; 96 | } else if (c == '2') { 97 | newBand = GSM_MODE_DCS; 98 | } else if (c == '3') { 99 | newBand = GSM_MODE_PCS; 100 | } else if (c == '4') { 101 | newBand = GSM_MODE_EGSM_DCS; 102 | } else if (c == '5') { 103 | newBand = GSM_MODE_GSM850_PCS; 104 | } else if (c == '6') { 105 | newBand = GSM_MODE_GSM850_EGSM_DCS_PCS; 106 | } else { 107 | newBand = "GSM_MODE_UNDEFINED"; 108 | } 109 | return newBand; 110 | } 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /examples/Tools/PinManagement/PinManagement.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example enables you to change or remove the PIN number of 4 | a SIM card inserted into a GSM shield. 5 | 6 | Circuit: 7 | * GSM shield 8 | * SIM card 9 | 10 | Created 12 Jun 2012 11 | by David del Peral 12 | 13 | This example code is part of the public domain 14 | 15 | http://www.arduino.cc/en/Tutorial/GSMToolsPinManagement 16 | 17 | */ 18 | 19 | // libraries 20 | #include 21 | 22 | // pin manager object 23 | GSMPIN PINManager; 24 | 25 | // save input in serial by user 26 | String user_input = ""; 27 | 28 | // authenticated with PIN code 29 | bool auth = false; 30 | 31 | // serial monitor result messages 32 | String oktext = "OK"; 33 | String errortext = "ERROR"; 34 | 35 | void setup() { 36 | // initialize serial communications and wait for port to open: 37 | Serial.begin(9600); 38 | while (!Serial) { 39 | ; // wait for serial port to connect. Needed for Leonardo only 40 | } 41 | 42 | Serial.println("Change PIN example\n"); 43 | PINManager.begin(); 44 | 45 | // check if the SIM have pin lock 46 | while (!auth) { 47 | int pin_query = PINManager.isPIN(); 48 | if (pin_query == 1) { 49 | // if SIM is locked, enter PIN code 50 | Serial.print("Enter PIN code: "); 51 | user_input = readSerial(); 52 | // check PIN code 53 | if (PINManager.checkPIN(user_input) == 0) { 54 | auth = true; 55 | PINManager.setPINUsed(true); 56 | Serial.println(oktext); 57 | } else { 58 | // if PIN code was incorrected 59 | Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); 60 | } 61 | } else if (pin_query == -1) { 62 | // PIN code is locked, user must enter PUK code 63 | Serial.println("PIN locked. Enter PUK code: "); 64 | String puk = readSerial(); 65 | Serial.print("Now, enter a new PIN code: "); 66 | user_input = readSerial(); 67 | // check PUK code 68 | if (PINManager.checkPUK(puk, user_input) == 0) { 69 | auth = true; 70 | PINManager.setPINUsed(true); 71 | Serial.println(oktext); 72 | } else { 73 | // if PUK o the new PIN are incorrect 74 | Serial.println("Incorrect PUK or invalid new PIN. Try again!."); 75 | } 76 | } else if (pin_query == -2) { 77 | // the worst case, PIN and PUK are locked 78 | Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone."); 79 | while (true); 80 | } else { 81 | // SIM does not requires authetication 82 | Serial.println("No pin necessary."); 83 | auth = true; 84 | } 85 | } 86 | 87 | // start GSM shield 88 | Serial.print("Checking register in GSM network..."); 89 | if (PINManager.checkReg() == 0) { 90 | Serial.println(oktext); 91 | } 92 | // if you are connect by roaming 93 | else if (PINManager.checkReg() == 1) { 94 | Serial.println("ROAMING " + oktext); 95 | } else { 96 | // error connection 97 | Serial.println(errortext); 98 | while (true); 99 | } 100 | } 101 | 102 | void loop() { 103 | // Function loop implements pin management user menu 104 | // Only if you SIM use pin lock, you can change PIN code 105 | // user_op variables save user option 106 | 107 | Serial.println("Choose an option:\n1 - On/Off PIN."); 108 | if (PINManager.getPINUsed()) { 109 | Serial.println("2 - Change PIN."); 110 | } 111 | String user_op = readSerial(); 112 | if (user_op == "1") { 113 | Serial.println("Enter your PIN code:"); 114 | user_input = readSerial(); 115 | // activate/deactivate PIN lock 116 | PINManager.switchPIN(user_input); 117 | } else if (user_op == "2" & PINManager.getPINUsed()) { 118 | Serial.println("Enter your actual PIN code:"); 119 | String oldPIN = readSerial(); 120 | Serial.println("Now, enter your new PIN code:"); 121 | String newPIN = readSerial(); 122 | // change PIN 123 | PINManager.changePIN(oldPIN, newPIN); 124 | } else { 125 | Serial.println("Incorrect option. Try again!."); 126 | } 127 | delay(1000); 128 | } 129 | 130 | /* 131 | Read input serial 132 | */ 133 | String readSerial() { 134 | String text = ""; 135 | while (1) { 136 | while (Serial.available() > 0) { 137 | char inChar = Serial.read(); 138 | if (inChar == '\n') { 139 | return text; 140 | } 141 | if (inChar != '\r') { 142 | text += inChar; 143 | } 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /examples/Tools/TestGPRS/TestGPRS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This sketch test the GSM shield's ability to connect to a 4 | GPERS network. It asks for APN information through the 5 | serial monitor and tries to connect to arduino.cc. 6 | 7 | Circuit: 8 | * GSM shield attached 9 | * SIM card with data plan 10 | 11 | Created 18 Jun 2012 12 | by David del Peral 13 | 14 | This example code is part of the public domain 15 | 16 | http://www.arduino.cc/en/Tutorial/GSMToolsTestGPRS 17 | 18 | */ 19 | 20 | // libraries 21 | #include 22 | 23 | // PIN Number 24 | #define PINNUMBER "" 25 | 26 | // initialize the library instance 27 | GSM gsmAccess; // GSM access: include a 'true' parameter for debug enabled 28 | GPRS gprsAccess; // GPRS access 29 | GSMClient client; // Client service for TCP connection 30 | 31 | // messages for serial monitor response 32 | String oktext = "OK"; 33 | String errortext = "ERROR"; 34 | 35 | // URL and path (for example: arduino.cc) 36 | char url[] = "arduino.cc"; 37 | char urlproxy[] = "http://www.arduino.cc"; 38 | char path[] = "/"; 39 | 40 | // variable for save response obtained 41 | String response = ""; 42 | 43 | // use a proxy 44 | bool use_proxy = false; 45 | 46 | void setup() { 47 | // initialize serial communications and wait for port to open: 48 | Serial.begin(9600); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo only 51 | } 52 | } 53 | 54 | void loop() { 55 | use_proxy = false; 56 | 57 | // start GSM shield 58 | // if your SIM has PIN, pass it as a parameter of begin() in quotes 59 | Serial.print("Connecting GSM network..."); 60 | if (gsmAccess.begin(PINNUMBER) != GSM_READY) { 61 | Serial.println(errortext); 62 | while (true); 63 | } 64 | Serial.println(oktext); 65 | 66 | // read APN introduced by user 67 | char apn[50]; 68 | Serial.print("Enter your APN: "); 69 | readSerial(apn); 70 | Serial.println(apn); 71 | 72 | // Read APN login introduced by user 73 | char login[50]; 74 | Serial.print("Now, enter your login: "); 75 | readSerial(login); 76 | Serial.println(login); 77 | 78 | // read APN password introduced by user 79 | char password[20]; 80 | Serial.print("Finally, enter your password: "); 81 | readSerial(password); 82 | 83 | // attach GPRS 84 | Serial.println("Attaching to GPRS with your APN..."); 85 | if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) { 86 | Serial.println(errortext); 87 | } else { 88 | 89 | Serial.println(oktext); 90 | 91 | // read proxy introduced by user 92 | char proxy[100]; 93 | Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); 94 | readSerial(proxy); 95 | Serial.println(proxy); 96 | 97 | // if user introduced a proxy, asks him for proxy port 98 | int pport; 99 | if (proxy[0] != '\0') { 100 | // read proxy port introduced by user 101 | char proxyport[10]; 102 | Serial.print("Enter the proxy port: "); 103 | readSerial(proxyport); 104 | // cast proxy port introduced to integer 105 | pport = (int) proxyport; 106 | use_proxy = true; 107 | Serial.println(proxyport); 108 | } 109 | 110 | // connection with arduino.cc and realize HTTP request 111 | Serial.print("Connecting and sending GET request to arduino.cc..."); 112 | int res_connect; 113 | 114 | // if use a proxy, connect with it 115 | if (use_proxy) { 116 | res_connect = client.connect(proxy, pport); 117 | } else { 118 | res_connect = client.connect(url, 80); 119 | } 120 | 121 | if (res_connect) { 122 | // make a HTTP 1.0 GET request (client sends the request) 123 | client.print("GET "); 124 | 125 | // if use a proxy, the path is arduino.cc URL 126 | if (use_proxy) { 127 | client.print(urlproxy); 128 | } else { 129 | client.print(path); 130 | } 131 | 132 | client.println(" HTTP/1.0"); 133 | client.println(); 134 | Serial.println(oktext); 135 | } else { 136 | // if you didn't get a connection to the server 137 | Serial.println(errortext); 138 | } 139 | Serial.print("Receiving response..."); 140 | 141 | bool test = true; 142 | while (test) { 143 | // if there are incoming bytes available 144 | // from the server, read and check them 145 | if (client.available()) { 146 | char c = client.read(); 147 | response += c; 148 | 149 | // cast response obtained from string to char array 150 | char responsechar[response.length() + 1]; 151 | response.toCharArray(responsechar, response.length() + 1); 152 | 153 | // if response includes a "200 OK" substring 154 | if (strstr(responsechar, "200 OK") != NULL) { 155 | Serial.println(oktext); 156 | Serial.println("TEST COMPLETE!"); 157 | test = false; 158 | } 159 | } 160 | 161 | // if the server's disconnected, stop the client: 162 | if (!client.connected()) { 163 | Serial.println(); 164 | Serial.println("disconnecting."); 165 | client.stop(); 166 | test = false; 167 | } 168 | } 169 | } 170 | } 171 | 172 | /* 173 | Read input serial 174 | */ 175 | int readSerial(char result[]) { 176 | int i = 0; 177 | while (1) { 178 | while (Serial.available() > 0) { 179 | char inChar = Serial.read(); 180 | if (inChar == '\n') { 181 | result[i] = '\0'; 182 | return 0; 183 | } 184 | if (inChar != '\r') { 185 | result[i] = inChar; 186 | i++; 187 | } 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1CellManagement.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | 36 | GSM3ShieldV1CellManagement::GSM3ShieldV1CellManagement() 37 | { 38 | } 39 | 40 | bool GSM3ShieldV1CellManagement::parseQCCID_available(bool& rsp) 41 | { 42 | char c; 43 | bool iccidFound = false; 44 | int i = 0; 45 | 46 | while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 19)) 47 | { 48 | if((c < 58) & (c > 47)) 49 | iccidFound = true; 50 | 51 | if(iccidFound) 52 | { 53 | bufferICCID[i] = c; 54 | i++; 55 | } 56 | } 57 | bufferICCID[i]=0; 58 | 59 | return true; 60 | } 61 | 62 | bool GSM3ShieldV1CellManagement::parseQENG_available(bool& rsp) 63 | { 64 | char c; 65 | char location[50] = ""; 66 | int i = 0; 67 | 68 | if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG: ", true))) 69 | rsp = false; 70 | else 71 | rsp = true; 72 | 73 | if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG:", true))) 74 | rsp = false; 75 | else 76 | rsp = true; 77 | 78 | while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 50)) 79 | { 80 | location[i] = c; 81 | i++; 82 | } 83 | location[i]=0; 84 | 85 | char* res_tok = strtok(location, ","); 86 | res_tok=strtok(NULL, ","); 87 | strcpy(countryCode, res_tok); 88 | res_tok=strtok(NULL, ","); 89 | strcpy(networkCode, res_tok); 90 | res_tok=strtok(NULL, ","); 91 | strcpy(locationArea, res_tok); 92 | res_tok=strtok(NULL, ","); 93 | strcpy(cellId, res_tok); 94 | 95 | return true; 96 | } 97 | 98 | int GSM3ShieldV1CellManagement::getLocation(char *country, char *network, char *area, char *cell) 99 | { 100 | if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY)) 101 | return 2; 102 | 103 | countryCode=country; 104 | networkCode=network; 105 | locationArea=area; 106 | cellId=cell; 107 | 108 | theGSM3ShieldV1ModemCore.openCommand(this,GETLOCATION); 109 | getLocationContinue(); 110 | 111 | unsigned long timeOut = millis(); 112 | while(((millis() - timeOut) < 5000) & (ready() == 0)); 113 | 114 | return theGSM3ShieldV1ModemCore.getCommandError(); 115 | } 116 | 117 | void GSM3ShieldV1CellManagement::getLocationContinue() 118 | { 119 | bool resp; 120 | 121 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 122 | case 1: 123 | theGSM3ShieldV1ModemCore.gss.tunedDelay(3000); 124 | delay(3000); 125 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 126 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG=1"), false); 127 | theGSM3ShieldV1ModemCore.print("\r"); 128 | break; 129 | case 2: 130 | if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 131 | { 132 | theGSM3ShieldV1ModemCore.gss.tunedDelay(3000); 133 | delay(3000); 134 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 135 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG?"), false); 136 | theGSM3ShieldV1ModemCore.print("\r"); 137 | } 138 | else theGSM3ShieldV1ModemCore.closeCommand(1); 139 | break; 140 | case 3: 141 | if (resp) 142 | { 143 | parseQENG_available(resp); 144 | theGSM3ShieldV1ModemCore.closeCommand(3); 145 | } 146 | else theGSM3ShieldV1ModemCore.closeCommand(2); 147 | break; 148 | } 149 | } 150 | 151 | int GSM3ShieldV1CellManagement::getICCID(char *iccid) 152 | { 153 | if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY)) 154 | return 2; 155 | 156 | bufferICCID=iccid; 157 | theGSM3ShieldV1ModemCore.openCommand(this,GETICCID); 158 | getICCIDContinue(); 159 | 160 | unsigned long timeOut = millis(); 161 | while(((millis() - timeOut) < 5000) & (ready() == 0)); 162 | 163 | return theGSM3ShieldV1ModemCore.getCommandError(); 164 | } 165 | 166 | void GSM3ShieldV1CellManagement::getICCIDContinue() 167 | { 168 | bool resp; 169 | 170 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 171 | case 1: 172 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 173 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QCCID"), false); 174 | theGSM3ShieldV1ModemCore.print("\r"); 175 | break; 176 | case 2: 177 | if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 178 | { 179 | parseQCCID_available(resp); 180 | theGSM3ShieldV1ModemCore.closeCommand(2); 181 | } 182 | else theGSM3ShieldV1ModemCore.closeCommand(1); 183 | break; 184 | } 185 | } 186 | 187 | void GSM3ShieldV1CellManagement::manageResponse(byte from, byte to) 188 | { 189 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 190 | { 191 | case NONE: 192 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 193 | break; 194 | case GETLOCATION: 195 | getLocationContinue(); 196 | break; 197 | case GETICCID: 198 | getICCIDContinue(); 199 | break; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1ModemCore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | 37 | GSM3ShieldV1ModemCore theGSM3ShieldV1ModemCore; 38 | 39 | char* __ok__="OK"; 40 | 41 | GSM3ShieldV1ModemCore::GSM3ShieldV1ModemCore() : gss() 42 | { 43 | gss.registerMgr(this); 44 | _dataInBufferFrom=0; 45 | _dataInBufferTo=0; 46 | commandError=1; 47 | commandCounter=0; 48 | ongoingCommand=NONE; 49 | takeMilliseconds(); 50 | 51 | for(int i=0;irecognizeUnsolicitedEvent(from); 176 | } 177 | if((!recognized)&&(activeProvider)) 178 | activeProvider->manageResponse(from, to); 179 | } 180 | 181 | 182 | void GSM3ShieldV1ModemCore::openCommand(GSM3ShieldV1BaseProvider* provider, GSM3_commandType_e c) 183 | { 184 | activeProvider=provider; 185 | commandError=0; 186 | commandCounter=1; 187 | ongoingCommand=c; 188 | _dataInBufferFrom=0; 189 | _dataInBufferTo=0; 190 | 191 | }; 192 | 193 | size_t GSM3ShieldV1ModemCore::writePGM(PGM_P str, bool CR) 194 | { 195 | int i=0; 196 | char c; 197 | 198 | do 199 | { 200 | c=pgm_read_byte_near(str + i); 201 | if(c!=0) 202 | write(c); 203 | i++; 204 | } while (c!=0); 205 | if(CR) 206 | print("\r"); 207 | 208 | return 1; 209 | } 210 | 211 | size_t GSM3ShieldV1ModemCore::write(uint8_t c) 212 | { 213 | if(_debug) 214 | GSM3CircularBuffer::printCharDebug(c); 215 | return gss.write(c); 216 | } 217 | 218 | unsigned long GSM3ShieldV1ModemCore::takeMilliseconds() 219 | { 220 | unsigned long now=millis(); 221 | unsigned long delta; 222 | delta=now-milliseconds; 223 | milliseconds=now; 224 | return delta; 225 | } 226 | 227 | void GSM3ShieldV1ModemCore::delayInsideInterrupt(unsigned long milliseconds) 228 | { 229 | for (unsigned long k=0;k 35 | #include 36 | #include 37 | 38 | GSM3ShieldV1ServerProvider::GSM3ShieldV1ServerProvider() 39 | { 40 | theGSM3MobileServerProvider=this; 41 | }; 42 | 43 | //Response management. 44 | void GSM3ShieldV1ServerProvider::manageResponse(byte from, byte to) 45 | { 46 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 47 | { 48 | case NONE: 49 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 50 | break; 51 | case CONNECTSERVER: 52 | connectTCPServerContinue(); 53 | break; 54 | /*case GETIP: 55 | getIPContinue(); 56 | break;*/ 57 | } 58 | } 59 | 60 | //Connect Server main function. 61 | int GSM3ShieldV1ServerProvider::connectTCPServer(int port) 62 | { 63 | // We forget about LocalIP as it has no real use, the modem does whatever it likes 64 | theGSM3ShieldV1ModemCore.setPort(port); 65 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTSERVER); 66 | // From this moment on we wait for a call 67 | connectTCPServerContinue(); 68 | return theGSM3ShieldV1ModemCore.getCommandError(); 69 | } 70 | 71 | //Connect Server continue function. 72 | void GSM3ShieldV1ServerProvider::connectTCPServerContinue() 73 | { 74 | 75 | bool resp; 76 | // 1: Read Local IP "AT+QILOCIP" 77 | // 2: Waiting for IP and Set local port "AT+QILPORT" 78 | // 3: Waiting for QILPOR OK andConfigure as server "AT+QISERVER" 79 | // 4: Wait for SERVER OK 80 | 81 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 82 | case 1: 83 | //"AT+QILOCIP." 84 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILOCIP")); 85 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 86 | break; 87 | case 2: 88 | //Not IP storing but the command is necessary. 89 | //if(parseQILOCIP_rsp(local_IP, local_IP_Length, resp)) 90 | // This awful trick saves some RAM bytes 91 | char aux[3]; 92 | aux[0]='\r';aux[1]='\n';aux[2]=0; 93 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux)) 94 | { 95 | //Response received 96 | if(resp) 97 | { 98 | // Great. Go for the next step 99 | // AT+QILPORT 100 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILPORT=\"TCP\","),false); 101 | theGSM3ShieldV1ModemCore.print( theGSM3ShieldV1ModemCore.getPort()); 102 | theGSM3ShieldV1ModemCore.print('\r'); 103 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 104 | } 105 | else theGSM3ShieldV1ModemCore.closeCommand(3); 106 | } 107 | break; 108 | case 3: 109 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 110 | { 111 | // Response received 112 | if(resp) 113 | { 114 | // OK received 115 | // Great. Go for the next step 116 | // AT+QISERVER 117 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISERVER"),true); 118 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 119 | } 120 | else theGSM3ShieldV1ModemCore.closeCommand(3); 121 | } 122 | break; 123 | case 4: 124 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 125 | { 126 | // Response received 127 | // OK received, kathapoon, chessespoon 128 | if (resp) 129 | { 130 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 131 | theGSM3ShieldV1ModemCore.closeCommand(1); 132 | } 133 | else 134 | theGSM3ShieldV1ModemCore.closeCommand(3); 135 | } 136 | break; 137 | } 138 | } 139 | 140 | //QILOCIP parse. 141 | /*bool GSM3ShieldV1ServerProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp) 142 | { 143 | if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength))) 144 | rsp = false; 145 | else 146 | rsp = true; 147 | return true; 148 | } 149 | 150 | //Get IP main function. 151 | int GSM3ShieldV1ServerProvider::getIP(char* LocalIP, int LocalIPlength) 152 | { 153 | theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP); 154 | theGSM3ShieldV1ModemCore.setPort(LocalIPlength); 155 | theGSM3ShieldV1ModemCore.openCommand(this,GETIP); 156 | getIPContinue(); 157 | return theGSM3ShieldV1ModemCore.getCommandError(); 158 | } 159 | 160 | void GSM3ShieldV1ServerProvider::getIPContinue() 161 | { 162 | 163 | bool resp; 164 | // 1: Read Local IP "AT+QILOCIP" 165 | // 2: Waiting for IP. 166 | 167 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 168 | case 1: 169 | //AT+QILOCIP 170 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MonoQILOCIP); 171 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 172 | break; 173 | case 2: 174 | if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp)) 175 | { 176 | if (resp) 177 | theGSM3ShieldV1ModemCore.closeCommand(1); 178 | else 179 | theGSM3ShieldV1ModemCore.closeCommand(3); 180 | } 181 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 182 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 183 | break; 184 | } 185 | }*/ 186 | 187 | bool GSM3ShieldV1ServerProvider::getSocketAsServerModemStatus(int s) 188 | { 189 | if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 190 | return true; 191 | else 192 | return false; 193 | } 194 | 195 | 196 | //URC recognize. 197 | bool GSM3ShieldV1ServerProvider::recognizeUnsolicitedEvent(byte oldTail) 198 | { 199 | 200 | int nlength; 201 | char auxLocate [15]; 202 | 203 | //REMOTE SOCKET CLOSED. 204 | prepareAuxLocate(PSTR("CLOSED\r\n"), auxLocate); 205 | if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate)) 206 | { 207 | //To detect remote socket closed for example inside socket data. 208 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 209 | } 210 | 211 | 212 | //REMOTE SOCKET ACCEPTED. 213 | prepareAuxLocate(PSTR("CONNECT\r\n"), auxLocate); 214 | if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate)) 215 | { 216 | //To detect remote socket closed for example inside socket data. 217 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, true); 218 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 219 | theGSM3ShieldV1ModemCore.setStatus(TRANSPARENT_CONNECTED); 220 | return true; 221 | } 222 | 223 | return false; 224 | } 225 | 226 | bool GSM3ShieldV1ServerProvider::getStatusSocketAsServer(uint8_t socket) 227 | { 228 | return(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED); 229 | }; 230 | 231 | void GSM3ShieldV1ServerProvider::releaseSocket(int socket) 232 | { 233 | } 234 | 235 | int GSM3ShieldV1ServerProvider::getNewOccupiedSocketAsServer() 236 | { 237 | return 0; 238 | } 239 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1VoiceProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | 37 | GSM3ShieldV1VoiceProvider::GSM3ShieldV1VoiceProvider() 38 | { 39 | phonelength=0; 40 | theGSM3MobileVoiceProvider=this; 41 | } 42 | 43 | void GSM3ShieldV1VoiceProvider::initialize() 44 | { 45 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 46 | } 47 | 48 | //Voice Call main function. 49 | int GSM3ShieldV1VoiceProvider::voiceCall(const char* to) 50 | { 51 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATD"),false); 52 | theGSM3ShieldV1ModemCore.print(to); 53 | theGSM3ShieldV1ModemCore.print(";\r"); 54 | setvoiceCallStatus(CALLING); 55 | return 1; 56 | } 57 | 58 | //Retrieve calling number main function. 59 | int GSM3ShieldV1VoiceProvider::retrieveCallingNumber (char* buffer, int bufsize) 60 | { 61 | theGSM3ShieldV1ModemCore.setPhoneNumber(buffer); 62 | phonelength = bufsize; 63 | theGSM3ShieldV1ModemCore.setCommandError(0); 64 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 65 | theGSM3ShieldV1ModemCore.openCommand(this,RETRIEVECALLINGNUMBER); 66 | retrieveCallingNumberContinue(); 67 | return theGSM3ShieldV1ModemCore.getCommandError(); 68 | } 69 | 70 | //Retrieve calling number Continue function. 71 | void GSM3ShieldV1VoiceProvider::retrieveCallingNumberContinue() 72 | { 73 | // 1: AT+CLCC 74 | // 2: Receive +CLCC: 1,1,4,0,0,"num",129,"" 75 | // This implementation really does not care much if the modem aswers trash to CMGL 76 | bool resp; 77 | //int msglength_aux; 78 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 79 | case 1: 80 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLCC")); 81 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 82 | break; 83 | case 2: 84 | if(parseCLCC(theGSM3ShieldV1ModemCore.getPhoneNumber(), phonelength)) 85 | { 86 | theGSM3ShieldV1ModemCore.closeCommand(1); 87 | } 88 | break; 89 | } 90 | } 91 | 92 | //CLCC parse. 93 | bool GSM3ShieldV1VoiceProvider::parseCLCC(char* number, int nlength) 94 | { 95 | theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CLCC: 1,1,4,0,0,\"","\"", number, nlength); 96 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 97 | return true; 98 | } 99 | 100 | //Answer Call main function. 101 | int GSM3ShieldV1VoiceProvider::answerCall() 102 | { 103 | theGSM3ShieldV1ModemCore.setCommandError(0); 104 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 105 | theGSM3ShieldV1ModemCore.openCommand(this,ANSWERCALL); 106 | answerCallContinue(); 107 | return theGSM3ShieldV1ModemCore.getCommandError(); 108 | } 109 | 110 | //Answer Call continue function. 111 | void GSM3ShieldV1VoiceProvider::answerCallContinue() 112 | { 113 | // 1: ATA 114 | // 2: Waiting for OK 115 | 116 | // This implementation really does not care much if the modem aswers trash to CMGL 117 | bool resp; 118 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 119 | case 1: 120 | // ATA ; 121 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATA")); 122 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 123 | break; 124 | case 2: 125 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 126 | { 127 | setvoiceCallStatus(TALKING); 128 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 129 | else theGSM3ShieldV1ModemCore.closeCommand(3); 130 | } 131 | break; 132 | } 133 | } 134 | 135 | //Hang Call main function. 136 | int GSM3ShieldV1VoiceProvider::hangCall() 137 | { 138 | theGSM3ShieldV1ModemCore.setCommandError(0); 139 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 140 | theGSM3ShieldV1ModemCore.openCommand(this,HANGCALL); 141 | hangCallContinue(); 142 | return theGSM3ShieldV1ModemCore.getCommandError(); 143 | } 144 | 145 | //Hang Call continue function. 146 | void GSM3ShieldV1VoiceProvider::hangCallContinue() 147 | { 148 | // 1: ATH 149 | // 2: Waiting for OK 150 | 151 | bool resp; 152 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 153 | case 1: 154 | //ATH 155 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATH")); 156 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 157 | break; 158 | case 2: 159 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 160 | { 161 | setvoiceCallStatus(IDLE_CALL); 162 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 163 | else theGSM3ShieldV1ModemCore.closeCommand(3); 164 | } 165 | break; 166 | } 167 | } 168 | 169 | //Response management. 170 | void GSM3ShieldV1VoiceProvider::manageResponse(byte from, byte to) 171 | { 172 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 173 | { 174 | case ANSWERCALL: 175 | answerCallContinue(); 176 | break; 177 | case HANGCALL: 178 | hangCallContinue(); 179 | break; 180 | case RETRIEVECALLINGNUMBER: 181 | retrieveCallingNumberContinue(); 182 | break; 183 | 184 | } 185 | } 186 | 187 | //URC recognize. 188 | bool GSM3ShieldV1VoiceProvider::recognizeUnsolicitedEvent(byte oldTail) 189 | { 190 | 191 | int nlength; 192 | char auxLocate [15]; 193 | //RING. 194 | prepareAuxLocate(PSTR("RING"), auxLocate); 195 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 196 | { 197 | // RING 198 | setvoiceCallStatus(RECEIVINGCALL); 199 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 200 | return true; 201 | } 202 | 203 | //CALL ACEPTED. 204 | prepareAuxLocate(PSTR("+COLP:"), auxLocate); 205 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 206 | { 207 | //DEBUG 208 | //Serial.println("Call Accepted."); 209 | setvoiceCallStatus(TALKING); 210 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 211 | return true; 212 | } 213 | 214 | //NO CARRIER. 215 | prepareAuxLocate(PSTR("NO CARRIER"), auxLocate); 216 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 217 | { 218 | //DEBUG 219 | //Serial.println("NO CARRIER received."); 220 | setvoiceCallStatus(IDLE_CALL); 221 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 222 | return true; 223 | } 224 | 225 | //BUSY. 226 | prepareAuxLocate(PSTR("BUSY"), auxLocate); 227 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 228 | { 229 | //DEBUG 230 | //Serial.println("BUSY received."); 231 | setvoiceCallStatus(IDLE_CALL); 232 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 233 | return true; 234 | } 235 | 236 | //CALL RECEPTION. 237 | prepareAuxLocate(PSTR("+CLIP:"), auxLocate); 238 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 239 | { 240 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 241 | setvoiceCallStatus(RECEIVINGCALL); 242 | return true; 243 | } 244 | 245 | return false; 246 | } 247 | 248 | 249 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1ModemCore.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | 35 | #ifndef __GSM3_SHIELDV1MODEMCORE__ 36 | #define __GSM3_SHIELDV1MODEMCORE__ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #define UMPROVIDERS 3 44 | 45 | class GSM3ShieldV1ModemCore : public GSM3SoftSerialMgr, public Print 46 | { 47 | private: 48 | 49 | // Phone number, used when calling, sending SMS and reading calling numbers 50 | // Also PIN in modem configuration 51 | // Also APN 52 | // Also remote server 53 | char* phoneNumber; 54 | 55 | // Working port. Port used in the ongoing command, while opening a server 56 | // Also for IP address length 57 | int port; 58 | 59 | // 0 = ongoing 60 | // 1 = OK 61 | // 2 = Error. Incorrect state 62 | // 3 = Unexpected modem message 63 | // 4 = OK but not available data. 64 | uint8_t commandError; 65 | 66 | // Counts the steps by the command 67 | uint8_t commandCounter; 68 | 69 | // Presently ongoing command 70 | GSM3_commandType_e ongoingCommand; 71 | 72 | // Enable/disable debug 73 | bool _debug; 74 | byte _dataInBufferFrom; 75 | byte _dataInBufferTo; 76 | 77 | // This is the modem (known) status 78 | GSM3_NetworkStatus_t _status; 79 | 80 | GSM3ShieldV1BaseProvider* UMProvider[UMPROVIDERS]; 81 | GSM3ShieldV1BaseProvider* activeProvider; 82 | 83 | // Private function for anage message 84 | void manageMsgNow(byte from, byte to); 85 | 86 | unsigned long milliseconds; 87 | 88 | public: 89 | 90 | /** Constructor */ 91 | GSM3ShieldV1ModemCore(); 92 | 93 | GSM3SoftSerial gss; // Direct access to modem 94 | 95 | /** Get phone number 96 | @return phone number 97 | */ 98 | char *getPhoneNumber(){return phoneNumber;}; 99 | 100 | /** Establish a new phone number 101 | @param n Phone number 102 | */ 103 | void setPhoneNumber(char *n){phoneNumber=n;}; 104 | 105 | /** Get port used 106 | @return port 107 | */ 108 | int getPort(){return port;}; 109 | 110 | /** Establish a new port for use 111 | @param p Port 112 | */ 113 | void setPort(int p){port=p;}; 114 | 115 | /** Get command error 116 | @return command error 117 | */ 118 | uint8_t getCommandError(){return commandError;}; 119 | 120 | /** Establish a command error 121 | @param n Command error 122 | */ 123 | void setCommandError(uint8_t n){commandError=n;}; 124 | 125 | /** Get command counter 126 | @return command counter 127 | */ 128 | uint8_t getCommandCounter(){return commandCounter;}; 129 | 130 | /** Set command counter 131 | @param c Initial value 132 | */ 133 | void setCommandCounter(uint8_t c){commandCounter=c;}; 134 | 135 | /** Get ongoing command 136 | @return command 137 | */ 138 | GSM3_commandType_e getOngoingCommand(){return ongoingCommand;}; 139 | 140 | /** Set ongoing command 141 | @param c New ongoing command 142 | */ 143 | void setOngoingCommand(GSM3_commandType_e c){ongoingCommand=c;}; 144 | 145 | /** Open command 146 | @param activeProvider Active provider 147 | @param c Command for open 148 | */ 149 | void openCommand(GSM3ShieldV1BaseProvider* activeProvider, GSM3_commandType_e c); 150 | 151 | /** Close command 152 | @param code Close code 153 | */ 154 | void closeCommand(int code); 155 | 156 | // These functions allow writing to the SoftwareSerial 157 | // If debug is set, dump to the console 158 | 159 | /** Write a character in serial 160 | @param c Character 161 | @return size 162 | */ 163 | size_t write(uint8_t c); 164 | 165 | /** Write PGM 166 | @param str Buffer for write 167 | @param CR Carriadge return adding automatically 168 | @return size 169 | */ 170 | virtual size_t writePGM(PGM_P str, bool CR=true); 171 | 172 | /** Establish debug mode 173 | @param db Boolean that indicates debug on or off 174 | */ 175 | void setDebug(bool db){_debug=db;}; 176 | 177 | /** Generic response parser 178 | @param rsp Returns true if expected response exists 179 | @param string Substring expected in response 180 | @param string2 Second substring expected in response 181 | @return true if parsed correctly 182 | */ 183 | bool genericParse_rsp(bool& rsp, const char* string=0, const char* string2=0); 184 | 185 | /** Generates a generic AT command request from PROGMEM buffer 186 | @param str Buffer with AT command 187 | @param addCR Carriadge return adding automatically 188 | */ 189 | void genericCommand_rq(PGM_P str, bool addCR=true); 190 | 191 | /** Generates a generic AT command request from a simple char buffer 192 | @param str Buffer with AT command 193 | @param addCR Carriadge return adding automatically 194 | */ 195 | void genericCommand_rqc(const char* str, bool addCR=true); 196 | 197 | /** Returns the circular buffer 198 | @return circular buffer 199 | */ 200 | inline GSM3CircularBuffer& theBuffer(){return gss.cb;}; 201 | 202 | /** Establish a new network status 203 | @param status Network status 204 | */ 205 | inline void setStatus(GSM3_NetworkStatus_t status) { _status = status; }; 206 | 207 | /** Returns actual network status 208 | @return network status 209 | */ 210 | inline GSM3_NetworkStatus_t getStatus() { return _status; }; 211 | 212 | /** Register provider as willing to receive unsolicited messages 213 | @param provider Pointer to provider able to receive unsolicited messages 214 | */ 215 | void registerUMProvider(GSM3ShieldV1BaseProvider* provider); 216 | 217 | /** unegister provider as willing to receive unsolicited messages 218 | @param provider Pointer to provider able to receive unsolicited messages 219 | */ 220 | void unRegisterUMProvider(GSM3ShieldV1BaseProvider* provider); 221 | 222 | 223 | /** Register a provider as "dialoguing" talking in facto with the modem 224 | @param provider Pointer to provider receiving responses 225 | */ 226 | void registerActiveProvider(GSM3ShieldV1BaseProvider* provider){activeProvider=provider;}; 227 | 228 | /** Needed to manage the SoftSerial. Receives the call when received data 229 | If _debugging, no code is called 230 | @param from Starting byte to read 231 | @param to Last byte to read 232 | */ 233 | void manageMsg(byte from, byte to); 234 | 235 | /** If _debugging, this call is assumed to be made out of interrupts 236 | Prints incoming info and calls manageMsgNow 237 | */ 238 | void manageReceivedData(); 239 | 240 | /** Chronometer. Measure milliseconds from last call 241 | @return milliseconds from las time function was called 242 | */ 243 | unsigned long takeMilliseconds(); 244 | 245 | /** Delay for interrupts 246 | @param milliseconds Delay time in milliseconds 247 | */ 248 | void delayInsideInterrupt(unsigned long milliseconds); 249 | 250 | }; 251 | 252 | extern GSM3ShieldV1ModemCore theGSM3ShieldV1ModemCore; 253 | 254 | #endif 255 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1SMSProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | 37 | GSM3ShieldV1SMSProvider::GSM3ShieldV1SMSProvider() 38 | { 39 | theGSM3SMSProvider=this; 40 | }; 41 | 42 | //Send SMS begin function. 43 | int GSM3ShieldV1SMSProvider::beginSMS(const char* to) 44 | { 45 | if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY)&&(theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY)) 46 | return 2; 47 | 48 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)to); 49 | theGSM3ShieldV1ModemCore.openCommand(this,BEGINSMS); 50 | beginSMSContinue(); 51 | return theGSM3ShieldV1ModemCore.getCommandError(); 52 | } 53 | 54 | //Send SMS continue function. 55 | void GSM3ShieldV1SMSProvider::beginSMSContinue() 56 | { 57 | bool resp; 58 | // 1: Send AT 59 | // 2: wait for > and write text 60 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 61 | case 1: 62 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 63 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGS=\""), false); 64 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 65 | theGSM3ShieldV1ModemCore.print("\"\r"); 66 | break; 67 | case 2: 68 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, ">")) 69 | { 70 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 71 | else theGSM3ShieldV1ModemCore.closeCommand(3); 72 | } 73 | break; 74 | } 75 | } 76 | 77 | //Send SMS write function. 78 | void GSM3ShieldV1SMSProvider::writeSMS(char c) 79 | { 80 | theGSM3ShieldV1ModemCore.write(c); 81 | } 82 | 83 | //Send SMS begin function. 84 | int GSM3ShieldV1SMSProvider::endSMS() 85 | { 86 | theGSM3ShieldV1ModemCore.openCommand(this,ENDSMS); 87 | endSMSContinue(); 88 | while(ready()==0) delay(100); 89 | return theGSM3ShieldV1ModemCore.getCommandError(); 90 | } 91 | 92 | //Send SMS continue function. 93 | void GSM3ShieldV1SMSProvider::endSMSContinue() 94 | { 95 | bool resp; 96 | // 1: Send #26 97 | // 2: wait for OK 98 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 99 | case 1: 100 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 101 | theGSM3ShieldV1ModemCore.write(26); 102 | theGSM3ShieldV1ModemCore.print("\r"); 103 | break; 104 | case 2: 105 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 106 | { 107 | if (resp) 108 | theGSM3ShieldV1ModemCore.closeCommand(1); 109 | else 110 | theGSM3ShieldV1ModemCore.closeCommand(3); 111 | } 112 | break; 113 | } 114 | } 115 | 116 | //Available SMS main function. 117 | int GSM3ShieldV1SMSProvider::availableSMS() 118 | { 119 | flagReadingSMS = 0; 120 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESMS); 121 | availableSMSContinue(); 122 | return theGSM3ShieldV1ModemCore.getCommandError(); 123 | } 124 | 125 | //Available SMS continue function. 126 | void GSM3ShieldV1SMSProvider::availableSMSContinue() 127 | { 128 | // 1: AT+CMGL="REC UNREAD",1 129 | // 2: Receive +CMGL: _id_ ... READ","_numero_" ... \n_mensaje_\nOK 130 | // 3: Send AT+CMGD= _id_ 131 | // 4: Receive OK 132 | // 5: Remaining SMS text in case full buffer. 133 | // This implementation really does not care much if the modem aswers trash to CMGL 134 | bool resp; 135 | //int msglength_aux; 136 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 137 | case 1: 138 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGL=\"REC UNREAD\",1")); 139 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 140 | break; 141 | case 2: 142 | if(parseCMGL_available(resp)) 143 | { 144 | if (!resp) theGSM3ShieldV1ModemCore.closeCommand(4); 145 | else theGSM3ShieldV1ModemCore.closeCommand(1); 146 | } 147 | break; 148 | } 149 | 150 | } 151 | 152 | //SMS available parse. 153 | bool GSM3ShieldV1SMSProvider::parseCMGL_available(bool& rsp) 154 | { 155 | fullBufferSMS = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<=4); 156 | if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+CMGL:", true))) 157 | rsp = false; 158 | else 159 | rsp = true; 160 | idSMS=theGSM3ShieldV1ModemCore.theBuffer().readInt(); 161 | 162 | //If there are 2 SMS in buffer, response is ...CRLFCRLF+CMGL 163 | twoSMSinBuffer = theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+"); 164 | 165 | checkSecondBuffer = 0; 166 | 167 | return true; 168 | } 169 | 170 | //remoteNumber SMS function. 171 | int GSM3ShieldV1SMSProvider::remoteSMSNumber(char* number, int nlength) 172 | { 173 | theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("READ\",\"", "\"", number, nlength); 174 | 175 | return 1; 176 | } 177 | 178 | //remoteNumber SMS function. 179 | int GSM3ShieldV1SMSProvider::readSMS() 180 | { 181 | char charSMS; 182 | //First char. 183 | if (!flagReadingSMS) 184 | { 185 | flagReadingSMS = 1; 186 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil("\n", true); 187 | } 188 | charSMS = theGSM3ShieldV1ModemCore.theBuffer().read(); 189 | 190 | //Second Buffer. 191 | if (checkSecondBuffer) 192 | { 193 | checkSecondBuffer = 0; 194 | twoSMSinBuffer = theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+"); 195 | } 196 | 197 | //Case the last char in buffer. 198 | if ((!twoSMSinBuffer)&&fullBufferSMS&&(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127)) 199 | { 200 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 201 | fullBufferSMS = 0; 202 | checkSecondBuffer = 1; 203 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 204 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 205 | delay(10); 206 | 207 | return charSMS; 208 | } 209 | //Case two SMS in buffer 210 | else if (twoSMSinBuffer) 211 | { 212 | if (theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+")) 213 | { 214 | return charSMS; 215 | } 216 | else 217 | { 218 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 219 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 220 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 221 | delay(10); 222 | return 0; 223 | } 224 | } 225 | //Case 1 SMS and buffer not full 226 | else if (!fullBufferSMS) 227 | { 228 | if (theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\nOK")) 229 | { 230 | return charSMS; 231 | } 232 | else 233 | { 234 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 235 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 236 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 237 | delay(10); 238 | return 0; 239 | } 240 | } 241 | //Case to read all the chars in buffer to the end. 242 | else 243 | { 244 | return charSMS; 245 | } 246 | } 247 | 248 | //Read socket main function. 249 | int GSM3ShieldV1SMSProvider::peekSMS() 250 | { 251 | if (!flagReadingSMS) 252 | { 253 | flagReadingSMS = 1; 254 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil("\n", true); 255 | } 256 | 257 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0); 258 | } 259 | 260 | //Flush SMS main function. 261 | void GSM3ShieldV1SMSProvider::flushSMS() 262 | { 263 | 264 | //With this, sms data can fill up to 2x128+5x128 bytes. 265 | for (int aux = 0;aux<5;aux++) 266 | { 267 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 268 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 269 | delay(10); 270 | } 271 | 272 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSMS); 273 | flushSMSContinue(); 274 | } 275 | 276 | //Send SMS continue function. 277 | void GSM3ShieldV1SMSProvider::flushSMSContinue() 278 | { 279 | bool resp; 280 | // 1: Deleting SMS 281 | // 2: wait for OK 282 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 283 | case 1: 284 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 285 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGD="), false); 286 | theGSM3ShieldV1ModemCore.print(idSMS); 287 | theGSM3ShieldV1ModemCore.print("\r"); 288 | break; 289 | case 2: 290 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 291 | { 292 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 293 | else theGSM3ShieldV1ModemCore.closeCommand(3); 294 | } 295 | break; 296 | } 297 | } 298 | 299 | void GSM3ShieldV1SMSProvider::manageResponse(byte from, byte to) 300 | { 301 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 302 | { 303 | /* case XON: 304 | if (flagReadingSocket) 305 | { 306 | // flagReadingSocket = 0; 307 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 308 | } 309 | else theGSM3ShieldV1ModemCore.openCommand(this,NONE); 310 | break; 311 | */ case NONE: 312 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 313 | break; 314 | case BEGINSMS: 315 | beginSMSContinue(); 316 | break; 317 | case ENDSMS: 318 | endSMSContinue(); 319 | break; 320 | case AVAILABLESMS: 321 | availableSMSContinue(); 322 | break; 323 | case FLUSHSMS: 324 | flushSMSContinue(); 325 | break; 326 | } 327 | } 328 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1ClientProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | 37 | GSM3ShieldV1ClientProvider::GSM3ShieldV1ClientProvider() 38 | { 39 | theGSM3MobileClientProvider=this; 40 | }; 41 | 42 | //Response management. 43 | void GSM3ShieldV1ClientProvider::manageResponse(byte from, byte to) 44 | { 45 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 46 | { 47 | case NONE: 48 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 49 | break; 50 | case CONNECTTCPCLIENT: 51 | connectTCPClientContinue(); 52 | break; 53 | case FLUSHSOCKET: 54 | flushSocketContinue(); 55 | break; 56 | } 57 | } 58 | 59 | //Connect TCP main function. 60 | int GSM3ShieldV1ClientProvider::connectTCPClient(const char* server, int port, int id_socket) 61 | { 62 | theGSM3ShieldV1ModemCore.setPort(port); 63 | idSocket = id_socket; 64 | 65 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server); 66 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT); 67 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 68 | connectTCPClientContinue(); 69 | return theGSM3ShieldV1ModemCore.getCommandError(); 70 | } 71 | 72 | int GSM3ShieldV1ClientProvider::connectTCPClient(IPAddress add, int port, int id_socket) 73 | { 74 | remoteIP=add; 75 | theGSM3ShieldV1ModemCore.setPhoneNumber(0); 76 | return connectTCPClient(0, port, id_socket); 77 | } 78 | 79 | //Connect TCP continue function. 80 | void GSM3ShieldV1ClientProvider::connectTCPClientContinue() 81 | { 82 | bool resp; 83 | // 0: Dot or DNS notation activation 84 | // 1: Disable SW flow control 85 | // 2: Waiting for IFC OK 86 | // 3: Start-up TCP connection "AT+QIOPEN" 87 | // 4: Wait for connection OK 88 | // 5: Wait for CONNECT 89 | 90 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 91 | case 1: 92 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false); 93 | if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&& 94 | ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9')))) 95 | { 96 | theGSM3ShieldV1ModemCore.print('1'); 97 | theGSM3ShieldV1ModemCore.print('\r'); 98 | } 99 | else 100 | { 101 | theGSM3ShieldV1ModemCore.print('0'); 102 | theGSM3ShieldV1ModemCore.print('\r'); 103 | } 104 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 105 | break; 106 | case 2: 107 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 108 | { 109 | //Response received 110 | if(resp) 111 | { 112 | // AT+QIOPEN 113 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false); 114 | theGSM3ShieldV1ModemCore.print("\"TCP\",\""); 115 | if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0) 116 | { 117 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 118 | } 119 | else 120 | { 121 | remoteIP.printTo(theGSM3ShieldV1ModemCore); 122 | } 123 | theGSM3ShieldV1ModemCore.print('"'); 124 | theGSM3ShieldV1ModemCore.print(','); 125 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort()); 126 | theGSM3ShieldV1ModemCore.print('\r'); 127 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 128 | } 129 | else theGSM3ShieldV1ModemCore.closeCommand(3); 130 | } 131 | break; 132 | 133 | case 3: 134 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 135 | { 136 | // Response received 137 | if(resp) 138 | { 139 | // OK Received 140 | // Great. Go for the next step 141 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 142 | } 143 | else theGSM3ShieldV1ModemCore.closeCommand(3); 144 | } 145 | break; 146 | case 4: 147 | char auxLocate [12]; 148 | prepareAuxLocate(PSTR("CONNECT\r\n"), auxLocate); 149 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate)) 150 | { 151 | // Response received 152 | if(resp) 153 | { 154 | // Received CONNECT OK 155 | // Great. We're done 156 | theGSM3ShieldV1ModemCore.setStatus(TRANSPARENT_CONNECTED); 157 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, true); 158 | theGSM3ShieldV1ModemCore.closeCommand(1); 159 | } 160 | else 161 | theGSM3ShieldV1ModemCore.closeCommand(3); 162 | } 163 | break; 164 | 165 | } 166 | } 167 | 168 | //Disconnect TCP main function. 169 | int GSM3ShieldV1ClientProvider::disconnectTCP(bool client1Server0, int id_socket) 170 | { 171 | // id Socket does not really mean anything, in this case we have 172 | // only one socket running 173 | theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP); 174 | 175 | // If we are not closed, launch the command 176 | //[ZZ] if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 177 | // { 178 | delay(1000); 179 | theGSM3ShieldV1ModemCore.print("+++"); 180 | delay(1000); 181 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE")); 182 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 183 | // } 184 | // Looks like it runs everytime, so we simply flush to death and go on 185 | do 186 | { 187 | // Empty the local buffer, and tell the modem to XON 188 | // If meanwhile we receive a DISCONNECT we should detect it as URC. 189 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 190 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 191 | // Give some time for the buffer to refill 192 | delay(100); 193 | theGSM3ShieldV1ModemCore.closeCommand(1); 194 | }while(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()>0); 195 | 196 | theGSM3ShieldV1ModemCore.unRegisterUMProvider(this); 197 | return theGSM3ShieldV1ModemCore.getCommandError(); 198 | } 199 | 200 | 201 | //Write socket first chain main function. 202 | void GSM3ShieldV1ClientProvider::beginWriteSocket(bool client1Server0, int id_socket) 203 | { 204 | } 205 | 206 | 207 | //Write socket next chain function. 208 | void GSM3ShieldV1ClientProvider::writeSocket(const char* buf) 209 | { 210 | if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 211 | theGSM3ShieldV1ModemCore.print(buf); 212 | } 213 | 214 | //Write socket character function. 215 | void GSM3ShieldV1ClientProvider::writeSocket(uint8_t c) 216 | { 217 | if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 218 | theGSM3ShieldV1ModemCore.print((char)c); 219 | } 220 | 221 | //Write socket last chain main function. 222 | void GSM3ShieldV1ClientProvider::endWriteSocket() 223 | { 224 | } 225 | 226 | 227 | //Available socket main function. 228 | int GSM3ShieldV1ClientProvider::availableSocket(bool client1Server0, int id_socket) 229 | { 230 | 231 | if(!(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED)) 232 | theGSM3ShieldV1ModemCore.closeCommand(4); 233 | 234 | if(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()) 235 | theGSM3ShieldV1ModemCore.closeCommand(1); 236 | else 237 | theGSM3ShieldV1ModemCore.closeCommand(4); 238 | 239 | return theGSM3ShieldV1ModemCore.getCommandError(); 240 | } 241 | 242 | int GSM3ShieldV1ClientProvider::readSocket() 243 | { 244 | char charSocket; 245 | 246 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0) 247 | { 248 | return 0; 249 | } 250 | 251 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read(); 252 | 253 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==100) 254 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 255 | 256 | return charSocket; 257 | 258 | } 259 | 260 | //Read socket main function. 261 | int GSM3ShieldV1ClientProvider::peekSocket() 262 | { 263 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0); 264 | } 265 | 266 | 267 | //Flush SMS main function. 268 | void GSM3ShieldV1ClientProvider::flushSocket() 269 | { 270 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET); 271 | 272 | flushSocketContinue(); 273 | } 274 | 275 | //Send SMS continue function. 276 | void GSM3ShieldV1ClientProvider::flushSocketContinue() 277 | { 278 | // If we have incomed data 279 | if(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()>0) 280 | { 281 | // Empty the local buffer, and tell the modem to XON 282 | // If meanwhile we receive a DISCONNECT we should detect it as URC. 283 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 284 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 285 | } 286 | else 287 | { 288 | //We're done 289 | theGSM3ShieldV1ModemCore.closeCommand(1); 290 | } 291 | } 292 | 293 | // URC recognize. 294 | // Yes, we recognize "closes" in client mode 295 | bool GSM3ShieldV1ClientProvider::recognizeUnsolicitedEvent(byte oldTail) 296 | { 297 | char auxLocate [12]; 298 | prepareAuxLocate(PSTR("CLOSED"), auxLocate); 299 | 300 | if((theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) & theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, false, false)) 301 | { 302 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 303 | theGSM3ShieldV1ModemCore.unRegisterUMProvider(this); 304 | return true; 305 | } 306 | 307 | return false; 308 | } 309 | 310 | int GSM3ShieldV1ClientProvider::getSocket(int socket) 311 | { 312 | return 0; 313 | } 314 | 315 | void GSM3ShieldV1ClientProvider::releaseSocket(int socket) 316 | { 317 | 318 | } 319 | 320 | bool GSM3ShieldV1ClientProvider::getStatusSocketClient(uint8_t socket) 321 | { 322 | return (theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED); 323 | 324 | }; 325 | 326 | 327 | 328 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1AccessProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | #include "GSM3IO.h" 37 | 38 | #define __TOUTSHUTDOWN__ 5000 39 | #define __TOUTMODEMCONFIGURATION__ 5000//equivalent to 30000 because of time in interrupt routine. 40 | #define __TOUTAT__ 1000 41 | 42 | const char _command_AT[] PROGMEM = "AT"; 43 | const char _command_CGREG[] PROGMEM = "AT+CGREG?"; 44 | 45 | 46 | GSM3ShieldV1AccessProvider::GSM3ShieldV1AccessProvider(bool debug) 47 | { 48 | theGSM3ShieldV1ModemCore.setDebug(debug); 49 | 50 | } 51 | 52 | void GSM3ShieldV1AccessProvider::manageResponse(byte from, byte to) 53 | { 54 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 55 | { 56 | case MODEMCONFIG: 57 | ModemConfigurationContinue(); 58 | break; 59 | case ALIVETEST: 60 | isModemAliveContinue(); 61 | break; 62 | } 63 | } 64 | 65 | ///////////////////////////////////////////////////////CONFIGURATION FUNCTIONS/////////////////////////////////////////////////////////////////// 66 | 67 | // Begin 68 | // Restart or start the modem 69 | // May be synchronous 70 | GSM3_NetworkStatus_t GSM3ShieldV1AccessProvider::begin(char* pin, bool restart, bool synchronous) 71 | { 72 | pinMode(__RESETPIN__, OUTPUT); 73 | 74 | #ifdef TTOPEN_V1 75 | pinMode(__POWERPIN__, OUTPUT); 76 | digitalWrite(__POWERPIN__, HIGH); 77 | #endif 78 | 79 | // If asked for modem restart, restart 80 | if (restart) 81 | HWrestart(); 82 | else 83 | HWstart(); 84 | 85 | theGSM3ShieldV1ModemCore.gss.begin(9600); 86 | // Launch modem configuration commands 87 | ModemConfiguration(pin); 88 | // If synchronous, wait till ModemConfiguration is over 89 | if(synchronous) 90 | { 91 | // if we shorten this delay, the command fails 92 | while(ready()==0) 93 | delay(1000); 94 | } 95 | return getStatus(); 96 | } 97 | 98 | //HWrestart. 99 | int GSM3ShieldV1AccessProvider::HWrestart() 100 | { 101 | #ifdef TTOPEN_V1 102 | digitalWrite(__POWERPIN__, HIGH); 103 | delay(1000); 104 | #endif 105 | 106 | theGSM3ShieldV1ModemCore.setStatus(IDLE); 107 | digitalWrite(__RESETPIN__, HIGH); 108 | delay(12000); 109 | digitalWrite(__RESETPIN__, LOW); 110 | delay(1000); 111 | return 1; //configandwait(pin); 112 | } 113 | 114 | //HWrestart. 115 | int GSM3ShieldV1AccessProvider::HWstart() 116 | { 117 | 118 | theGSM3ShieldV1ModemCore.setStatus(IDLE); 119 | digitalWrite(__RESETPIN__, HIGH); 120 | delay(2000); 121 | digitalWrite(__RESETPIN__, LOW); 122 | //delay(1000); 123 | 124 | return 1; //configandwait(pin); 125 | } 126 | 127 | //Initial configuration main function. 128 | int GSM3ShieldV1AccessProvider::ModemConfiguration(char* pin) 129 | { 130 | theGSM3ShieldV1ModemCore.setPhoneNumber(pin); 131 | theGSM3ShieldV1ModemCore.openCommand(this,MODEMCONFIG); 132 | theGSM3ShieldV1ModemCore.setStatus(CONNECTING); 133 | ModemConfigurationContinue(); 134 | return theGSM3ShieldV1ModemCore.getCommandError(); 135 | } 136 | 137 | //Initial configuration continue function. 138 | void GSM3ShieldV1AccessProvider::ModemConfigurationContinue() 139 | { 140 | bool resp; 141 | 142 | // 1: Send AT 143 | // 2: Wait AT OK and SetPin or CGREG 144 | // 3: Wait Pin OK and CGREG 145 | // 4: Wait CGREG and Flow SW control or CGREG 146 | // 5: Wait IFC OK and SMS Text Mode 147 | // 6: Wait SMS text Mode OK and Calling line identification 148 | // 7: Wait Calling Line Id OK and Echo off 149 | // 8: Wait for OK and COLP command for connecting line identification. 150 | // 9: Wait for OK. 151 | int ct=theGSM3ShieldV1ModemCore.getCommandCounter(); 152 | if(ct==1) 153 | { 154 | // Launch AT 155 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 156 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT); 157 | } 158 | else if(ct==2) 159 | { 160 | // Wait for AT - OK. 161 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 162 | { 163 | if(resp) 164 | { 165 | // OK received 166 | if(theGSM3ShieldV1ModemCore.getPhoneNumber() && (theGSM3ShieldV1ModemCore.getPhoneNumber()[0]!=0)) 167 | { 168 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CPIN="), false); 169 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 170 | theGSM3ShieldV1ModemCore.genericCommand_rqc(theGSM3ShieldV1ModemCore.getPhoneNumber()); 171 | } 172 | else 173 | { 174 | //DEBUG 175 | //Serial.println("AT+CGREG?"); 176 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 177 | theGSM3ShieldV1ModemCore.takeMilliseconds(); 178 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG); 179 | } 180 | } 181 | else theGSM3ShieldV1ModemCore.closeCommand(3); 182 | } 183 | } 184 | else if(ct==3) 185 | { 186 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 187 | { 188 | if(resp) 189 | { 190 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 191 | theGSM3ShieldV1ModemCore.takeMilliseconds(); 192 | theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000); 193 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG); 194 | } 195 | else theGSM3ShieldV1ModemCore.closeCommand(3); 196 | } 197 | } 198 | else if(ct==4) 199 | { 200 | char auxLocate1 [12]; 201 | char auxLocate2 [12]; 202 | prepareAuxLocate(PSTR("+CGREG: 0,1"), auxLocate1); 203 | prepareAuxLocate(PSTR("+CGREG: 0,5"), auxLocate2); 204 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate1, auxLocate2)) 205 | { 206 | if(resp) 207 | { 208 | theGSM3ShieldV1ModemCore.setCommandCounter(5); 209 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+IFC=1,1")); 210 | } 211 | else 212 | { 213 | // If not, launch command again 214 | if(theGSM3ShieldV1ModemCore.takeMilliseconds() > __TOUTMODEMCONFIGURATION__) 215 | { 216 | theGSM3ShieldV1ModemCore.closeCommand(3); 217 | } 218 | else 219 | { 220 | theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000); 221 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG); 222 | } 223 | } 224 | } 225 | } 226 | else if(ct==5) 227 | { 228 | // 5: Wait IFC OK 229 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 230 | { 231 | //Delay for SW flow control being active. 232 | theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000); 233 | // 9: SMS Text Mode 234 | theGSM3ShieldV1ModemCore.setCommandCounter(6); 235 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGF=1")); 236 | } 237 | } 238 | else if(ct==6) 239 | { 240 | // 6: Wait SMS text Mode OK 241 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 242 | { 243 | //Calling line identification 244 | theGSM3ShieldV1ModemCore.setCommandCounter(7); 245 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLIP=1")); 246 | } 247 | } 248 | else if(ct==7) 249 | { 250 | // 7: Wait Calling Line Id OK 251 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 252 | { 253 | // Echo off 254 | theGSM3ShieldV1ModemCore.setCommandCounter(8); 255 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATE0")); 256 | } 257 | } 258 | else if(ct==8) 259 | { 260 | // 8: Wait ATEO OK, send COLP 261 | // In Arduino Mega, attention, take away the COLP step 262 | // It looks as we can only have 8 steps 263 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 264 | { 265 | theGSM3ShieldV1ModemCore.setCommandCounter(9); 266 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+COLP=1")); 267 | } 268 | } 269 | else if(ct==9) 270 | { 271 | // 9: Wait ATCOLP OK 272 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 273 | { 274 | if (resp) 275 | { 276 | theGSM3ShieldV1ModemCore.setStatus(GSM_READY); 277 | theGSM3ShieldV1ModemCore.closeCommand(1); 278 | } 279 | else theGSM3ShieldV1ModemCore.closeCommand(3); 280 | } 281 | } 282 | } 283 | 284 | //Alive Test main function. 285 | int GSM3ShieldV1AccessProvider::isAccessAlive() 286 | { 287 | theGSM3ShieldV1ModemCore.setCommandError(0); 288 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 289 | theGSM3ShieldV1ModemCore.openCommand(this,ALIVETEST); 290 | isModemAliveContinue(); 291 | return theGSM3ShieldV1ModemCore.getCommandError(); 292 | } 293 | 294 | //Alive Test continue function. 295 | void GSM3ShieldV1AccessProvider::isModemAliveContinue() 296 | { 297 | bool rsp; 298 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 299 | case 1: 300 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT); 301 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 302 | break; 303 | case 2: 304 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(rsp)) 305 | { 306 | if (rsp) theGSM3ShieldV1ModemCore.closeCommand(1); 307 | else theGSM3ShieldV1ModemCore.closeCommand(3); 308 | } 309 | break; 310 | } 311 | } 312 | 313 | //Shutdown. 314 | bool GSM3ShieldV1AccessProvider::shutdown() 315 | { 316 | unsigned long m; 317 | bool resp; 318 | char auxLocate [18]; 319 | 320 | // It makes no sense to have an asynchronous shutdown 321 | pinMode(__RESETPIN__, OUTPUT); 322 | digitalWrite(__RESETPIN__, HIGH); 323 | delay(1500); 324 | digitalWrite(__RESETPIN__, LOW); 325 | theGSM3ShieldV1ModemCore.setStatus(IDLE); 326 | theGSM3ShieldV1ModemCore.gss.close(); 327 | 328 | m=millis(); 329 | prepareAuxLocate(PSTR("POWER DOWN"), auxLocate); 330 | while((millis()-m) < __TOUTSHUTDOWN__) 331 | { 332 | delay(1); 333 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate)) 334 | return resp; 335 | } 336 | return false; 337 | } 338 | 339 | //Secure shutdown. 340 | bool GSM3ShieldV1AccessProvider::secureShutdown() 341 | { 342 | // It makes no sense to have an asynchronous shutdown 343 | pinMode(__RESETPIN__, OUTPUT); 344 | digitalWrite(__RESETPIN__, HIGH); 345 | delay(900); 346 | digitalWrite(__RESETPIN__, LOW); 347 | theGSM3ShieldV1ModemCore.setStatus(OFF); 348 | theGSM3ShieldV1ModemCore.gss.close(); 349 | 350 | #ifdef TTOPEN_V1 351 | _delay_ms(12000); 352 | digitalWrite(__POWERPIN__, LOW); 353 | #endif 354 | 355 | return true; 356 | } 357 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1MultiServerProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | #include 37 | 38 | #define __NCLIENTS_MAX__ 3 39 | 40 | const char _command_QILOCIP[] PROGMEM = "AT+QILOCIP"; 41 | 42 | GSM3ShieldV1MultiServerProvider::GSM3ShieldV1MultiServerProvider() 43 | { 44 | theGSM3MobileServerProvider=this; 45 | socketsAsServer=0; 46 | socketsAccepted=0; 47 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 48 | }; 49 | 50 | //Response management. 51 | void GSM3ShieldV1MultiServerProvider::manageResponse(byte from, byte to) 52 | { 53 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 54 | { 55 | case NONE: 56 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 57 | break; 58 | case CONNECTSERVER: 59 | connectTCPServerContinue(); 60 | break; 61 | case GETIP: 62 | getIPContinue(); 63 | break; 64 | } 65 | } 66 | 67 | //Connect Server main function. 68 | int GSM3ShieldV1MultiServerProvider::connectTCPServer(int port) 69 | { 70 | // We forget about LocalIP as it has no real use, the modem does whatever it likes 71 | theGSM3ShieldV1ModemCore.setPort(port); 72 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTSERVER); 73 | connectTCPServerContinue(); 74 | return theGSM3ShieldV1ModemCore.getCommandError(); 75 | } 76 | 77 | //Connect Server continue function. 78 | void GSM3ShieldV1MultiServerProvider::connectTCPServerContinue() 79 | { 80 | 81 | bool resp; 82 | // 1: Read Local IP "AT+QILOCIP" 83 | // 2: Waiting for IP and Set local port "AT+QILPORT" 84 | // 3: Waiting for QILPOR OK andConfigure as server "AT+QISERVER" 85 | // 4: Wait for SERVER OK 86 | 87 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 88 | case 1: 89 | //"AT+QILOCIP." 90 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_QILOCIP); 91 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 92 | break; 93 | case 2: 94 | //Not IP storing but the command is necessary. 95 | //if(parseQILOCIP_rsp(local_IP, local_IP_Length, resp)) 96 | // This awful trick saves some RAM bytes 97 | char aux[3]; 98 | aux[0]='\r';aux[1]='\n';aux[2]=0; 99 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux)) 100 | { 101 | //Response received 102 | if(resp) 103 | { 104 | // Great. Go for the next step 105 | // AT+QILPORT 106 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILPORT=\"TCP\","),false); 107 | theGSM3ShieldV1ModemCore.print( theGSM3ShieldV1ModemCore.getPort()); 108 | theGSM3ShieldV1ModemCore.print('\r'); 109 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 110 | } 111 | else theGSM3ShieldV1ModemCore.closeCommand(3); 112 | } 113 | break; 114 | case 3: 115 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 116 | { 117 | // Response received 118 | if(resp) 119 | { 120 | // OK received 121 | // Great. Go for the next step 122 | // AT+QISERVER 123 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISERVER=0,"),false); 124 | theGSM3ShieldV1ModemCore.print(__NCLIENTS_MAX__); 125 | theGSM3ShieldV1ModemCore.print('\r'); 126 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 127 | } 128 | else theGSM3ShieldV1ModemCore.closeCommand(3); 129 | } 130 | break; 131 | case 4: 132 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 133 | { 134 | // Response received 135 | // OK received, kathapoon, chessespoon 136 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 137 | else theGSM3ShieldV1ModemCore.closeCommand(3); 138 | } 139 | break; 140 | } 141 | } 142 | 143 | //QILOCIP parse. 144 | bool GSM3ShieldV1MultiServerProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp) 145 | { 146 | if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength))) 147 | rsp = false; 148 | else 149 | rsp = true; 150 | return true; 151 | } 152 | 153 | //Get IP main function. 154 | int GSM3ShieldV1MultiServerProvider::getIP(char* LocalIP, int LocalIPlength) 155 | { 156 | theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP); 157 | theGSM3ShieldV1ModemCore.setPort(LocalIPlength); 158 | theGSM3ShieldV1ModemCore.openCommand(this,GETIP); 159 | getIPContinue(); 160 | return theGSM3ShieldV1ModemCore.getCommandError(); 161 | } 162 | 163 | void GSM3ShieldV1MultiServerProvider::getIPContinue() 164 | { 165 | 166 | bool resp; 167 | // 1: Read Local IP "AT+QILOCIP" 168 | // 2: Waiting for IP. 169 | 170 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 171 | case 1: 172 | //AT+QILOCIP 173 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_QILOCIP); 174 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 175 | break; 176 | case 2: 177 | if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp)) 178 | { 179 | if (resp) 180 | theGSM3ShieldV1ModemCore.closeCommand(1); 181 | else 182 | theGSM3ShieldV1ModemCore.closeCommand(3); 183 | } 184 | break; 185 | } 186 | } 187 | 188 | bool GSM3ShieldV1MultiServerProvider::getSocketAsServerModemStatus(int s) 189 | { 190 | if (socketsAccepted&(0x0001< 35 | #include 36 | 37 | const char _command_CGATT[] PROGMEM = "AT+CGATT="; 38 | const char _command_SEPARATOR[] PROGMEM = "\",\""; 39 | 40 | //Attach GPRS main function. 41 | GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::attachGPRS(char* apn, char* user_name, char* password, bool synchronous) 42 | { 43 | user = user_name; 44 | passwd = password; 45 | // A sad use of byte reuse 46 | theGSM3ShieldV1ModemCore.setPhoneNumber(apn); 47 | 48 | theGSM3ShieldV1ModemCore.openCommand(this,ATTACHGPRS); 49 | theGSM3ShieldV1ModemCore.setStatus(CONNECTING); 50 | 51 | attachGPRSContinue(); 52 | 53 | // If synchronous, wait till attach is over, or not. 54 | if(synchronous) 55 | { 56 | // if we shorten this delay, the command fails 57 | while(ready()==0) 58 | delay(100); 59 | } 60 | 61 | return theGSM3ShieldV1ModemCore.getStatus(); 62 | } 63 | 64 | //Atthach GPRS continue function. 65 | void GSM3ShieldV1DataNetworkProvider::attachGPRSContinue() 66 | { 67 | bool resp; 68 | // 1: Attach to GPRS service "AT+CGATT=1" 69 | // 2: Wait attach OK and Set the context 0 as FGCNT "AT+QIFGCNT=0" 70 | // 3: Wait context OK and Set bearer type as GPRS, APN, user name and pasword "AT+QICSGP=1..." 71 | // 4: Wait bearer OK and Enable the function of MUXIP "AT+QIMUX=1" 72 | // 5: Wait for disable MUXIP OK and Set the session mode as non transparent "AT+QIMODE=0" 73 | // 6: Wait for session mode OK and Enable notification when data received "AT+QINDI=1" 74 | // 8: Wait domain name OK and Register the TCP/IP stack "AT+QIREGAPP" 75 | // 9: Wait for Register OK and Activate FGCNT "AT+QIACT" 76 | // 10: Wait for activate OK 77 | 78 | int ct=theGSM3ShieldV1ModemCore.getCommandCounter(); 79 | if(ct==1) 80 | { 81 | //AT+CGATT 82 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGATT,false); 83 | theGSM3ShieldV1ModemCore.print(1); 84 | theGSM3ShieldV1ModemCore.print('\r'); 85 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 86 | } 87 | else if(ct==2) 88 | { 89 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 90 | { 91 | if(resp) 92 | { 93 | //AT+QIFGCNT 94 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIFGCNT=0")); 95 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 96 | } 97 | else theGSM3ShieldV1ModemCore.closeCommand(3); 98 | } 99 | } 100 | else if(ct==3) 101 | { 102 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 103 | { 104 | if(resp) 105 | { 106 | // Great. Go for the next step 107 | //DEBUG 108 | //Serial.println("AT+QICSGP."); 109 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICSGP=1,\""),false); 110 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 111 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_SEPARATOR,false); 112 | theGSM3ShieldV1ModemCore.print(user); 113 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_SEPARATOR,false); 114 | theGSM3ShieldV1ModemCore.print(passwd); 115 | theGSM3ShieldV1ModemCore.print("\"\r"); 116 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 117 | } 118 | else theGSM3ShieldV1ModemCore.closeCommand(3); 119 | } 120 | } 121 | else if(ct==4) 122 | { 123 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 124 | { 125 | if(resp) 126 | { 127 | // AT+QIMUX=1 for multisocket 128 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIMUX=0")); 129 | theGSM3ShieldV1ModemCore.setCommandCounter(5); 130 | } 131 | else theGSM3ShieldV1ModemCore.closeCommand(3); 132 | } 133 | } 134 | else if(ct==5) 135 | { 136 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 137 | { 138 | if(resp) 139 | { 140 | //AT+QIMODE=0 for multisocket 141 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIMODE=1")); 142 | theGSM3ShieldV1ModemCore.setCommandCounter(6); 143 | } 144 | else theGSM3ShieldV1ModemCore.closeCommand(3); 145 | } 146 | } 147 | else if(ct==6) 148 | { 149 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 150 | { 151 | if(resp) 152 | { 153 | // AT+QINDI=1 154 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QINDI=1")); 155 | theGSM3ShieldV1ModemCore.setCommandCounter(8); 156 | } 157 | else theGSM3ShieldV1ModemCore.closeCommand(3); 158 | } 159 | } 160 | else if(ct==8) 161 | { 162 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 163 | { 164 | if(resp) 165 | { 166 | // AT+QIREGAPP 167 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIREGAPP")); 168 | theGSM3ShieldV1ModemCore.setCommandCounter(9); 169 | } 170 | else theGSM3ShieldV1ModemCore.closeCommand(3); 171 | } 172 | } 173 | else if(ct==9) 174 | { 175 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 176 | { 177 | if(resp) 178 | { 179 | // AT+QIACT 180 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIACT")); 181 | theGSM3ShieldV1ModemCore.setCommandCounter(10); 182 | } 183 | else theGSM3ShieldV1ModemCore.closeCommand(3); 184 | } 185 | } 186 | else if(ct==10) 187 | { 188 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 189 | { 190 | if (resp) 191 | { 192 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 193 | theGSM3ShieldV1ModemCore.closeCommand(1); 194 | } 195 | else theGSM3ShieldV1ModemCore.closeCommand(3); 196 | } 197 | } 198 | } 199 | 200 | //Detach GPRS main function. 201 | GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::detachGPRS(bool synchronous) 202 | { 203 | theGSM3ShieldV1ModemCore.openCommand(this,DETACHGPRS); 204 | theGSM3ShieldV1ModemCore.setStatus(CONNECTING); 205 | detachGPRSContinue(); 206 | 207 | if(synchronous) 208 | { 209 | while(ready()==0) 210 | delay(1); 211 | } 212 | 213 | return theGSM3ShieldV1ModemCore.getStatus(); 214 | } 215 | 216 | void GSM3ShieldV1DataNetworkProvider::detachGPRSContinue() 217 | { 218 | bool resp; 219 | // 1: Detach to GPRS service "AT+CGATT=0" 220 | // 2: Wait dettach +PDP DEACT 221 | // 3: Wait for OK 222 | 223 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 224 | case 1: 225 | //AT+CGATT=0 226 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGATT,false); 227 | theGSM3ShieldV1ModemCore.print(0); 228 | theGSM3ShieldV1ModemCore.print('\r'); 229 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 230 | break; 231 | case 2: 232 | char auxLocate[12]; 233 | prepareAuxLocate(PSTR("+PDP DEACT"), auxLocate); 234 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 235 | { 236 | if(resp) 237 | { 238 | // Received +PDP DEACT; 239 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 240 | } 241 | else theGSM3ShieldV1ModemCore.closeCommand(3); 242 | } 243 | break; 244 | case 3: 245 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 246 | { 247 | // OK received 248 | if (resp) 249 | { 250 | theGSM3ShieldV1ModemCore.setStatus(GSM_READY); 251 | theGSM3ShieldV1ModemCore.closeCommand(1); 252 | } 253 | else theGSM3ShieldV1ModemCore.closeCommand(3); 254 | } 255 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 256 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 257 | break; 258 | } 259 | } 260 | 261 | //QILOCIP parse. 262 | bool GSM3ShieldV1DataNetworkProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp) 263 | { 264 | if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength))) 265 | rsp = false; 266 | else 267 | rsp = true; 268 | return true; 269 | } 270 | 271 | //Get IP main function. 272 | int GSM3ShieldV1DataNetworkProvider::getIP(char* LocalIP, int LocalIPlength) 273 | { 274 | theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP); 275 | theGSM3ShieldV1ModemCore.setPort(LocalIPlength); 276 | theGSM3ShieldV1ModemCore.openCommand(this,GETIP); 277 | getIPContinue(); 278 | return theGSM3ShieldV1ModemCore.getCommandError(); 279 | } 280 | 281 | void GSM3ShieldV1DataNetworkProvider::getIPContinue() 282 | { 283 | 284 | bool resp; 285 | // 1: Read Local IP "AT+QILOCIP" 286 | // 2: Waiting for IP. 287 | 288 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 289 | case 1: 290 | //AT+QILOCIP 291 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILOCIP")); 292 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 293 | break; 294 | case 2: 295 | if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp)) 296 | { 297 | if (resp) 298 | theGSM3ShieldV1ModemCore.closeCommand(1); 299 | else 300 | theGSM3ShieldV1ModemCore.closeCommand(3); 301 | } 302 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 303 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 304 | break; 305 | } 306 | } 307 | 308 | //Get IP with IPAddress object 309 | IPAddress GSM3ShieldV1DataNetworkProvider::getIPAddress() { 310 | char ip_temp[15]=""; 311 | getIP(ip_temp, 15); 312 | unsigned long m=millis(); 313 | 314 | while((millis()-m)<10*1000 && (!ready())){ 315 | // wait for a response from the modem: 316 | delay(100); 317 | } 318 | IPAddress ip; 319 | inet_aton(ip_temp, ip); 320 | return ip; 321 | } 322 | 323 | int GSM3ShieldV1DataNetworkProvider::inet_aton(const char* aIPAddrString, IPAddress& aResult) 324 | { 325 | // See if we've been given a valid IP address 326 | const char* p =aIPAddrString; 327 | while (*p && 328 | ( (*p == '.') || (*p >= '0') || (*p <= '9') )) 329 | { 330 | p++; 331 | } 332 | 333 | if (*p == '\0') 334 | { 335 | // It's looking promising, we haven't found any invalid characters 336 | p = aIPAddrString; 337 | int segment =0; 338 | int segmentValue =0; 339 | while (*p && (segment < 4)) 340 | { 341 | if (*p == '.') 342 | { 343 | // We've reached the end of a segment 344 | if (segmentValue > 255) 345 | { 346 | // You can't have IP address segments that don't fit in a byte 347 | return 0; 348 | } 349 | else 350 | { 351 | aResult[segment] = (byte)segmentValue; 352 | segment++; 353 | segmentValue = 0; 354 | } 355 | } 356 | else 357 | { 358 | // Next digit 359 | segmentValue = (segmentValue*10)+(*p - '0'); 360 | } 361 | p++; 362 | } 363 | // We've reached the end of address, but there'll still be the last 364 | // segment to deal with 365 | if ((segmentValue > 255) || (segment > 3)) 366 | { 367 | // You can't have IP address segments that don't fit in a byte, 368 | // or more than four segments 369 | return 0; 370 | } 371 | else 372 | { 373 | aResult[segment] = (byte)segmentValue; 374 | return 1; 375 | } 376 | } 377 | else 378 | { 379 | return 0; 380 | } 381 | } 382 | 383 | //Response management. 384 | void GSM3ShieldV1DataNetworkProvider::manageResponse(byte from, byte to) 385 | { 386 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 387 | { 388 | case ATTACHGPRS: 389 | attachGPRSContinue(); 390 | break; 391 | case DETACHGPRS: 392 | detachGPRSContinue(); 393 | break; 394 | case GETIP: 395 | getIPContinue(); 396 | break; 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /src/GSM3ShieldV1MultiClientProvider.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the GSM3 communications library for Arduino 3 | -- Multi-transport communications platform 4 | -- Fully asynchronous 5 | -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1 6 | -- Voice calls 7 | -- SMS 8 | -- TCP/IP connections 9 | -- HTTP basic clients 10 | 11 | This library has been developed by Telefónica Digital - PDI - 12 | - Physical Internet Lab, as part as its collaboration with 13 | Arduino and the Open Hardware Community. 14 | 15 | September-December 2012 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | The latest version of this library can always be found at 32 | https://github.com/BlueVia/Official-Arduino 33 | */ 34 | #include 35 | #include 36 | 37 | const char _command_MultiQISRVC[] PROGMEM = "AT+QISRVC="; 38 | 39 | #define __TOUTFLUSH__ 10000 40 | 41 | GSM3ShieldV1MultiClientProvider::GSM3ShieldV1MultiClientProvider() 42 | { 43 | theGSM3MobileClientProvider=this; 44 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 45 | }; 46 | 47 | //Response management. 48 | void GSM3ShieldV1MultiClientProvider::manageResponse(byte from, byte to) 49 | { 50 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 51 | { 52 | case XON: 53 | if (flagReadingSocket) 54 | { 55 | // flagReadingSocket = 0; 56 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 57 | } 58 | else theGSM3ShieldV1ModemCore.setOngoingCommand(NONE); 59 | break; 60 | case NONE: 61 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 62 | break; 63 | case CONNECTTCPCLIENT: 64 | connectTCPClientContinue(); 65 | break; 66 | case DISCONNECTTCP: 67 | disconnectTCPContinue(); 68 | break; 69 | case BEGINWRITESOCKET: 70 | beginWriteSocketContinue(); 71 | break; 72 | case ENDWRITESOCKET: 73 | endWriteSocketContinue(); 74 | break; 75 | case AVAILABLESOCKET: 76 | availableSocketContinue(); 77 | break; 78 | case FLUSHSOCKET: 79 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 80 | flushSocketContinue(); 81 | break; 82 | } 83 | } 84 | 85 | //Connect TCP main function. 86 | int GSM3ShieldV1MultiClientProvider::connectTCPClient(const char* server, int port, int id_socket) 87 | { 88 | theGSM3ShieldV1ModemCore.setPort(port); 89 | idSocket = id_socket; 90 | 91 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server); 92 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT); 93 | connectTCPClientContinue(); 94 | return theGSM3ShieldV1ModemCore.getCommandError(); 95 | } 96 | 97 | int GSM3ShieldV1MultiClientProvider::connectTCPClient(IPAddress add, int port, int id_socket) 98 | { 99 | remoteIP=add; 100 | theGSM3ShieldV1ModemCore.setPhoneNumber(0); 101 | return connectTCPClient(0, port, id_socket); 102 | } 103 | 104 | //Connect TCP continue function. 105 | void GSM3ShieldV1MultiClientProvider::connectTCPClientContinue() 106 | { 107 | bool resp; 108 | // 0: Dot or DNS notation activation 109 | // 1: Disable SW flow control 110 | // 2: Waiting for IFC OK 111 | // 3: Start-up TCP connection "AT+QIOPEN" 112 | // 4: Wait for connection OK 113 | // 5: Wait for CONNECT 114 | 115 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 116 | case 1: 117 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false); 118 | if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&& 119 | ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9')))) 120 | { 121 | theGSM3ShieldV1ModemCore.print('1'); 122 | theGSM3ShieldV1ModemCore.print('\r'); 123 | } 124 | else 125 | { 126 | theGSM3ShieldV1ModemCore.print('0'); 127 | theGSM3ShieldV1ModemCore.print('\r'); 128 | } 129 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 130 | break; 131 | case 2: 132 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 133 | { 134 | //Response received 135 | if(resp) 136 | { 137 | // AT+QIOPEN 138 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false); 139 | theGSM3ShieldV1ModemCore.print(idSocket); 140 | theGSM3ShieldV1ModemCore.print(",\"TCP\",\""); 141 | if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0) 142 | { 143 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 144 | } 145 | else 146 | { 147 | remoteIP.printTo(theGSM3ShieldV1ModemCore); 148 | } 149 | theGSM3ShieldV1ModemCore.print('"'); 150 | theGSM3ShieldV1ModemCore.print(','); 151 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort()); 152 | theGSM3ShieldV1ModemCore.print('\r'); 153 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 154 | } 155 | else theGSM3ShieldV1ModemCore.closeCommand(3); 156 | } 157 | break; 158 | 159 | case 3: 160 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 161 | { 162 | // Response received 163 | if(resp) 164 | { 165 | // OK Received 166 | // Great. Go for the next step 167 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 168 | } 169 | else theGSM3ShieldV1ModemCore.closeCommand(3); 170 | } 171 | break; 172 | case 4: 173 | char auxLocate [12]; 174 | prepareAuxLocate(PSTR("CONNECT OK"), auxLocate); 175 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate)) 176 | { 177 | // Response received 178 | if(resp) 179 | { 180 | // Received CONNECT OK 181 | // Great. We're done 182 | theGSM3ShieldV1ModemCore.closeCommand(1); 183 | } 184 | else 185 | theGSM3ShieldV1ModemCore.closeCommand(3); 186 | } 187 | break; 188 | 189 | } 190 | } 191 | 192 | //Disconnect TCP main function. 193 | int GSM3ShieldV1MultiClientProvider::disconnectTCP(bool client1Server0, int id_socket) 194 | { 195 | idSocket = id_socket; 196 | 197 | // First of all, we will flush the socket synchronously 198 | unsigned long m; 199 | m=millis(); 200 | flushSocket(); 201 | while(((millis()-m)< __TOUTFLUSH__ )&&(ready()==0)) 202 | delay(10); 203 | 204 | // Could not flush the communications... strange 205 | if(ready()==0) 206 | { 207 | theGSM3ShieldV1ModemCore.setCommandError(2); 208 | return theGSM3ShieldV1ModemCore.getCommandError(); 209 | } 210 | 211 | // Set up the command 212 | client1_server0 = client1Server0; 213 | flagReadingSocket=0; 214 | theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP); 215 | disconnectTCPContinue(); 216 | return theGSM3ShieldV1ModemCore.getCommandError(); 217 | } 218 | 219 | //Disconnect TCP continue function 220 | void GSM3ShieldV1MultiClientProvider::disconnectTCPContinue() 221 | { 222 | bool resp; 223 | // 1: Send AT+QISRVC 224 | // 2: "AT+QICLOSE" 225 | // 3: Wait for OK 226 | 227 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 228 | case 1: 229 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false); 230 | if (client1_server0) theGSM3ShieldV1ModemCore.print('1'); 231 | else theGSM3ShieldV1ModemCore.print('2'); 232 | theGSM3ShieldV1ModemCore.print('\r'); 233 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 234 | break; 235 | case 2: 236 | // Parse response to QISRVC 237 | theGSM3ShieldV1ModemCore.genericParse_rsp(resp); 238 | if(resp) 239 | { 240 | // Send QICLOSE command 241 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE="),false); 242 | theGSM3ShieldV1ModemCore.print(idSocket); 243 | theGSM3ShieldV1ModemCore.print('\r'); 244 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 245 | } 246 | else 247 | theGSM3ShieldV1ModemCore.closeCommand(3); 248 | break; 249 | case 3: 250 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 251 | { 252 | theGSM3ShieldV1ModemCore.setCommandCounter(0); 253 | if (resp) 254 | theGSM3ShieldV1ModemCore.closeCommand(1); 255 | else 256 | theGSM3ShieldV1ModemCore.closeCommand(3); 257 | } 258 | break; 259 | } 260 | } 261 | 262 | //Write socket first chain main function. 263 | void GSM3ShieldV1MultiClientProvider::beginWriteSocket(bool client1Server0, int id_socket) 264 | { 265 | idSocket = id_socket; 266 | client1_server0 = client1Server0; 267 | theGSM3ShieldV1ModemCore.openCommand(this,BEGINWRITESOCKET); 268 | beginWriteSocketContinue(); 269 | } 270 | 271 | //Write socket first chain continue function. 272 | void GSM3ShieldV1MultiClientProvider::beginWriteSocketContinue() 273 | { 274 | bool resp; 275 | // 1: Send AT+QISRVC 276 | // 2: Send AT+QISEND 277 | // 3: wait for > and Write text 278 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 279 | case 1: 280 | // AT+QISRVC 281 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false); 282 | if (client1_server0) 283 | theGSM3ShieldV1ModemCore.print('1'); 284 | else 285 | theGSM3ShieldV1ModemCore.print('2'); 286 | theGSM3ShieldV1ModemCore.print('\r'); 287 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 288 | break; 289 | case 2: 290 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 291 | { 292 | // Response received 293 | if(resp) 294 | { 295 | // AT+QISEND 296 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISEND="), false); 297 | theGSM3ShieldV1ModemCore.print(idSocket); 298 | theGSM3ShieldV1ModemCore.print('\r'); 299 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 300 | } 301 | else 302 | { 303 | theGSM3ShieldV1ModemCore.closeCommand(3); 304 | } 305 | } 306 | break; 307 | case 3: 308 | char aux[2]; 309 | aux[0]='>'; 310 | aux[1]=0; 311 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux)) 312 | { 313 | if(resp) 314 | { 315 | // Received ">" 316 | theGSM3ShieldV1ModemCore.closeCommand(1); 317 | } 318 | else 319 | { 320 | theGSM3ShieldV1ModemCore.closeCommand(3); 321 | } 322 | } 323 | break; 324 | } 325 | } 326 | 327 | //Write socket next chain function. 328 | void GSM3ShieldV1MultiClientProvider::writeSocket(const char* buf) 329 | { 330 | theGSM3ShieldV1ModemCore.print(buf); 331 | } 332 | 333 | //Write socket character function. 334 | void GSM3ShieldV1MultiClientProvider::writeSocket(char c) 335 | { 336 | theGSM3ShieldV1ModemCore.print(c); 337 | } 338 | 339 | //Write socket last chain main function. 340 | void GSM3ShieldV1MultiClientProvider::endWriteSocket() 341 | { 342 | theGSM3ShieldV1ModemCore.openCommand(this,ENDWRITESOCKET); 343 | endWriteSocketContinue(); 344 | } 345 | 346 | //Write socket last chain continue function. 347 | void GSM3ShieldV1MultiClientProvider::endWriteSocketContinue() 348 | { 349 | bool resp; 350 | // 1: Write text (ctrl-Z) 351 | // 2: Wait for OK 352 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 353 | case 1: 354 | theGSM3ShieldV1ModemCore.write(26); // Ctrl-Z 355 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 356 | break; 357 | case 2: 358 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 359 | { 360 | // OK received 361 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 362 | else theGSM3ShieldV1ModemCore.closeCommand(3); 363 | } 364 | break; 365 | } 366 | } 367 | 368 | //Available socket main function. 369 | int GSM3ShieldV1MultiClientProvider::availableSocket(bool client1Server0, int id_socket) 370 | { 371 | if(flagReadingSocket==1) 372 | { 373 | theGSM3ShieldV1ModemCore.setCommandError(1); 374 | return 1; 375 | } 376 | client1_server0 = client1Server0; 377 | idSocket = id_socket; 378 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET); 379 | availableSocketContinue(); 380 | return theGSM3ShieldV1ModemCore.getCommandError(); 381 | } 382 | 383 | //Available socket continue function. 384 | void GSM3ShieldV1MultiClientProvider::availableSocketContinue() 385 | { 386 | bool resp; 387 | // 1: AT+QIRD 388 | // 2: Wait for OK and Next necessary AT+QIRD 389 | 390 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 391 | case 1: 392 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIRD=0,"),false); 393 | if (client1_server0) 394 | theGSM3ShieldV1ModemCore.print('1'); 395 | else 396 | theGSM3ShieldV1ModemCore.print('2'); 397 | theGSM3ShieldV1ModemCore.print(','); 398 | theGSM3ShieldV1ModemCore.print(idSocket); 399 | theGSM3ShieldV1ModemCore.print(",1500"); 400 | // theGSM3ShieldV1ModemCore.print(",120"); 401 | theGSM3ShieldV1ModemCore.print('\r'); 402 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 403 | break; 404 | case 2: 405 | if(parseQIRD_head(resp)) 406 | { 407 | if (!resp) 408 | { 409 | theGSM3ShieldV1ModemCore.closeCommand(4); 410 | } 411 | else 412 | { 413 | flagReadingSocket=1; 414 | theGSM3ShieldV1ModemCore.closeCommand(1); 415 | } 416 | } 417 | else 418 | { 419 | theGSM3ShieldV1ModemCore.closeCommand(3); 420 | } 421 | break; 422 | } 423 | } 424 | 425 | //Read Socket Parse head. 426 | bool GSM3ShieldV1MultiClientProvider::parseQIRD_head(bool& rsp) 427 | { 428 | char _qird [8]; 429 | prepareAuxLocate(PSTR("+QIRD:"), _qird); 430 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 431 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(_qird)) 432 | { 433 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true); 434 | // Saving more memory, reuse _qird 435 | _qird[0]='\n'; 436 | _qird[1]=0; 437 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true); 438 | rsp = true; 439 | return true; 440 | } 441 | else if(theGSM3ShieldV1ModemCore.theBuffer().locate("OK")) 442 | { 443 | rsp = false; 444 | return true; 445 | } 446 | else 447 | { 448 | rsp = false; 449 | return false; 450 | } 451 | } 452 | /* 453 | //Read socket main function. 454 | int GSM3ShieldV1MultiClientProvider::readSocket() 455 | { 456 | char charSocket; 457 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read(); 458 | //Case buffer not full 459 | if (!fullBufferSocket) 460 | { 461 | //The last part of the buffer after data is CRLFOKCRLF 462 | if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125) 463 | { 464 | //Start again availableSocket function. 465 | flagReadingSocket=0; 466 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET); 467 | availableSocketContinue(); 468 | } 469 | } 470 | else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127) 471 | { 472 | // The buffer is full, no more action is possible until we have read() 473 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 474 | flagReadingSocket = 1; 475 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 476 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 477 | //A small delay to assure data received after xon. 478 | delay(10); 479 | } 480 | //To distinguish the case no more available data in socket. 481 | if (ready()==1) 482 | return charSocket; 483 | else 484 | return 0; 485 | } 486 | */ 487 | int GSM3ShieldV1MultiClientProvider::readSocket() 488 | { 489 | char charSocket; 490 | 491 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0) 492 | { 493 | Serial.println();Serial.println("*"); 494 | return 0; 495 | } 496 | 497 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read(); 498 | //Case buffer not full 499 | if (!fullBufferSocket) 500 | { 501 | //The last part of the buffer after data is CRLFOKCRLF 502 | if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125) 503 | { 504 | //Start again availableSocket function. 505 | flagReadingSocket=0; 506 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET); 507 | availableSocketContinue(); 508 | } 509 | } 510 | else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()>=100) 511 | { 512 | // The buffer was full, we have to let the data flow again 513 | // theGSM3ShieldV1ModemCore.theBuffer().flush(); 514 | flagReadingSocket = 1; 515 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 516 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 517 | //A small delay to assure data received after xon. 518 | delay(100); 519 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes() >=6) 520 | fullBufferSocket=false; 521 | } 522 | 523 | return charSocket; 524 | 525 | } 526 | 527 | //Read socket main function. 528 | int GSM3ShieldV1MultiClientProvider::peekSocket() 529 | { 530 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0); 531 | } 532 | 533 | 534 | //Flush SMS main function. 535 | void GSM3ShieldV1MultiClientProvider::flushSocket() 536 | { 537 | flagReadingSocket=0; 538 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET); 539 | flushSocketContinue(); 540 | } 541 | 542 | //Send SMS continue function. 543 | void GSM3ShieldV1MultiClientProvider::flushSocketContinue() 544 | { 545 | bool resp; 546 | // 1: Deleting SMS 547 | // 2: wait for OK 548 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 549 | case 1: 550 | //DEBUG 551 | //Serial.println("Flushing Socket."); 552 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 553 | if (fullBufferSocket) 554 | { 555 | //Serial.println("Buffer flushed."); 556 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 557 | } 558 | else 559 | { 560 | //Serial.println("Socket flushed completely."); 561 | theGSM3ShieldV1ModemCore.closeCommand(1); 562 | } 563 | break; 564 | } 565 | } 566 | 567 | //URC recognize. 568 | // Momentarily, we will not recognize "closes" in client mode 569 | bool GSM3ShieldV1MultiClientProvider::recognizeUnsolicitedEvent(byte oldTail) 570 | { 571 | return false; 572 | } 573 | 574 | int GSM3ShieldV1MultiClientProvider::getSocket(int socket) 575 | { 576 | if(socket==-1) 577 | { 578 | int i; 579 | for(i=minSocket(); i<=maxSocket(); i++) 580 | { 581 | if (!(sockets&(0x0001<8) 608 | return 0; 609 | if(sockets&(0x0001<