├── .gitattributes ├── .gitignore ├── GSM.h ├── GSM3CircularBuffer.cpp ├── GSM3CircularBuffer.h ├── GSM3MobileAccessProvider.cpp ├── GSM3MobileAccessProvider.h ├── GSM3MobileCellManagement.cpp ├── GSM3MobileCellManagement.h ├── GSM3MobileClientProvider.cpp ├── GSM3MobileClientProvider.h ├── GSM3MobileClientService.cpp ├── GSM3MobileClientService.h ├── GSM3MobileDataNetworkProvider.cpp ├── GSM3MobileDataNetworkProvider.h ├── GSM3MobileMockupProvider.cpp ├── GSM3MobileMockupProvider.h ├── GSM3MobileNetworkProvider.cpp ├── GSM3MobileNetworkProvider.h ├── GSM3MobileNetworkRegistry.cpp ├── GSM3MobileNetworkRegistry.h ├── GSM3MobileSMSProvider.cpp ├── GSM3MobileSMSProvider.h ├── GSM3MobileServerProvider.cpp ├── GSM3MobileServerProvider.h ├── GSM3MobileServerService.cpp ├── GSM3MobileServerService.h ├── GSM3MobileVoiceProvider.cpp ├── GSM3MobileVoiceProvider.h ├── GSM3SMSService.cpp ├── GSM3SMSService.h ├── GSM3ShieldV1.cpp ├── GSM3ShieldV1.h ├── GSM3ShieldV1AccessProvider.cpp ├── GSM3ShieldV1AccessProvider.h ├── GSM3ShieldV1BandManagement.cpp ├── GSM3ShieldV1BandManagement.h ├── GSM3ShieldV1BaseProvider.cpp ├── GSM3ShieldV1BaseProvider.h ├── GSM3ShieldV1CellManagement.cpp ├── GSM3ShieldV1CellManagement.h ├── GSM3ShieldV1ClientProvider.cpp ├── GSM3ShieldV1ClientProvider.h ├── GSM3ShieldV1DataNetworkProvider.cpp ├── GSM3ShieldV1DataNetworkProvider.h ├── GSM3ShieldV1DirectModemProvider.cpp ├── GSM3ShieldV1DirectModemProvider.h ├── GSM3ShieldV1ModemCore.cpp ├── GSM3ShieldV1ModemCore.h ├── GSM3ShieldV1ModemVerification.cpp ├── GSM3ShieldV1ModemVerification.h ├── GSM3ShieldV1MultiClientProvider.cpp ├── GSM3ShieldV1MultiClientProvider.h ├── GSM3ShieldV1MultiServerProvider.cpp ├── GSM3ShieldV1MultiServerProvider.h ├── GSM3ShieldV1PinManagement.cpp ├── GSM3ShieldV1PinManagement.h ├── GSM3ShieldV1SMSProvider.cpp ├── GSM3ShieldV1SMSProvider.h ├── GSM3ShieldV1ScanNetworks.cpp ├── GSM3ShieldV1ScanNetworks.h ├── GSM3ShieldV1ServerProvider.cpp ├── GSM3ShieldV1ServerProvider.h ├── GSM3ShieldV1VoiceProvider.cpp ├── GSM3ShieldV1VoiceProvider.h ├── GSM3SoftSerial.cpp ├── GSM3SoftSerial.h ├── GSM3VoiceCallService.cpp ├── GSM3VoiceCallService.h ├── License.txt ├── MemoryFree.cpp └── examples ├── GsmChatServer └── GsmChatServer.ino ├── GsmCosmClient └── GsmCosmClient.ino ├── GsmCosmClientString └── GsmCosmClientString.ino ├── GsmTwitterClient └── GsmTwitterClient.ino ├── GsmWebClient └── GsmWebClient.ino ├── GsmWebServer └── GsmWebServer.ino ├── MakeVoiceCall └── MakeVoiceCall.ino ├── ReceiveSMS └── ReceiveSMS.ino ├── ReceiveVoiceCall └── ReceiveVoiceCall.ino ├── SendSMS └── SendSMS.ino ├── Tools ├── BandManagement │ └── BandManagement.ino ├── GsmScanNetworks │ └── GsmScanNetworks.ino ├── PinManagement │ └── PinManagement.ino ├── TelefonicaShieldSW │ └── TelefonicaShieldSW.ino ├── TestGPRS │ └── TestGPRS.ino └── TestModem │ └── TestModem.ino └── proto-examples ├── GsmChatServer └── GsmChatServer.ino ├── GsmPachubeClient └── GsmPachubeClient.ino ├── GsmScanNetworks └── GsmScanNetworks.ino ├── GsmTwitterClient └── GsmTwitterClient.ino ├── GsmWebClient └── GsmWebClient.ino └── GsmWebServer └── GsmWebServer.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /GSM.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM.h -------------------------------------------------------------------------------- /GSM3CircularBuffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3CircularBuffer.cpp -------------------------------------------------------------------------------- /GSM3CircularBuffer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3CircularBuffer.h -------------------------------------------------------------------------------- /GSM3MobileAccessProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GSM3MobileAccessProvider* theGSM3MobileAccessProvider; -------------------------------------------------------------------------------- /GSM3MobileAccessProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileAccessProvider.h -------------------------------------------------------------------------------- /GSM3MobileCellManagement.cpp: -------------------------------------------------------------------------------- 1 | #include -------------------------------------------------------------------------------- /GSM3MobileCellManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileCellManagement.h -------------------------------------------------------------------------------- /GSM3MobileClientProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GSM3MobileClientProvider* theGSM3MobileClientProvider; -------------------------------------------------------------------------------- /GSM3MobileClientProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileClientProvider.h -------------------------------------------------------------------------------- /GSM3MobileClientService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileClientService.cpp -------------------------------------------------------------------------------- /GSM3MobileClientService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileClientService.h -------------------------------------------------------------------------------- /GSM3MobileDataNetworkProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // GSM3MobileDataNetworkProvider* theGSM3MobileDataNetworkProvider; -------------------------------------------------------------------------------- /GSM3MobileDataNetworkProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileDataNetworkProvider.h -------------------------------------------------------------------------------- /GSM3MobileMockupProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileMockupProvider.cpp -------------------------------------------------------------------------------- /GSM3MobileMockupProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileMockupProvider.h -------------------------------------------------------------------------------- /GSM3MobileNetworkProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileNetworkProvider.cpp -------------------------------------------------------------------------------- /GSM3MobileNetworkProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileNetworkProvider.h -------------------------------------------------------------------------------- /GSM3MobileNetworkRegistry.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileNetworkRegistry.cpp -------------------------------------------------------------------------------- /GSM3MobileNetworkRegistry.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileNetworkRegistry.h -------------------------------------------------------------------------------- /GSM3MobileSMSProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GSM3MobileSMSProvider* theGSM3SMSProvider; 4 | -------------------------------------------------------------------------------- /GSM3MobileSMSProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileSMSProvider.h -------------------------------------------------------------------------------- /GSM3MobileServerProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GSM3MobileServerProvider* theGSM3MobileServerProvider; 4 | 5 | -------------------------------------------------------------------------------- /GSM3MobileServerProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileServerProvider.h -------------------------------------------------------------------------------- /GSM3MobileServerService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileServerService.cpp -------------------------------------------------------------------------------- /GSM3MobileServerService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileServerService.h -------------------------------------------------------------------------------- /GSM3MobileVoiceProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | GSM3MobileVoiceProvider* theGSM3MobileVoiceProvider; 5 | -------------------------------------------------------------------------------- /GSM3MobileVoiceProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3MobileVoiceProvider.h -------------------------------------------------------------------------------- /GSM3SMSService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3SMSService.cpp -------------------------------------------------------------------------------- /GSM3SMSService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3SMSService.h -------------------------------------------------------------------------------- /GSM3ShieldV1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1.cpp -------------------------------------------------------------------------------- /GSM3ShieldV1.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1.h -------------------------------------------------------------------------------- /GSM3ShieldV1AccessProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define __RESETPIN__ 7 5 | #define __TOUTSHUTDOWN__ 5000 6 | #define __TOUTMODEMCONFIGURATION__ 5000//equivalent to 30000 because of time in interrupt routine. 7 | #define __TOUTAT__ 1000 8 | 9 | char _command_AT[] PROGMEM = "AT"; 10 | char _command_CGREG[] PROGMEM = "AT+CGREG?"; 11 | 12 | 13 | GSM3ShieldV1AccessProvider::GSM3ShieldV1AccessProvider(bool debug) 14 | { 15 | theGSM3ShieldV1ModemCore.setDebug(debug); 16 | theGSM3ShieldV1ModemCore.gss.begin(9600); 17 | 18 | } 19 | 20 | void GSM3ShieldV1AccessProvider::manageResponse(byte from, byte to) 21 | { 22 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 23 | { 24 | case MODEMCONFIG: 25 | ModemConfigurationContinue(); 26 | break; 27 | case ALIVETEST: 28 | isModemAliveContinue(); 29 | break; 30 | } 31 | } 32 | 33 | ///////////////////////////////////////////////////////CONFIGURATION FUNCTIONS/////////////////////////////////////////////////////////////////// 34 | 35 | // Begin 36 | // Restart or start the modem 37 | // May be synchronous 38 | GSM3_NetworkStatus_t GSM3ShieldV1AccessProvider::begin(char* pin, bool restart, bool synchronous) 39 | { 40 | pinMode(__RESETPIN__, OUTPUT); 41 | 42 | // If asked for modem restart, restart 43 | if (restart) 44 | HWrestart(); 45 | else 46 | HWstart(); 47 | // Launch modem configuration commands 48 | ModemConfiguration(pin); 49 | // If synchronous, wait till ModemConfiguration is over 50 | if(synchronous) 51 | { 52 | // if we shorten this delay, the command fails 53 | while(ready()==0) 54 | delay(1000); 55 | } 56 | return getStatus(); 57 | } 58 | 59 | //HWrestart. 60 | int GSM3ShieldV1AccessProvider::HWrestart() 61 | { 62 | 63 | theGSM3ShieldV1ModemCore.setStatus(IDLE); 64 | digitalWrite(__RESETPIN__, HIGH); 65 | delay(12000); 66 | digitalWrite(__RESETPIN__, LOW); 67 | delay(1000); 68 | return 1; //configandwait(pin); 69 | } 70 | 71 | //HWrestart. 72 | int GSM3ShieldV1AccessProvider::HWstart() 73 | { 74 | 75 | theGSM3ShieldV1ModemCore.setStatus(IDLE); 76 | digitalWrite(__RESETPIN__, HIGH); 77 | delay(2000); 78 | digitalWrite(__RESETPIN__, LOW); 79 | //delay(1000); 80 | 81 | return 1; //configandwait(pin); 82 | } 83 | 84 | //Initial configuration main function. 85 | int GSM3ShieldV1AccessProvider::ModemConfiguration(char* pin) 86 | { 87 | theGSM3ShieldV1ModemCore.setPhoneNumber(pin); 88 | theGSM3ShieldV1ModemCore.openCommand(this,MODEMCONFIG); 89 | theGSM3ShieldV1ModemCore.setStatus(CONNECTING); 90 | ModemConfigurationContinue(); 91 | return theGSM3ShieldV1ModemCore.getCommandError(); 92 | } 93 | 94 | //Initial configuration continue function. 95 | void GSM3ShieldV1AccessProvider::ModemConfigurationContinue() 96 | { 97 | bool resp; 98 | 99 | // 1: Send AT 100 | // 2: Wait AT OK and SetPin or CGREG 101 | // 3: Wait Pin OK and CGREG 102 | // 4: Wait CGREG and Flow SW control or CGREG 103 | // 5: Wait IFC OK and SMS Text Mode 104 | // 6: Wait SMS text Mode OK and Calling line identification 105 | // 7: Wait Calling Line Id OK and Echo off 106 | // 8: Wait for OK and COLP command for connecting line identification. 107 | // 9: Wait for OK. 108 | int ct=theGSM3ShieldV1ModemCore.getCommandCounter(); 109 | if(ct==1) 110 | { 111 | // Launch AT 112 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 113 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT); 114 | } 115 | else if(ct==2) 116 | { 117 | // Wait for AT - OK. 118 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 119 | { 120 | if(resp) 121 | { 122 | // OK received 123 | if(theGSM3ShieldV1ModemCore.getPhoneNumber() && (theGSM3ShieldV1ModemCore.getPhoneNumber()[0]!=0)) 124 | { 125 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CPIN="), false); 126 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 127 | theGSM3ShieldV1ModemCore.genericCommand_rqc(theGSM3ShieldV1ModemCore.getPhoneNumber()); 128 | } 129 | else 130 | { 131 | //DEBUG 132 | //Serial.println("AT+CGREG?"); 133 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 134 | theGSM3ShieldV1ModemCore.takeMilliseconds(); 135 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG); 136 | } 137 | } 138 | else theGSM3ShieldV1ModemCore.closeCommand(3); 139 | } 140 | } 141 | else if(ct==3) 142 | { 143 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 144 | { 145 | if(resp) 146 | { 147 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 148 | theGSM3ShieldV1ModemCore.takeMilliseconds(); 149 | theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000); 150 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG); 151 | } 152 | else theGSM3ShieldV1ModemCore.closeCommand(3); 153 | } 154 | } 155 | else if(ct==4) 156 | { 157 | char auxLocate1 [12]; 158 | char auxLocate2 [12]; 159 | prepareAuxLocate(PSTR("+CGREG: 0,1"), auxLocate1); 160 | prepareAuxLocate(PSTR("+CGREG: 0,5"), auxLocate2); 161 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate1, auxLocate2)) 162 | { 163 | if(resp) 164 | { 165 | theGSM3ShieldV1ModemCore.setCommandCounter(5); 166 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+IFC=1,1")); 167 | } 168 | else 169 | { 170 | // If not, launch command again 171 | if(theGSM3ShieldV1ModemCore.takeMilliseconds() > __TOUTMODEMCONFIGURATION__) 172 | { 173 | theGSM3ShieldV1ModemCore.closeCommand(3); 174 | } 175 | else 176 | { 177 | theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000); 178 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG); 179 | } 180 | } 181 | } 182 | } 183 | else if(ct==5) 184 | { 185 | // 5: Wait IFC OK 186 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 187 | { 188 | //Delay for SW flow control being active. 189 | theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000); 190 | // 9: SMS Text Mode 191 | theGSM3ShieldV1ModemCore.setCommandCounter(6); 192 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGF=1")); 193 | } 194 | } 195 | else if(ct==6) 196 | { 197 | // 6: Wait SMS text Mode OK 198 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 199 | { 200 | //Calling line identification 201 | theGSM3ShieldV1ModemCore.setCommandCounter(7); 202 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLIP=1")); 203 | } 204 | } 205 | else if(ct==7) 206 | { 207 | // 7: Wait Calling Line Id OK 208 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 209 | { 210 | // Echo off 211 | theGSM3ShieldV1ModemCore.setCommandCounter(8); 212 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATE0")); 213 | } 214 | } 215 | else if(ct==8) 216 | { 217 | // 8: Wait ATEO OK, send COLP 218 | // In Arduino Mega, attention, take away the COLP step 219 | // It looks as we can only have 8 steps 220 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 221 | { 222 | theGSM3ShieldV1ModemCore.setCommandCounter(9); 223 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+COLP=1")); 224 | } 225 | } 226 | else if(ct==9) 227 | { 228 | // 9: Wait ATCOLP OK 229 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 230 | { 231 | if (resp) 232 | { 233 | theGSM3ShieldV1ModemCore.setStatus(GSM_READY); 234 | theGSM3ShieldV1ModemCore.closeCommand(1); 235 | } 236 | else theGSM3ShieldV1ModemCore.closeCommand(3); 237 | } 238 | } 239 | } 240 | 241 | //Alive Test main function. 242 | int GSM3ShieldV1AccessProvider::isAccessAlive() 243 | { 244 | theGSM3ShieldV1ModemCore.setCommandError(0); 245 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 246 | theGSM3ShieldV1ModemCore.openCommand(this,ALIVETEST); 247 | isModemAliveContinue(); 248 | return theGSM3ShieldV1ModemCore.getCommandError(); 249 | } 250 | 251 | //Alive Test continue function. 252 | void GSM3ShieldV1AccessProvider::isModemAliveContinue() 253 | { 254 | bool rsp; 255 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 256 | case 1: 257 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT); 258 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 259 | break; 260 | case 2: 261 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(rsp)) 262 | { 263 | if (rsp) theGSM3ShieldV1ModemCore.closeCommand(1); 264 | else theGSM3ShieldV1ModemCore.closeCommand(3); 265 | } 266 | break; 267 | } 268 | } 269 | 270 | //Shutdown. 271 | bool GSM3ShieldV1AccessProvider::shutdown() 272 | { 273 | unsigned long m; 274 | bool resp; 275 | char auxLocate [18]; 276 | 277 | // It makes no sense to have an asynchronous shutdown 278 | pinMode(__RESETPIN__, OUTPUT); 279 | digitalWrite(__RESETPIN__, HIGH); 280 | delay(1500); 281 | digitalWrite(__RESETPIN__, LOW); 282 | theGSM3ShieldV1ModemCore.setStatus(IDLE); 283 | theGSM3ShieldV1ModemCore.gss.close(); 284 | 285 | m=millis(); 286 | prepareAuxLocate(PSTR("POWER DOWN"), auxLocate); 287 | while((millis()-m) < __TOUTSHUTDOWN__) 288 | { 289 | delay(1); 290 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate)) 291 | return resp; 292 | } 293 | return false; 294 | } 295 | 296 | -------------------------------------------------------------------------------- /GSM3ShieldV1AccessProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1AccessProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1BandManagement.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GSM3ShieldV1BandManagement::GSM3ShieldV1BandManagement(bool trace): modem(trace) 4 | { 5 | quectelStrings[UNDEFINED]=""; 6 | quectelStrings[EGSM_MODE]="\"EGSM_MODE\""; 7 | quectelStrings[DCS_MODE]="\"DCS_MODE\""; 8 | quectelStrings[PCS_MODE]="\"PCS_MODE\""; 9 | quectelStrings[EGSM_DCS_MODE]="\"EGSM_DCS_MODE\""; 10 | quectelStrings[GSM850_PCS_MODE]="\"GSM850_PCS_MODE\""; 11 | quectelStrings[GSM850_EGSM_DCS_PCS_MODE]="\"GSM850_EGSM_DCS_PCS_MODE\""; 12 | 13 | bandNames[UNDEFINED]="UNDEFINED"; 14 | bandNames[EGSM_MODE]="E-GSM(900)"; 15 | bandNames[DCS_MODE]="DCS(1800)"; 16 | bandNames[PCS_MODE]="PCS(1900)"; 17 | bandNames[EGSM_DCS_MODE]="E-GSM(900)+DCS(1800) ex: Europe"; 18 | bandNames[GSM850_PCS_MODE]="GSM(850)+PCS(1900) Ex: USA, South Am."; 19 | bandNames[GSM850_EGSM_DCS_PCS_MODE]="GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)"; 20 | } 21 | 22 | GSM3_NetworkStatus_t GSM3ShieldV1BandManagement::begin() 23 | { 24 | // check modem response 25 | modem.begin(); 26 | 27 | // reset hardware 28 | modem.restartModem(); 29 | 30 | return IDLE; 31 | } 32 | 33 | GSM3GSMBand GSM3ShieldV1BandManagement::getBand() 34 | { 35 | String modemResponse=modem.writeModemCommand("AT+QBAND?", 2000); 36 | 37 | 38 | for(GSM3GSMBand i=GSM850_EGSM_DCS_PCS_MODE;i>UNDEFINED;i=(GSM3GSMBand)((int)i-1)) 39 | { 40 | if(modemResponse.indexOf(quectelStrings[i])>=0) 41 | return i; 42 | } 43 | 44 | Serial.print("Unrecognized modem answer:"); 45 | Serial.println(modemResponse); 46 | 47 | return UNDEFINED; 48 | } 49 | 50 | String GSM3ShieldV1BandManagement::getBandName(GSM3GSMBand band) 51 | { 52 | String result; 53 | 54 | result=bandNames[band]; 55 | return result; 56 | } 57 | 58 | bool GSM3ShieldV1BandManagement::setBand(GSM3GSMBand band) 59 | { 60 | String command; 61 | String modemResponse; 62 | command="AT+QBAND="; 63 | command+=quectelStrings[band]; 64 | 65 | // Quad-band takes an awful lot of time 66 | modemResponse=modem.writeModemCommand(command, 15000); 67 | 68 | if(modemResponse.indexOf("QBAND")>=0) 69 | return true; 70 | else 71 | return false; 72 | } -------------------------------------------------------------------------------- /GSM3ShieldV1BandManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1BandManagement.h -------------------------------------------------------------------------------- /GSM3ShieldV1BaseProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Returns 0 if last command is still executing 6 | // 1 if success 7 | // >1 if error 8 | int GSM3ShieldV1BaseProvider::ready() 9 | { 10 | theGSM3ShieldV1ModemCore.manageReceivedData(); 11 | 12 | return theGSM3ShieldV1ModemCore.getCommandError(); 13 | }; 14 | 15 | void GSM3ShieldV1BaseProvider::prepareAuxLocate(PROGMEM prog_char str[], char auxLocate[]) 16 | { 17 | int i=0; 18 | char c; 19 | 20 | do 21 | { 22 | c=pgm_read_byte_near(str + i); 23 | auxLocate[i]=c; 24 | i++; 25 | } while (c!=0); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /GSM3ShieldV1BaseProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1BaseProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1CellManagement.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | GSM3ShieldV1CellManagement::GSM3ShieldV1CellManagement() 4 | { 5 | } 6 | 7 | bool GSM3ShieldV1CellManagement::parseQCCID_available(bool& rsp) 8 | { 9 | char c; 10 | bool iccidFound = false; 11 | int i = 0; 12 | 13 | while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 19)) 14 | { 15 | if((c < 58) & (c > 47)) 16 | iccidFound = true; 17 | 18 | if(iccidFound) 19 | { 20 | bufferICCID[i] = c; 21 | i++; 22 | } 23 | } 24 | bufferICCID[i]=0; 25 | 26 | return true; 27 | } 28 | 29 | bool GSM3ShieldV1CellManagement::parseQENG_available(bool& rsp) 30 | { 31 | char c; 32 | char location[50] = ""; 33 | int i = 0; 34 | 35 | if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG: ", true))) 36 | rsp = false; 37 | else 38 | rsp = true; 39 | 40 | if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG:", true))) 41 | rsp = false; 42 | else 43 | rsp = true; 44 | 45 | while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 50)) 46 | { 47 | location[i] = c; 48 | i++; 49 | } 50 | location[i]=0; 51 | 52 | char* res_tok = strtok(location, ","); 53 | res_tok=strtok(NULL, ","); 54 | strcpy(countryCode, res_tok); 55 | res_tok=strtok(NULL, ","); 56 | strcpy(networkCode, res_tok); 57 | res_tok=strtok(NULL, ","); 58 | strcpy(locationArea, res_tok); 59 | res_tok=strtok(NULL, ","); 60 | strcpy(cellId, res_tok); 61 | 62 | return true; 63 | } 64 | 65 | int GSM3ShieldV1CellManagement::getLocation(char *country, char *network, char *area, char *cell) 66 | { 67 | if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY)) 68 | return 2; 69 | 70 | countryCode=country; 71 | networkCode=network; 72 | locationArea=area; 73 | cellId=cell; 74 | 75 | theGSM3ShieldV1ModemCore.openCommand(this,GETLOCATION); 76 | getLocationContinue(); 77 | 78 | unsigned long timeOut = millis(); 79 | while(((millis() - timeOut) < 5000) & (ready() == 0)); 80 | 81 | return theGSM3ShieldV1ModemCore.getCommandError(); 82 | } 83 | 84 | void GSM3ShieldV1CellManagement::getLocationContinue() 85 | { 86 | bool resp; 87 | 88 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 89 | case 1: 90 | theGSM3ShieldV1ModemCore.gss.tunedDelay(3000); 91 | delay(3000); 92 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 93 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG=1"), false); 94 | theGSM3ShieldV1ModemCore.print("\r"); 95 | break; 96 | case 2: 97 | if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 98 | { 99 | theGSM3ShieldV1ModemCore.gss.tunedDelay(3000); 100 | delay(3000); 101 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 102 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG?"), false); 103 | theGSM3ShieldV1ModemCore.print("\r"); 104 | } 105 | else theGSM3ShieldV1ModemCore.closeCommand(1); 106 | break; 107 | case 3: 108 | if (resp) 109 | { 110 | parseQENG_available(resp); 111 | theGSM3ShieldV1ModemCore.closeCommand(3); 112 | } 113 | else theGSM3ShieldV1ModemCore.closeCommand(2); 114 | break; 115 | } 116 | } 117 | 118 | int GSM3ShieldV1CellManagement::getICCID(char *iccid) 119 | { 120 | if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY)) 121 | return 2; 122 | 123 | bufferICCID=iccid; 124 | theGSM3ShieldV1ModemCore.openCommand(this,GETICCID); 125 | getICCIDContinue(); 126 | 127 | unsigned long timeOut = millis(); 128 | while(((millis() - timeOut) < 5000) & (ready() == 0)); 129 | 130 | return theGSM3ShieldV1ModemCore.getCommandError(); 131 | } 132 | 133 | void GSM3ShieldV1CellManagement::getICCIDContinue() 134 | { 135 | bool resp; 136 | 137 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 138 | case 1: 139 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 140 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QCCID"), false); 141 | theGSM3ShieldV1ModemCore.print("\r"); 142 | break; 143 | case 2: 144 | if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 145 | { 146 | parseQCCID_available(resp); 147 | theGSM3ShieldV1ModemCore.closeCommand(2); 148 | } 149 | else theGSM3ShieldV1ModemCore.closeCommand(1); 150 | break; 151 | } 152 | } 153 | 154 | void GSM3ShieldV1CellManagement::manageResponse(byte from, byte to) 155 | { 156 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 157 | { 158 | case NONE: 159 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 160 | break; 161 | case GETLOCATION: 162 | getLocationContinue(); 163 | break; 164 | case GETICCID: 165 | getICCIDContinue(); 166 | break; 167 | } 168 | } -------------------------------------------------------------------------------- /GSM3ShieldV1CellManagement.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1CellManagement.h -------------------------------------------------------------------------------- /GSM3ShieldV1ClientProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | GSM3ShieldV1ClientProvider::GSM3ShieldV1ClientProvider() 5 | { 6 | theGSM3MobileClientProvider=this; 7 | }; 8 | 9 | //Response management. 10 | void GSM3ShieldV1ClientProvider::manageResponse(byte from, byte to) 11 | { 12 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 13 | { 14 | case NONE: 15 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 16 | break; 17 | case CONNECTTCPCLIENT: 18 | connectTCPClientContinue(); 19 | break; 20 | case FLUSHSOCKET: 21 | flushSocketContinue(); 22 | break; 23 | } 24 | } 25 | 26 | //Connect TCP main function. 27 | int GSM3ShieldV1ClientProvider::connectTCPClient(const char* server, int port, int id_socket) 28 | { 29 | theGSM3ShieldV1ModemCore.setPort(port); 30 | idSocket = id_socket; 31 | 32 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server); 33 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT); 34 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 35 | connectTCPClientContinue(); 36 | return theGSM3ShieldV1ModemCore.getCommandError(); 37 | } 38 | 39 | int GSM3ShieldV1ClientProvider::connectTCPClient(IPAddress add, int port, int id_socket) 40 | { 41 | remoteIP=add; 42 | theGSM3ShieldV1ModemCore.setPhoneNumber(0); 43 | return connectTCPClient(0, port, id_socket); 44 | } 45 | 46 | //Connect TCP continue function. 47 | void GSM3ShieldV1ClientProvider::connectTCPClientContinue() 48 | { 49 | bool resp; 50 | // 0: Dot or DNS notation activation 51 | // 1: Disable SW flow control 52 | // 2: Waiting for IFC OK 53 | // 3: Start-up TCP connection "AT+QIOPEN" 54 | // 4: Wait for connection OK 55 | // 5: Wait for CONNECT 56 | 57 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 58 | case 1: 59 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false); 60 | if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&& 61 | ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9')))) 62 | { 63 | theGSM3ShieldV1ModemCore.print('1'); 64 | theGSM3ShieldV1ModemCore.print('\r'); 65 | } 66 | else 67 | { 68 | theGSM3ShieldV1ModemCore.print('0'); 69 | theGSM3ShieldV1ModemCore.print('\r'); 70 | } 71 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 72 | break; 73 | case 2: 74 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 75 | { 76 | //Response received 77 | if(resp) 78 | { 79 | // AT+QIOPEN 80 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false); 81 | theGSM3ShieldV1ModemCore.print("\"TCP\",\""); 82 | if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0) 83 | { 84 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 85 | } 86 | else 87 | { 88 | remoteIP.printTo(theGSM3ShieldV1ModemCore); 89 | } 90 | theGSM3ShieldV1ModemCore.print('"'); 91 | theGSM3ShieldV1ModemCore.print(','); 92 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort()); 93 | theGSM3ShieldV1ModemCore.print('\r'); 94 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 95 | } 96 | else theGSM3ShieldV1ModemCore.closeCommand(3); 97 | } 98 | break; 99 | 100 | case 3: 101 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 102 | { 103 | // Response received 104 | if(resp) 105 | { 106 | // OK Received 107 | // Great. Go for the next step 108 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 109 | } 110 | else theGSM3ShieldV1ModemCore.closeCommand(3); 111 | } 112 | break; 113 | case 4: 114 | char auxLocate [12]; 115 | prepareAuxLocate(PSTR("CONNECT\r\n"), auxLocate); 116 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate)) 117 | { 118 | // Response received 119 | if(resp) 120 | { 121 | // Received CONNECT OK 122 | // Great. We're done 123 | theGSM3ShieldV1ModemCore.setStatus(TRANSPARENT_CONNECTED); 124 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, true); 125 | theGSM3ShieldV1ModemCore.closeCommand(1); 126 | } 127 | else 128 | theGSM3ShieldV1ModemCore.closeCommand(3); 129 | } 130 | break; 131 | 132 | } 133 | } 134 | 135 | //Disconnect TCP main function. 136 | int GSM3ShieldV1ClientProvider::disconnectTCP(bool client1Server0, int id_socket) 137 | { 138 | // id Socket does not really mean anything, in this case we have 139 | // only one socket running 140 | theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP); 141 | 142 | // If we are not closed, launch the command 143 | //[ZZ] if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 144 | // { 145 | delay(1000); 146 | theGSM3ShieldV1ModemCore.print("+++"); 147 | delay(1000); 148 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE")); 149 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 150 | // } 151 | // Looks like it runs everytime, so we simply flush to death and go on 152 | do 153 | { 154 | // Empty the local buffer, and tell the modem to XON 155 | // If meanwhile we receive a DISCONNECT we should detect it as URC. 156 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 157 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 158 | // Give some time for the buffer to refill 159 | delay(100); 160 | theGSM3ShieldV1ModemCore.closeCommand(1); 161 | }while(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()>0); 162 | 163 | theGSM3ShieldV1ModemCore.unRegisterUMProvider(this); 164 | return theGSM3ShieldV1ModemCore.getCommandError(); 165 | } 166 | 167 | 168 | //Write socket first chain main function. 169 | void GSM3ShieldV1ClientProvider::beginWriteSocket(bool client1Server0, int id_socket) 170 | { 171 | } 172 | 173 | 174 | //Write socket next chain function. 175 | void GSM3ShieldV1ClientProvider::writeSocket(const char* buf) 176 | { 177 | if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 178 | theGSM3ShieldV1ModemCore.print(buf); 179 | } 180 | 181 | //Write socket character function. 182 | void GSM3ShieldV1ClientProvider::writeSocket(uint8_t c) 183 | { 184 | if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 185 | theGSM3ShieldV1ModemCore.print((char)c); 186 | } 187 | 188 | //Write socket last chain main function. 189 | void GSM3ShieldV1ClientProvider::endWriteSocket() 190 | { 191 | } 192 | 193 | 194 | //Available socket main function. 195 | int GSM3ShieldV1ClientProvider::availableSocket(bool client1Server0, int id_socket) 196 | { 197 | 198 | if(!(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED)) 199 | theGSM3ShieldV1ModemCore.closeCommand(4); 200 | 201 | if(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()) 202 | theGSM3ShieldV1ModemCore.closeCommand(1); 203 | else 204 | theGSM3ShieldV1ModemCore.closeCommand(4); 205 | 206 | return theGSM3ShieldV1ModemCore.getCommandError(); 207 | } 208 | 209 | int GSM3ShieldV1ClientProvider::readSocket() 210 | { 211 | char charSocket; 212 | 213 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0) 214 | { 215 | return 0; 216 | } 217 | 218 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read(); 219 | 220 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==100) 221 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 222 | 223 | return charSocket; 224 | 225 | } 226 | 227 | //Read socket main function. 228 | int GSM3ShieldV1ClientProvider::peekSocket() 229 | { 230 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0); 231 | } 232 | 233 | 234 | //Flush SMS main function. 235 | void GSM3ShieldV1ClientProvider::flushSocket() 236 | { 237 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET); 238 | 239 | flushSocketContinue(); 240 | } 241 | 242 | //Send SMS continue function. 243 | void GSM3ShieldV1ClientProvider::flushSocketContinue() 244 | { 245 | // If we have incomed data 246 | if(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()>0) 247 | { 248 | // Empty the local buffer, and tell the modem to XON 249 | // If meanwhile we receive a DISCONNECT we should detect it as URC. 250 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 251 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 252 | } 253 | else 254 | { 255 | //We're done 256 | theGSM3ShieldV1ModemCore.closeCommand(1); 257 | } 258 | } 259 | 260 | // URC recognize. 261 | // Yes, we recognize "closes" in client mode 262 | bool GSM3ShieldV1ClientProvider::recognizeUnsolicitedEvent(byte oldTail) 263 | { 264 | char auxLocate [12]; 265 | prepareAuxLocate(PSTR("CLOSED"), auxLocate); 266 | 267 | if((theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) & theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, false, false)) 268 | { 269 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 270 | theGSM3ShieldV1ModemCore.unRegisterUMProvider(this); 271 | return true; 272 | } 273 | 274 | return false; 275 | } 276 | 277 | int GSM3ShieldV1ClientProvider::getSocket(int socket) 278 | { 279 | return 0; 280 | } 281 | 282 | void GSM3ShieldV1ClientProvider::releaseSocket(int socket) 283 | { 284 | 285 | } 286 | 287 | bool GSM3ShieldV1ClientProvider::getStatusSocketClient(uint8_t socket) 288 | { 289 | return (theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED); 290 | 291 | }; 292 | 293 | 294 | 295 | -------------------------------------------------------------------------------- /GSM3ShieldV1ClientProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1ClientProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1DataNetworkProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char _command_CGATT[] PROGMEM = "AT+CGATT="; 5 | char _command_SEPARATOR[] PROGMEM = "\",\""; 6 | 7 | //Attach GPRS main function. 8 | GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::attachGPRS(char* apn, char* user_name, char* password, bool synchronous) 9 | { 10 | user = user_name; 11 | passwd = password; 12 | // A sad use of byte reuse 13 | theGSM3ShieldV1ModemCore.setPhoneNumber(apn); 14 | 15 | theGSM3ShieldV1ModemCore.openCommand(this,ATTACHGPRS); 16 | theGSM3ShieldV1ModemCore.setStatus(CONNECTING); 17 | 18 | attachGPRSContinue(); 19 | 20 | // If synchronous, wait till attach is over, or not. 21 | if(synchronous) 22 | { 23 | // if we shorten this delay, the command fails 24 | while(ready()==0) 25 | delay(100); 26 | } 27 | 28 | return theGSM3ShieldV1ModemCore.getStatus(); 29 | } 30 | 31 | //Atthach GPRS continue function. 32 | void GSM3ShieldV1DataNetworkProvider::attachGPRSContinue() 33 | { 34 | bool resp; 35 | // 1: Attach to GPRS service "AT+CGATT=1" 36 | // 2: Wait attach OK and Set the context 0 as FGCNT "AT+QIFGCNT=0" 37 | // 3: Wait context OK and Set bearer type as GPRS, APN, user name and pasword "AT+QICSGP=1..." 38 | // 4: Wait bearer OK and Enable the function of MUXIP "AT+QIMUX=1" 39 | // 5: Wait for disable MUXIP OK and Set the session mode as non transparent "AT+QIMODE=0" 40 | // 6: Wait for session mode OK and Enable notification when data received "AT+QINDI=1" 41 | // 8: Wait domain name OK and Register the TCP/IP stack "AT+QIREGAPP" 42 | // 9: Wait for Register OK and Activate FGCNT "AT+QIACT" 43 | // 10: Wait for activate OK 44 | 45 | int ct=theGSM3ShieldV1ModemCore.getCommandCounter(); 46 | if(ct==1) 47 | { 48 | //AT+CGATT 49 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGATT,false); 50 | theGSM3ShieldV1ModemCore.print(1); 51 | theGSM3ShieldV1ModemCore.print('\r'); 52 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 53 | } 54 | else if(ct==2) 55 | { 56 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 57 | { 58 | if(resp) 59 | { 60 | //AT+QIFGCNT 61 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIFGCNT=0")); 62 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 63 | } 64 | else theGSM3ShieldV1ModemCore.closeCommand(3); 65 | } 66 | } 67 | else if(ct==3) 68 | { 69 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 70 | { 71 | if(resp) 72 | { 73 | // Great. Go for the next step 74 | //DEBUG 75 | //Serial.println("AT+QICSGP."); 76 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICSGP=1,\""),false); 77 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 78 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_SEPARATOR,false); 79 | theGSM3ShieldV1ModemCore.print(user); 80 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_SEPARATOR,false); 81 | theGSM3ShieldV1ModemCore.print(passwd); 82 | theGSM3ShieldV1ModemCore.print("\"\r"); 83 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 84 | } 85 | else theGSM3ShieldV1ModemCore.closeCommand(3); 86 | } 87 | } 88 | else if(ct==4) 89 | { 90 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 91 | { 92 | if(resp) 93 | { 94 | // AT+QIMUX=1 for multisocket 95 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIMUX=0")); 96 | theGSM3ShieldV1ModemCore.setCommandCounter(5); 97 | } 98 | else theGSM3ShieldV1ModemCore.closeCommand(3); 99 | } 100 | } 101 | else if(ct==5) 102 | { 103 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 104 | { 105 | if(resp) 106 | { 107 | //AT+QIMODE=0 for multisocket 108 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIMODE=1")); 109 | theGSM3ShieldV1ModemCore.setCommandCounter(6); 110 | } 111 | else theGSM3ShieldV1ModemCore.closeCommand(3); 112 | } 113 | } 114 | else if(ct==6) 115 | { 116 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 117 | { 118 | if(resp) 119 | { 120 | // AT+QINDI=1 121 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QINDI=1")); 122 | theGSM3ShieldV1ModemCore.setCommandCounter(8); 123 | } 124 | else theGSM3ShieldV1ModemCore.closeCommand(3); 125 | } 126 | } 127 | else if(ct==8) 128 | { 129 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 130 | { 131 | if(resp) 132 | { 133 | // AT+QIREGAPP 134 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIREGAPP")); 135 | theGSM3ShieldV1ModemCore.setCommandCounter(9); 136 | } 137 | else theGSM3ShieldV1ModemCore.closeCommand(3); 138 | } 139 | } 140 | else if(ct==9) 141 | { 142 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 143 | { 144 | if(resp) 145 | { 146 | // AT+QIACT 147 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIACT")); 148 | theGSM3ShieldV1ModemCore.setCommandCounter(10); 149 | } 150 | else theGSM3ShieldV1ModemCore.closeCommand(3); 151 | } 152 | } 153 | else if(ct==10) 154 | { 155 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 156 | { 157 | if (resp) 158 | { 159 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 160 | theGSM3ShieldV1ModemCore.closeCommand(1); 161 | } 162 | else theGSM3ShieldV1ModemCore.closeCommand(3); 163 | } 164 | } 165 | } 166 | 167 | //Detach GPRS main function. 168 | GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::detachGPRS(bool synchronous) 169 | { 170 | theGSM3ShieldV1ModemCore.openCommand(this,DETACHGPRS); 171 | theGSM3ShieldV1ModemCore.setStatus(CONNECTING); 172 | detachGPRSContinue(); 173 | 174 | if(synchronous) 175 | { 176 | while(ready()==0) 177 | delay(1); 178 | } 179 | 180 | return theGSM3ShieldV1ModemCore.getStatus(); 181 | } 182 | 183 | void GSM3ShieldV1DataNetworkProvider::detachGPRSContinue() 184 | { 185 | bool resp; 186 | // 1: Detach to GPRS service "AT+CGATT=0" 187 | // 2: Wait dettach +PDP DEACT 188 | // 3: Wait for OK 189 | 190 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 191 | case 1: 192 | //AT+CGATT=0 193 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGATT,false); 194 | theGSM3ShieldV1ModemCore.print(0); 195 | theGSM3ShieldV1ModemCore.print('\r'); 196 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 197 | break; 198 | case 2: 199 | char auxLocate[12]; 200 | prepareAuxLocate(PSTR("+PDP DEACT"), auxLocate); 201 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 202 | { 203 | if(resp) 204 | { 205 | // Received +PDP DEACT; 206 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 207 | } 208 | else theGSM3ShieldV1ModemCore.closeCommand(3); 209 | } 210 | break; 211 | case 3: 212 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 213 | { 214 | // OK received 215 | if (resp) 216 | { 217 | theGSM3ShieldV1ModemCore.setStatus(GSM_READY); 218 | theGSM3ShieldV1ModemCore.closeCommand(1); 219 | } 220 | else theGSM3ShieldV1ModemCore.closeCommand(3); 221 | } 222 | break; 223 | } 224 | } 225 | 226 | //QILOCIP parse. 227 | bool GSM3ShieldV1DataNetworkProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp) 228 | { 229 | if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength))) 230 | rsp = false; 231 | else 232 | rsp = true; 233 | return true; 234 | } 235 | 236 | //Get IP main function. 237 | int GSM3ShieldV1DataNetworkProvider::getIP(char* LocalIP, int LocalIPlength) 238 | { 239 | theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP); 240 | theGSM3ShieldV1ModemCore.setPort(LocalIPlength); 241 | theGSM3ShieldV1ModemCore.openCommand(this,GETIP); 242 | getIPContinue(); 243 | return theGSM3ShieldV1ModemCore.getCommandError(); 244 | } 245 | 246 | void GSM3ShieldV1DataNetworkProvider::getIPContinue() 247 | { 248 | 249 | bool resp; 250 | // 1: Read Local IP "AT+QILOCIP" 251 | // 2: Waiting for IP. 252 | 253 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 254 | case 1: 255 | //AT+QILOCIP 256 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILOCIP")); 257 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 258 | break; 259 | case 2: 260 | if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp)) 261 | { 262 | if (resp) 263 | theGSM3ShieldV1ModemCore.closeCommand(1); 264 | else 265 | theGSM3ShieldV1ModemCore.closeCommand(3); 266 | } 267 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 268 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 269 | break; 270 | } 271 | } 272 | 273 | //Get IP with IPAddress object 274 | IPAddress GSM3ShieldV1DataNetworkProvider::getIPAddress() { 275 | char ip_temp[15]=""; 276 | getIP(ip_temp, 15); 277 | unsigned long m=millis(); 278 | 279 | while((millis()-m)<10*1000 && (!ready())){ 280 | // wait for a response from the modem: 281 | delay(100); 282 | } 283 | IPAddress ip; 284 | inet_aton(ip_temp, ip); 285 | return ip; 286 | } 287 | 288 | int GSM3ShieldV1DataNetworkProvider::inet_aton(const char* aIPAddrString, IPAddress& aResult) 289 | { 290 | // See if we've been given a valid IP address 291 | const char* p =aIPAddrString; 292 | while (*p && 293 | ( (*p == '.') || (*p >= '0') || (*p <= '9') )) 294 | { 295 | p++; 296 | } 297 | 298 | if (*p == '\0') 299 | { 300 | // It's looking promising, we haven't found any invalid characters 301 | p = aIPAddrString; 302 | int segment =0; 303 | int segmentValue =0; 304 | while (*p && (segment < 4)) 305 | { 306 | if (*p == '.') 307 | { 308 | // We've reached the end of a segment 309 | if (segmentValue > 255) 310 | { 311 | // You can't have IP address segments that don't fit in a byte 312 | return 0; 313 | } 314 | else 315 | { 316 | aResult[segment] = (byte)segmentValue; 317 | segment++; 318 | segmentValue = 0; 319 | } 320 | } 321 | else 322 | { 323 | // Next digit 324 | segmentValue = (segmentValue*10)+(*p - '0'); 325 | } 326 | p++; 327 | } 328 | // We've reached the end of address, but there'll still be the last 329 | // segment to deal with 330 | if ((segmentValue > 255) || (segment > 3)) 331 | { 332 | // You can't have IP address segments that don't fit in a byte, 333 | // or more than four segments 334 | return 0; 335 | } 336 | else 337 | { 338 | aResult[segment] = (byte)segmentValue; 339 | return 1; 340 | } 341 | } 342 | else 343 | { 344 | return 0; 345 | } 346 | } 347 | 348 | //Response management. 349 | void GSM3ShieldV1DataNetworkProvider::manageResponse(byte from, byte to) 350 | { 351 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 352 | { 353 | case ATTACHGPRS: 354 | attachGPRSContinue(); 355 | break; 356 | case DETACHGPRS: 357 | detachGPRSContinue(); 358 | break; 359 | case GETIP: 360 | getIPContinue(); 361 | break; 362 | } 363 | } 364 | -------------------------------------------------------------------------------- /GSM3ShieldV1DataNetworkProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1DataNetworkProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1DirectModemProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1DirectModemProvider.cpp -------------------------------------------------------------------------------- /GSM3ShieldV1DirectModemProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1DirectModemProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1ModemCore.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | GSM3ShieldV1ModemCore theGSM3ShieldV1ModemCore; 5 | 6 | char* __ok__="OK"; 7 | 8 | GSM3ShieldV1ModemCore::GSM3ShieldV1ModemCore() : gss() 9 | { 10 | gss.registerMgr(this); 11 | _dataInBufferFrom=0; 12 | _dataInBufferTo=0; 13 | commandError=1; 14 | commandCounter=0; 15 | ongoingCommand=NONE; 16 | takeMilliseconds(); 17 | 18 | for(int i=0;irecognizeUnsolicitedEvent(from); 143 | } 144 | if((!recognized)&&(activeProvider)) 145 | activeProvider->manageResponse(from, to); 146 | } 147 | 148 | 149 | void GSM3ShieldV1ModemCore::openCommand(GSM3ShieldV1BaseProvider* provider, GSM3_commandType_e c) 150 | { 151 | activeProvider=provider; 152 | commandError=0; 153 | commandCounter=1; 154 | ongoingCommand=c; 155 | _dataInBufferFrom=0; 156 | _dataInBufferTo=0; 157 | 158 | }; 159 | 160 | size_t GSM3ShieldV1ModemCore::writePGM(PROGMEM prog_char str[], bool CR) 161 | { 162 | int i=0; 163 | char c; 164 | 165 | do 166 | { 167 | c=pgm_read_byte_near(str + i); 168 | if(c!=0) 169 | write(c); 170 | i++; 171 | } while (c!=0); 172 | if(CR) 173 | print("\r"); 174 | 175 | return 1; 176 | } 177 | 178 | size_t GSM3ShieldV1ModemCore::write(uint8_t c) 179 | { 180 | if(_debug) 181 | GSM3CircularBuffer::printCharDebug(c); 182 | return gss.write(c); 183 | } 184 | 185 | unsigned long GSM3ShieldV1ModemCore::takeMilliseconds() 186 | { 187 | unsigned long now=millis(); 188 | unsigned long delta; 189 | delta=now-milliseconds; 190 | milliseconds=now; 191 | return delta; 192 | } 193 | 194 | void GSM3ShieldV1ModemCore::delayInsideInterrupt(unsigned long milliseconds) 195 | { 196 | for (unsigned long k=0;k 2 | #include 3 | 4 | char _command_MultiQISRVC[] PROGMEM = "AT+QISRVC="; 5 | 6 | #define __TOUTFLUSH__ 10000 7 | 8 | GSM3ShieldV1MultiClientProvider::GSM3ShieldV1MultiClientProvider() 9 | { 10 | theGSM3MobileClientProvider=this; 11 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 12 | }; 13 | 14 | //Response management. 15 | void GSM3ShieldV1MultiClientProvider::manageResponse(byte from, byte to) 16 | { 17 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 18 | { 19 | case XON: 20 | if (flagReadingSocket) 21 | { 22 | // flagReadingSocket = 0; 23 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 24 | } 25 | else theGSM3ShieldV1ModemCore.setOngoingCommand(NONE); 26 | break; 27 | case NONE: 28 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 29 | break; 30 | case CONNECTTCPCLIENT: 31 | connectTCPClientContinue(); 32 | break; 33 | case DISCONNECTTCP: 34 | disconnectTCPContinue(); 35 | break; 36 | case BEGINWRITESOCKET: 37 | beginWriteSocketContinue(); 38 | break; 39 | case ENDWRITESOCKET: 40 | endWriteSocketContinue(); 41 | break; 42 | case AVAILABLESOCKET: 43 | availableSocketContinue(); 44 | break; 45 | case FLUSHSOCKET: 46 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 47 | flushSocketContinue(); 48 | break; 49 | } 50 | } 51 | 52 | //Connect TCP main function. 53 | int GSM3ShieldV1MultiClientProvider::connectTCPClient(const char* server, int port, int id_socket) 54 | { 55 | theGSM3ShieldV1ModemCore.setPort(port); 56 | idSocket = id_socket; 57 | 58 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server); 59 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT); 60 | connectTCPClientContinue(); 61 | return theGSM3ShieldV1ModemCore.getCommandError(); 62 | } 63 | 64 | int GSM3ShieldV1MultiClientProvider::connectTCPClient(IPAddress add, int port, int id_socket) 65 | { 66 | remoteIP=add; 67 | theGSM3ShieldV1ModemCore.setPhoneNumber(0); 68 | return connectTCPClient(0, port, id_socket); 69 | } 70 | 71 | //Connect TCP continue function. 72 | void GSM3ShieldV1MultiClientProvider::connectTCPClientContinue() 73 | { 74 | bool resp; 75 | // 0: Dot or DNS notation activation 76 | // 1: Disable SW flow control 77 | // 2: Waiting for IFC OK 78 | // 3: Start-up TCP connection "AT+QIOPEN" 79 | // 4: Wait for connection OK 80 | // 5: Wait for CONNECT 81 | 82 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 83 | case 1: 84 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false); 85 | if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&& 86 | ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9')))) 87 | { 88 | theGSM3ShieldV1ModemCore.print('1'); 89 | theGSM3ShieldV1ModemCore.print('\r'); 90 | } 91 | else 92 | { 93 | theGSM3ShieldV1ModemCore.print('0'); 94 | theGSM3ShieldV1ModemCore.print('\r'); 95 | } 96 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 97 | break; 98 | case 2: 99 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 100 | { 101 | //Response received 102 | if(resp) 103 | { 104 | // AT+QIOPEN 105 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false); 106 | theGSM3ShieldV1ModemCore.print(idSocket); 107 | theGSM3ShieldV1ModemCore.print(",\"TCP\",\""); 108 | if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0) 109 | { 110 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 111 | } 112 | else 113 | { 114 | remoteIP.printTo(theGSM3ShieldV1ModemCore); 115 | } 116 | theGSM3ShieldV1ModemCore.print('"'); 117 | theGSM3ShieldV1ModemCore.print(','); 118 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort()); 119 | theGSM3ShieldV1ModemCore.print('\r'); 120 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 121 | } 122 | else theGSM3ShieldV1ModemCore.closeCommand(3); 123 | } 124 | break; 125 | 126 | case 3: 127 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 128 | { 129 | // Response received 130 | if(resp) 131 | { 132 | // OK Received 133 | // Great. Go for the next step 134 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 135 | } 136 | else theGSM3ShieldV1ModemCore.closeCommand(3); 137 | } 138 | break; 139 | case 4: 140 | char auxLocate [12]; 141 | prepareAuxLocate(PSTR("CONNECT OK"), auxLocate); 142 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate)) 143 | { 144 | // Response received 145 | if(resp) 146 | { 147 | // Received CONNECT OK 148 | // Great. We're done 149 | theGSM3ShieldV1ModemCore.closeCommand(1); 150 | } 151 | else 152 | theGSM3ShieldV1ModemCore.closeCommand(3); 153 | } 154 | break; 155 | 156 | } 157 | } 158 | 159 | //Disconnect TCP main function. 160 | int GSM3ShieldV1MultiClientProvider::disconnectTCP(bool client1Server0, int id_socket) 161 | { 162 | idSocket = id_socket; 163 | 164 | // First of all, we will flush the socket synchronously 165 | unsigned long m; 166 | m=millis(); 167 | flushSocket(); 168 | while(((millis()-m)< __TOUTFLUSH__ )&&(ready()==0)) 169 | delay(10); 170 | 171 | // Could not flush the communications... strange 172 | if(ready()==0) 173 | { 174 | theGSM3ShieldV1ModemCore.setCommandError(2); 175 | return theGSM3ShieldV1ModemCore.getCommandError(); 176 | } 177 | 178 | // Set up the command 179 | client1_server0 = client1Server0; 180 | flagReadingSocket=0; 181 | theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP); 182 | disconnectTCPContinue(); 183 | return theGSM3ShieldV1ModemCore.getCommandError(); 184 | } 185 | 186 | //Disconnect TCP continue function 187 | void GSM3ShieldV1MultiClientProvider::disconnectTCPContinue() 188 | { 189 | bool resp; 190 | // 1: Send AT+QISRVC 191 | // 2: "AT+QICLOSE" 192 | // 3: Wait for OK 193 | 194 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 195 | case 1: 196 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false); 197 | if (client1_server0) theGSM3ShieldV1ModemCore.print('1'); 198 | else theGSM3ShieldV1ModemCore.print('2'); 199 | theGSM3ShieldV1ModemCore.print('\r'); 200 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 201 | break; 202 | case 2: 203 | // Parse response to QISRVC 204 | theGSM3ShieldV1ModemCore.genericParse_rsp(resp); 205 | if(resp) 206 | { 207 | // Send QICLOSE command 208 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE="),false); 209 | theGSM3ShieldV1ModemCore.print(idSocket); 210 | theGSM3ShieldV1ModemCore.print('\r'); 211 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 212 | } 213 | else 214 | theGSM3ShieldV1ModemCore.closeCommand(3); 215 | break; 216 | case 3: 217 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 218 | { 219 | theGSM3ShieldV1ModemCore.setCommandCounter(0); 220 | if (resp) 221 | theGSM3ShieldV1ModemCore.closeCommand(1); 222 | else 223 | theGSM3ShieldV1ModemCore.closeCommand(3); 224 | } 225 | break; 226 | } 227 | } 228 | 229 | //Write socket first chain main function. 230 | void GSM3ShieldV1MultiClientProvider::beginWriteSocket(bool client1Server0, int id_socket) 231 | { 232 | idSocket = id_socket; 233 | client1_server0 = client1Server0; 234 | theGSM3ShieldV1ModemCore.openCommand(this,BEGINWRITESOCKET); 235 | beginWriteSocketContinue(); 236 | } 237 | 238 | //Write socket first chain continue function. 239 | void GSM3ShieldV1MultiClientProvider::beginWriteSocketContinue() 240 | { 241 | bool resp; 242 | // 1: Send AT+QISRVC 243 | // 2: Send AT+QISEND 244 | // 3: wait for > and Write text 245 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 246 | case 1: 247 | // AT+QISRVC 248 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false); 249 | if (client1_server0) 250 | theGSM3ShieldV1ModemCore.print('1'); 251 | else 252 | theGSM3ShieldV1ModemCore.print('2'); 253 | theGSM3ShieldV1ModemCore.print('\r'); 254 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 255 | break; 256 | case 2: 257 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 258 | { 259 | // Response received 260 | if(resp) 261 | { 262 | // AT+QISEND 263 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISEND="), false); 264 | theGSM3ShieldV1ModemCore.print(idSocket); 265 | theGSM3ShieldV1ModemCore.print('\r'); 266 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 267 | } 268 | else 269 | { 270 | theGSM3ShieldV1ModemCore.closeCommand(3); 271 | } 272 | } 273 | break; 274 | case 3: 275 | char aux[2]; 276 | aux[0]='>'; 277 | aux[1]=0; 278 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux)) 279 | { 280 | if(resp) 281 | { 282 | // Received ">" 283 | theGSM3ShieldV1ModemCore.closeCommand(1); 284 | } 285 | else 286 | { 287 | theGSM3ShieldV1ModemCore.closeCommand(3); 288 | } 289 | } 290 | break; 291 | } 292 | } 293 | 294 | //Write socket next chain function. 295 | void GSM3ShieldV1MultiClientProvider::writeSocket(const char* buf) 296 | { 297 | theGSM3ShieldV1ModemCore.print(buf); 298 | } 299 | 300 | //Write socket character function. 301 | void GSM3ShieldV1MultiClientProvider::writeSocket(char c) 302 | { 303 | theGSM3ShieldV1ModemCore.print(c); 304 | } 305 | 306 | //Write socket last chain main function. 307 | void GSM3ShieldV1MultiClientProvider::endWriteSocket() 308 | { 309 | theGSM3ShieldV1ModemCore.openCommand(this,ENDWRITESOCKET); 310 | endWriteSocketContinue(); 311 | } 312 | 313 | //Write socket last chain continue function. 314 | void GSM3ShieldV1MultiClientProvider::endWriteSocketContinue() 315 | { 316 | bool resp; 317 | // 1: Write text (ctrl-Z) 318 | // 2: Wait for OK 319 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 320 | case 1: 321 | theGSM3ShieldV1ModemCore.write(26); // Ctrl-Z 322 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 323 | break; 324 | case 2: 325 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 326 | { 327 | // OK received 328 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 329 | else theGSM3ShieldV1ModemCore.closeCommand(3); 330 | } 331 | break; 332 | } 333 | } 334 | 335 | //Available socket main function. 336 | int GSM3ShieldV1MultiClientProvider::availableSocket(bool client1Server0, int id_socket) 337 | { 338 | if(flagReadingSocket==1) 339 | { 340 | theGSM3ShieldV1ModemCore.setCommandError(1); 341 | return 1; 342 | } 343 | client1_server0 = client1Server0; 344 | idSocket = id_socket; 345 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET); 346 | availableSocketContinue(); 347 | return theGSM3ShieldV1ModemCore.getCommandError(); 348 | } 349 | 350 | //Available socket continue function. 351 | void GSM3ShieldV1MultiClientProvider::availableSocketContinue() 352 | { 353 | bool resp; 354 | // 1: AT+QIRD 355 | // 2: Wait for OK and Next necessary AT+QIRD 356 | 357 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 358 | case 1: 359 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIRD=0,"),false); 360 | if (client1_server0) 361 | theGSM3ShieldV1ModemCore.print('1'); 362 | else 363 | theGSM3ShieldV1ModemCore.print('2'); 364 | theGSM3ShieldV1ModemCore.print(','); 365 | theGSM3ShieldV1ModemCore.print(idSocket); 366 | theGSM3ShieldV1ModemCore.print(",1500"); 367 | // theGSM3ShieldV1ModemCore.print(",120"); 368 | theGSM3ShieldV1ModemCore.print('\r'); 369 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 370 | break; 371 | case 2: 372 | if(parseQIRD_head(resp)) 373 | { 374 | if (!resp) 375 | { 376 | theGSM3ShieldV1ModemCore.closeCommand(4); 377 | } 378 | else 379 | { 380 | flagReadingSocket=1; 381 | theGSM3ShieldV1ModemCore.closeCommand(1); 382 | } 383 | } 384 | else 385 | { 386 | theGSM3ShieldV1ModemCore.closeCommand(3); 387 | } 388 | break; 389 | } 390 | } 391 | 392 | //Read Socket Parse head. 393 | bool GSM3ShieldV1MultiClientProvider::parseQIRD_head(bool& rsp) 394 | { 395 | char _qird [8]; 396 | prepareAuxLocate(PSTR("+QIRD:"), _qird); 397 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 398 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(_qird)) 399 | { 400 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true); 401 | // Saving more memory, reuse _qird 402 | _qird[0]='\n'; 403 | _qird[1]=0; 404 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true); 405 | rsp = true; 406 | return true; 407 | } 408 | else if(theGSM3ShieldV1ModemCore.theBuffer().locate("OK")) 409 | { 410 | rsp = false; 411 | return true; 412 | } 413 | else 414 | { 415 | rsp = false; 416 | return false; 417 | } 418 | } 419 | /* 420 | //Read socket main function. 421 | int GSM3ShieldV1MultiClientProvider::readSocket() 422 | { 423 | char charSocket; 424 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read(); 425 | //Case buffer not full 426 | if (!fullBufferSocket) 427 | { 428 | //The last part of the buffer after data is CRLFOKCRLF 429 | if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125) 430 | { 431 | //Start again availableSocket function. 432 | flagReadingSocket=0; 433 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET); 434 | availableSocketContinue(); 435 | } 436 | } 437 | else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127) 438 | { 439 | // The buffer is full, no more action is possible until we have read() 440 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 441 | flagReadingSocket = 1; 442 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 443 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 444 | //A small delay to assure data received after xon. 445 | delay(10); 446 | } 447 | //To distinguish the case no more available data in socket. 448 | if (ready()==1) 449 | return charSocket; 450 | else 451 | return 0; 452 | } 453 | */ 454 | int GSM3ShieldV1MultiClientProvider::readSocket() 455 | { 456 | char charSocket; 457 | 458 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0) 459 | { 460 | Serial.println();Serial.println("*"); 461 | return 0; 462 | } 463 | 464 | charSocket = theGSM3ShieldV1ModemCore.theBuffer().read(); 465 | //Case buffer not full 466 | if (!fullBufferSocket) 467 | { 468 | //The last part of the buffer after data is CRLFOKCRLF 469 | if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125) 470 | { 471 | //Start again availableSocket function. 472 | flagReadingSocket=0; 473 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET); 474 | availableSocketContinue(); 475 | } 476 | } 477 | else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()>=100) 478 | { 479 | // The buffer was full, we have to let the data flow again 480 | // theGSM3ShieldV1ModemCore.theBuffer().flush(); 481 | flagReadingSocket = 1; 482 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 483 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 484 | //A small delay to assure data received after xon. 485 | delay(100); 486 | if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes() >=6) 487 | fullBufferSocket=false; 488 | } 489 | 490 | return charSocket; 491 | 492 | } 493 | 494 | //Read socket main function. 495 | int GSM3ShieldV1MultiClientProvider::peekSocket() 496 | { 497 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0); 498 | } 499 | 500 | 501 | //Flush SMS main function. 502 | void GSM3ShieldV1MultiClientProvider::flushSocket() 503 | { 504 | flagReadingSocket=0; 505 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET); 506 | flushSocketContinue(); 507 | } 508 | 509 | //Send SMS continue function. 510 | void GSM3ShieldV1MultiClientProvider::flushSocketContinue() 511 | { 512 | bool resp; 513 | // 1: Deleting SMS 514 | // 2: wait for OK 515 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 516 | case 1: 517 | //DEBUG 518 | //Serial.println("Flushing Socket."); 519 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 520 | if (fullBufferSocket) 521 | { 522 | //Serial.println("Buffer flushed."); 523 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 524 | } 525 | else 526 | { 527 | //Serial.println("Socket flushed completely."); 528 | theGSM3ShieldV1ModemCore.closeCommand(1); 529 | } 530 | break; 531 | } 532 | } 533 | 534 | //URC recognize. 535 | // Momentarily, we will not recognize "closes" in client mode 536 | bool GSM3ShieldV1MultiClientProvider::recognizeUnsolicitedEvent(byte oldTail) 537 | { 538 | return false; 539 | } 540 | 541 | int GSM3ShieldV1MultiClientProvider::getSocket(int socket) 542 | { 543 | if(socket==-1) 544 | { 545 | int i; 546 | for(i=minSocket(); i<=maxSocket(); i++) 547 | { 548 | if (!(sockets&(0x0001<8) 575 | return 0; 576 | if(sockets&(0x0001< 2 | #include 3 | #include 4 | 5 | #define __NCLIENTS_MAX__ 3 6 | 7 | char _command_QILOCIP[] PROGMEM = "AT+QILOCIP"; 8 | 9 | GSM3ShieldV1MultiServerProvider::GSM3ShieldV1MultiServerProvider() 10 | { 11 | theGSM3MobileServerProvider=this; 12 | socketsAsServer=0; 13 | socketsAccepted=0; 14 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 15 | }; 16 | 17 | //Response management. 18 | void GSM3ShieldV1MultiServerProvider::manageResponse(byte from, byte to) 19 | { 20 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 21 | { 22 | case NONE: 23 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 24 | break; 25 | case CONNECTSERVER: 26 | connectTCPServerContinue(); 27 | break; 28 | case GETIP: 29 | getIPContinue(); 30 | break; 31 | } 32 | } 33 | 34 | //Connect Server main function. 35 | int GSM3ShieldV1MultiServerProvider::connectTCPServer(int port) 36 | { 37 | // We forget about LocalIP as it has no real use, the modem does whatever it likes 38 | theGSM3ShieldV1ModemCore.setPort(port); 39 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTSERVER); 40 | connectTCPServerContinue(); 41 | return theGSM3ShieldV1ModemCore.getCommandError(); 42 | } 43 | 44 | //Connect Server continue function. 45 | void GSM3ShieldV1MultiServerProvider::connectTCPServerContinue() 46 | { 47 | 48 | bool resp; 49 | // 1: Read Local IP "AT+QILOCIP" 50 | // 2: Waiting for IP and Set local port "AT+QILPORT" 51 | // 3: Waiting for QILPOR OK andConfigure as server "AT+QISERVER" 52 | // 4: Wait for SERVER OK 53 | 54 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 55 | case 1: 56 | //"AT+QILOCIP." 57 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_QILOCIP); 58 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 59 | break; 60 | case 2: 61 | //Not IP storing but the command is necessary. 62 | //if(parseQILOCIP_rsp(local_IP, local_IP_Length, resp)) 63 | // This awful trick saves some RAM bytes 64 | char aux[3]; 65 | aux[0]='\r';aux[1]='\n';aux[2]=0; 66 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux)) 67 | { 68 | //Response received 69 | if(resp) 70 | { 71 | // Great. Go for the next step 72 | // AT+QILPORT 73 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILPORT=\"TCP\","),false); 74 | theGSM3ShieldV1ModemCore.print( theGSM3ShieldV1ModemCore.getPort()); 75 | theGSM3ShieldV1ModemCore.print('\r'); 76 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 77 | } 78 | else theGSM3ShieldV1ModemCore.closeCommand(3); 79 | } 80 | break; 81 | case 3: 82 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 83 | { 84 | // Response received 85 | if(resp) 86 | { 87 | // OK received 88 | // Great. Go for the next step 89 | // AT+QISERVER 90 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISERVER=0,"),false); 91 | theGSM3ShieldV1ModemCore.print(__NCLIENTS_MAX__); 92 | theGSM3ShieldV1ModemCore.print('\r'); 93 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 94 | } 95 | else theGSM3ShieldV1ModemCore.closeCommand(3); 96 | } 97 | break; 98 | case 4: 99 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 100 | { 101 | // Response received 102 | // OK received, kathapoon, chessespoon 103 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 104 | else theGSM3ShieldV1ModemCore.closeCommand(3); 105 | } 106 | break; 107 | } 108 | } 109 | 110 | //QILOCIP parse. 111 | bool GSM3ShieldV1MultiServerProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp) 112 | { 113 | if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength))) 114 | rsp = false; 115 | else 116 | rsp = true; 117 | return true; 118 | } 119 | 120 | //Get IP main function. 121 | int GSM3ShieldV1MultiServerProvider::getIP(char* LocalIP, int LocalIPlength) 122 | { 123 | theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP); 124 | theGSM3ShieldV1ModemCore.setPort(LocalIPlength); 125 | theGSM3ShieldV1ModemCore.openCommand(this,GETIP); 126 | getIPContinue(); 127 | return theGSM3ShieldV1ModemCore.getCommandError(); 128 | } 129 | 130 | void GSM3ShieldV1MultiServerProvider::getIPContinue() 131 | { 132 | 133 | bool resp; 134 | // 1: Read Local IP "AT+QILOCIP" 135 | // 2: Waiting for IP. 136 | 137 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 138 | case 1: 139 | //AT+QILOCIP 140 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_QILOCIP); 141 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 142 | break; 143 | case 2: 144 | if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp)) 145 | { 146 | if (resp) 147 | theGSM3ShieldV1ModemCore.closeCommand(1); 148 | else 149 | theGSM3ShieldV1ModemCore.closeCommand(3); 150 | } 151 | break; 152 | } 153 | } 154 | 155 | bool GSM3ShieldV1MultiServerProvider::getSocketAsServerModemStatus(int s) 156 | { 157 | if (socketsAccepted&(0x0001< 2 | #include 3 | 4 | GSM3ShieldV1SMSProvider::GSM3ShieldV1SMSProvider() 5 | { 6 | theGSM3SMSProvider=this; 7 | }; 8 | 9 | //Send SMS begin function. 10 | int GSM3ShieldV1SMSProvider::beginSMS(const char* to) 11 | { 12 | if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY)&&(theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY)) 13 | return 2; 14 | 15 | theGSM3ShieldV1ModemCore.setPhoneNumber((char*)to); 16 | theGSM3ShieldV1ModemCore.openCommand(this,BEGINSMS); 17 | beginSMSContinue(); 18 | return theGSM3ShieldV1ModemCore.getCommandError(); 19 | } 20 | 21 | //Send SMS continue function. 22 | void GSM3ShieldV1SMSProvider::beginSMSContinue() 23 | { 24 | bool resp; 25 | // 1: Send AT 26 | // 2: wait for > and write text 27 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 28 | case 1: 29 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 30 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGS=\""), false); 31 | theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber()); 32 | theGSM3ShieldV1ModemCore.print("\"\r"); 33 | break; 34 | case 2: 35 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, ">")) 36 | { 37 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 38 | else theGSM3ShieldV1ModemCore.closeCommand(3); 39 | } 40 | break; 41 | } 42 | } 43 | 44 | //Send SMS write function. 45 | void GSM3ShieldV1SMSProvider::writeSMS(char c) 46 | { 47 | theGSM3ShieldV1ModemCore.write(c); 48 | } 49 | 50 | //Send SMS begin function. 51 | int GSM3ShieldV1SMSProvider::endSMS() 52 | { 53 | theGSM3ShieldV1ModemCore.openCommand(this,ENDSMS); 54 | endSMSContinue(); 55 | return theGSM3ShieldV1ModemCore.getCommandError(); 56 | } 57 | 58 | //Send SMS continue function. 59 | void GSM3ShieldV1SMSProvider::endSMSContinue() 60 | { 61 | bool resp; 62 | // 1: Send #26 63 | // 2: wait for OK 64 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 65 | case 1: 66 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 67 | theGSM3ShieldV1ModemCore.write(26); 68 | theGSM3ShieldV1ModemCore.print("\r"); 69 | break; 70 | case 2: 71 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 72 | { 73 | if (resp) 74 | theGSM3ShieldV1ModemCore.closeCommand(1); 75 | else 76 | theGSM3ShieldV1ModemCore.closeCommand(3); 77 | } 78 | break; 79 | } 80 | } 81 | 82 | //Available SMS main function. 83 | int GSM3ShieldV1SMSProvider::availableSMS() 84 | { 85 | flagReadingSMS = 0; 86 | theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESMS); 87 | availableSMSContinue(); 88 | return theGSM3ShieldV1ModemCore.getCommandError(); 89 | } 90 | 91 | //Available SMS continue function. 92 | void GSM3ShieldV1SMSProvider::availableSMSContinue() 93 | { 94 | // 1: AT+CMGL="REC UNREAD",1 95 | // 2: Receive +CMGL: _id_ ... READ","_numero_" ... \n_mensaje_\nOK 96 | // 3: Send AT+CMGD= _id_ 97 | // 4: Receive OK 98 | // 5: Remaining SMS text in case full buffer. 99 | // This implementation really does not care much if the modem aswers trash to CMGL 100 | bool resp; 101 | //int msglength_aux; 102 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 103 | case 1: 104 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGL=\"REC UNREAD\",1")); 105 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 106 | break; 107 | case 2: 108 | if(parseCMGL_available(resp)) 109 | { 110 | if (!resp) theGSM3ShieldV1ModemCore.closeCommand(4); 111 | else theGSM3ShieldV1ModemCore.closeCommand(1); 112 | } 113 | break; 114 | } 115 | 116 | } 117 | 118 | //SMS available parse. 119 | bool GSM3ShieldV1SMSProvider::parseCMGL_available(bool& rsp) 120 | { 121 | fullBufferSMS = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 122 | if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+CMGL:", true))) 123 | rsp = false; 124 | else 125 | rsp = true; 126 | idSMS=theGSM3ShieldV1ModemCore.theBuffer().readInt(); 127 | 128 | //If there are 2 SMS in buffer, response is ...CRLFCRLF+CMGL 129 | twoSMSinBuffer = theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+"); 130 | 131 | checkSecondBuffer = 0; 132 | 133 | return true; 134 | } 135 | 136 | //remoteNumber SMS function. 137 | int GSM3ShieldV1SMSProvider::remoteSMSNumber(char* number, int nlength) 138 | { 139 | theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("READ\",\"", "\"", number, nlength); 140 | 141 | return 1; 142 | } 143 | 144 | //remoteNumber SMS function. 145 | int GSM3ShieldV1SMSProvider::readSMS() 146 | { 147 | char charSMS; 148 | //First char. 149 | if (!flagReadingSMS) 150 | { 151 | flagReadingSMS = 1; 152 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil("\n", true); 153 | } 154 | charSMS = theGSM3ShieldV1ModemCore.theBuffer().read(); 155 | 156 | //Second Buffer. 157 | if (checkSecondBuffer) 158 | { 159 | checkSecondBuffer = 0; 160 | twoSMSinBuffer = theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+"); 161 | } 162 | 163 | //Case the last char in buffer. 164 | if ((!twoSMSinBuffer)&&fullBufferSMS&&(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127)) 165 | { 166 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 167 | fullBufferSMS = 0; 168 | checkSecondBuffer = 1; 169 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 170 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 171 | delay(10); 172 | 173 | return charSMS; 174 | } 175 | //Case two SMS in buffer 176 | else if (twoSMSinBuffer) 177 | { 178 | if (theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+")) 179 | { 180 | return charSMS; 181 | } 182 | else 183 | { 184 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 185 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 186 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 187 | delay(10); 188 | return 0; 189 | } 190 | } 191 | //Case 1 SMS and buffer not full 192 | else if (!fullBufferSMS) 193 | { 194 | if (theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\nOK")) 195 | { 196 | return charSMS; 197 | } 198 | else 199 | { 200 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 201 | theGSM3ShieldV1ModemCore.openCommand(this,XON); 202 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 203 | delay(10); 204 | return 0; 205 | } 206 | } 207 | //Case to read all the chars in buffer to the end. 208 | else 209 | { 210 | return charSMS; 211 | } 212 | } 213 | 214 | //Read socket main function. 215 | int GSM3ShieldV1SMSProvider::peekSMS() 216 | { 217 | if (!flagReadingSMS) 218 | { 219 | flagReadingSMS = 1; 220 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil("\n", true); 221 | } 222 | 223 | return theGSM3ShieldV1ModemCore.theBuffer().peek(0); 224 | } 225 | 226 | //Flush SMS main function. 227 | void GSM3ShieldV1SMSProvider::flushSMS() 228 | { 229 | 230 | //With this, sms data can fill up to 2x128+5x128 bytes. 231 | for (int aux = 0;aux<5;aux++) 232 | { 233 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 234 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 235 | delay(10); 236 | } 237 | 238 | theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSMS); 239 | flushSMSContinue(); 240 | } 241 | 242 | //Send SMS continue function. 243 | void GSM3ShieldV1SMSProvider::flushSMSContinue() 244 | { 245 | bool resp; 246 | // 1: Deleting SMS 247 | // 2: wait for OK 248 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 249 | case 1: 250 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 251 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGD="), false); 252 | theGSM3ShieldV1ModemCore.print(idSMS); 253 | theGSM3ShieldV1ModemCore.print("\r"); 254 | break; 255 | case 2: 256 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 257 | { 258 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 259 | else theGSM3ShieldV1ModemCore.closeCommand(3); 260 | } 261 | break; 262 | } 263 | } 264 | 265 | void GSM3ShieldV1SMSProvider::manageResponse(byte from, byte to) 266 | { 267 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 268 | { 269 | /* case XON: 270 | if (flagReadingSocket) 271 | { 272 | // flagReadingSocket = 0; 273 | fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3); 274 | } 275 | else theGSM3ShieldV1ModemCore.openCommand(this,NONE); 276 | break; 277 | */ case NONE: 278 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 279 | break; 280 | case BEGINSMS: 281 | beginSMSContinue(); 282 | break; 283 | case ENDSMS: 284 | endSMSContinue(); 285 | break; 286 | case AVAILABLESMS: 287 | availableSMSContinue(); 288 | break; 289 | case FLUSHSMS: 290 | flushSMSContinue(); 291 | break; 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /GSM3ShieldV1SMSProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1SMSProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1ScanNetworks.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1ScanNetworks.cpp -------------------------------------------------------------------------------- /GSM3ShieldV1ScanNetworks.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1ScanNetworks.h -------------------------------------------------------------------------------- /GSM3ShieldV1ServerProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | GSM3ShieldV1ServerProvider::GSM3ShieldV1ServerProvider() 6 | { 7 | theGSM3MobileServerProvider=this; 8 | }; 9 | 10 | //Response management. 11 | void GSM3ShieldV1ServerProvider::manageResponse(byte from, byte to) 12 | { 13 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 14 | { 15 | case NONE: 16 | theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from); 17 | break; 18 | case CONNECTSERVER: 19 | connectTCPServerContinue(); 20 | break; 21 | /*case GETIP: 22 | getIPContinue(); 23 | break;*/ 24 | } 25 | } 26 | 27 | //Connect Server main function. 28 | int GSM3ShieldV1ServerProvider::connectTCPServer(int port) 29 | { 30 | // We forget about LocalIP as it has no real use, the modem does whatever it likes 31 | theGSM3ShieldV1ModemCore.setPort(port); 32 | theGSM3ShieldV1ModemCore.openCommand(this,CONNECTSERVER); 33 | // From this moment on we wait for a call 34 | connectTCPServerContinue(); 35 | return theGSM3ShieldV1ModemCore.getCommandError(); 36 | } 37 | 38 | //Connect Server continue function. 39 | void GSM3ShieldV1ServerProvider::connectTCPServerContinue() 40 | { 41 | 42 | bool resp; 43 | // 1: Read Local IP "AT+QILOCIP" 44 | // 2: Waiting for IP and Set local port "AT+QILPORT" 45 | // 3: Waiting for QILPOR OK andConfigure as server "AT+QISERVER" 46 | // 4: Wait for SERVER OK 47 | 48 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 49 | case 1: 50 | //"AT+QILOCIP." 51 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILOCIP")); 52 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 53 | break; 54 | case 2: 55 | //Not IP storing but the command is necessary. 56 | //if(parseQILOCIP_rsp(local_IP, local_IP_Length, resp)) 57 | // This awful trick saves some RAM bytes 58 | char aux[3]; 59 | aux[0]='\r';aux[1]='\n';aux[2]=0; 60 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux)) 61 | { 62 | //Response received 63 | if(resp) 64 | { 65 | // Great. Go for the next step 66 | // AT+QILPORT 67 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILPORT=\"TCP\","),false); 68 | theGSM3ShieldV1ModemCore.print( theGSM3ShieldV1ModemCore.getPort()); 69 | theGSM3ShieldV1ModemCore.print('\r'); 70 | theGSM3ShieldV1ModemCore.setCommandCounter(3); 71 | } 72 | else theGSM3ShieldV1ModemCore.closeCommand(3); 73 | } 74 | break; 75 | case 3: 76 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 77 | { 78 | // Response received 79 | if(resp) 80 | { 81 | // OK received 82 | // Great. Go for the next step 83 | // AT+QISERVER 84 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISERVER"),true); 85 | theGSM3ShieldV1ModemCore.setCommandCounter(4); 86 | } 87 | else theGSM3ShieldV1ModemCore.closeCommand(3); 88 | } 89 | break; 90 | case 4: 91 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 92 | { 93 | // Response received 94 | // OK received, kathapoon, chessespoon 95 | if (resp) 96 | { 97 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 98 | theGSM3ShieldV1ModemCore.closeCommand(1); 99 | } 100 | else 101 | theGSM3ShieldV1ModemCore.closeCommand(3); 102 | } 103 | break; 104 | } 105 | } 106 | 107 | //QILOCIP parse. 108 | /*bool GSM3ShieldV1ServerProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp) 109 | { 110 | if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength))) 111 | rsp = false; 112 | else 113 | rsp = true; 114 | return true; 115 | } 116 | 117 | //Get IP main function. 118 | int GSM3ShieldV1ServerProvider::getIP(char* LocalIP, int LocalIPlength) 119 | { 120 | theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP); 121 | theGSM3ShieldV1ModemCore.setPort(LocalIPlength); 122 | theGSM3ShieldV1ModemCore.openCommand(this,GETIP); 123 | getIPContinue(); 124 | return theGSM3ShieldV1ModemCore.getCommandError(); 125 | } 126 | 127 | void GSM3ShieldV1ServerProvider::getIPContinue() 128 | { 129 | 130 | bool resp; 131 | // 1: Read Local IP "AT+QILOCIP" 132 | // 2: Waiting for IP. 133 | 134 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 135 | case 1: 136 | //AT+QILOCIP 137 | theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MonoQILOCIP); 138 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 139 | break; 140 | case 2: 141 | if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp)) 142 | { 143 | if (resp) 144 | theGSM3ShieldV1ModemCore.closeCommand(1); 145 | else 146 | theGSM3ShieldV1ModemCore.closeCommand(3); 147 | } 148 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 149 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 150 | break; 151 | } 152 | }*/ 153 | 154 | bool GSM3ShieldV1ServerProvider::getSocketAsServerModemStatus(int s) 155 | { 156 | if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) 157 | return true; 158 | else 159 | return false; 160 | } 161 | 162 | 163 | //URC recognize. 164 | bool GSM3ShieldV1ServerProvider::recognizeUnsolicitedEvent(byte oldTail) 165 | { 166 | 167 | int nlength; 168 | char auxLocate [15]; 169 | 170 | //REMOTE SOCKET CLOSED. 171 | prepareAuxLocate(PSTR("CLOSED\r\n"), auxLocate); 172 | if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate)) 173 | { 174 | //To detect remote socket closed for example inside socket data. 175 | theGSM3ShieldV1ModemCore.setStatus(GPRS_READY); 176 | } 177 | 178 | 179 | //REMOTE SOCKET ACCEPTED. 180 | prepareAuxLocate(PSTR("CONNECT\r\n"), auxLocate); 181 | if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate)) 182 | { 183 | //To detect remote socket closed for example inside socket data. 184 | theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, true); 185 | theGSM3ShieldV1ModemCore.gss.spaceAvailable(); 186 | theGSM3ShieldV1ModemCore.setStatus(TRANSPARENT_CONNECTED); 187 | return true; 188 | } 189 | 190 | return false; 191 | } 192 | 193 | bool GSM3ShieldV1ServerProvider::getStatusSocketAsServer(uint8_t socket) 194 | { 195 | return(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED); 196 | }; 197 | 198 | void GSM3ShieldV1ServerProvider::releaseSocket(int socket) 199 | { 200 | } 201 | 202 | int GSM3ShieldV1ServerProvider::getNewOccupiedSocketAsServer() 203 | { 204 | return 0; 205 | } -------------------------------------------------------------------------------- /GSM3ShieldV1ServerProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1ServerProvider.h -------------------------------------------------------------------------------- /GSM3ShieldV1VoiceProvider.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | GSM3ShieldV1VoiceProvider::GSM3ShieldV1VoiceProvider() 5 | { 6 | phonelength=0; 7 | theGSM3MobileVoiceProvider=this; 8 | } 9 | 10 | void GSM3ShieldV1VoiceProvider::initialize() 11 | { 12 | theGSM3ShieldV1ModemCore.registerUMProvider(this); 13 | } 14 | 15 | //Voice Call main function. 16 | int GSM3ShieldV1VoiceProvider::voiceCall(const char* to) 17 | { 18 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATD"),false); 19 | theGSM3ShieldV1ModemCore.print(to); 20 | theGSM3ShieldV1ModemCore.print(";\r"); 21 | setvoiceCallStatus(CALLING); 22 | return 1; 23 | } 24 | 25 | //Retrieve calling number main function. 26 | int GSM3ShieldV1VoiceProvider::retrieveCallingNumber (char* buffer, int bufsize) 27 | { 28 | theGSM3ShieldV1ModemCore.setPhoneNumber(buffer); 29 | phonelength = bufsize; 30 | theGSM3ShieldV1ModemCore.setCommandError(0); 31 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 32 | theGSM3ShieldV1ModemCore.openCommand(this,RETRIEVECALLINGNUMBER); 33 | retrieveCallingNumberContinue(); 34 | return theGSM3ShieldV1ModemCore.getCommandError(); 35 | } 36 | 37 | //Retrieve calling number Continue function. 38 | void GSM3ShieldV1VoiceProvider::retrieveCallingNumberContinue() 39 | { 40 | // 1: AT+CLCC 41 | // 2: Receive +CLCC: 1,1,4,0,0,"num",129,"" 42 | // This implementation really does not care much if the modem aswers trash to CMGL 43 | bool resp; 44 | //int msglength_aux; 45 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 46 | case 1: 47 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLCC")); 48 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 49 | break; 50 | case 2: 51 | if(parseCLCC(theGSM3ShieldV1ModemCore.getPhoneNumber(), phonelength)) 52 | { 53 | theGSM3ShieldV1ModemCore.closeCommand(1); 54 | } 55 | break; 56 | } 57 | } 58 | 59 | //CLCC parse. 60 | bool GSM3ShieldV1VoiceProvider::parseCLCC(char* number, int nlength) 61 | { 62 | theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CLCC: 1,1,4,0,0,\"","\"", number, nlength); 63 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 64 | return true; 65 | } 66 | 67 | //Answer Call main function. 68 | int GSM3ShieldV1VoiceProvider::answerCall() 69 | { 70 | theGSM3ShieldV1ModemCore.setCommandError(0); 71 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 72 | theGSM3ShieldV1ModemCore.openCommand(this,ANSWERCALL); 73 | answerCallContinue(); 74 | return theGSM3ShieldV1ModemCore.getCommandError(); 75 | } 76 | 77 | //Answer Call continue function. 78 | void GSM3ShieldV1VoiceProvider::answerCallContinue() 79 | { 80 | // 1: ATA 81 | // 2: Waiting for OK 82 | 83 | // This implementation really does not care much if the modem aswers trash to CMGL 84 | bool resp; 85 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 86 | case 1: 87 | // ATA ; 88 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATA")); 89 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 90 | break; 91 | case 2: 92 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 93 | { 94 | setvoiceCallStatus(TALKING); 95 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 96 | else theGSM3ShieldV1ModemCore.closeCommand(3); 97 | } 98 | break; 99 | } 100 | } 101 | 102 | //Hang Call main function. 103 | int GSM3ShieldV1VoiceProvider::hangCall() 104 | { 105 | theGSM3ShieldV1ModemCore.setCommandError(0); 106 | theGSM3ShieldV1ModemCore.setCommandCounter(1); 107 | theGSM3ShieldV1ModemCore.openCommand(this,HANGCALL); 108 | hangCallContinue(); 109 | return theGSM3ShieldV1ModemCore.getCommandError(); 110 | } 111 | 112 | //Hang Call continue function. 113 | void GSM3ShieldV1VoiceProvider::hangCallContinue() 114 | { 115 | // 1: ATH 116 | // 2: Waiting for OK 117 | 118 | bool resp; 119 | switch (theGSM3ShieldV1ModemCore.getCommandCounter()) { 120 | case 1: 121 | //ATH 122 | theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATH")); 123 | theGSM3ShieldV1ModemCore.setCommandCounter(2); 124 | break; 125 | case 2: 126 | if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp)) 127 | { 128 | setvoiceCallStatus(IDLE_CALL); 129 | if (resp) theGSM3ShieldV1ModemCore.closeCommand(1); 130 | else theGSM3ShieldV1ModemCore.closeCommand(3); 131 | } 132 | break; 133 | } 134 | } 135 | 136 | //Response management. 137 | void GSM3ShieldV1VoiceProvider::manageResponse(byte from, byte to) 138 | { 139 | switch(theGSM3ShieldV1ModemCore.getOngoingCommand()) 140 | { 141 | case ANSWERCALL: 142 | answerCallContinue(); 143 | break; 144 | case HANGCALL: 145 | hangCallContinue(); 146 | break; 147 | case RETRIEVECALLINGNUMBER: 148 | retrieveCallingNumberContinue(); 149 | break; 150 | 151 | } 152 | } 153 | 154 | //URC recognize. 155 | bool GSM3ShieldV1VoiceProvider::recognizeUnsolicitedEvent(byte oldTail) 156 | { 157 | 158 | int nlength; 159 | char auxLocate [15]; 160 | //RING. 161 | prepareAuxLocate(PSTR("RING"), auxLocate); 162 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 163 | { 164 | // RING 165 | setvoiceCallStatus(RECEIVINGCALL); 166 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 167 | return true; 168 | } 169 | 170 | //CALL ACEPTED. 171 | prepareAuxLocate(PSTR("+COLP:"), auxLocate); 172 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 173 | { 174 | //DEBUG 175 | //Serial.println("Call Accepted."); 176 | setvoiceCallStatus(TALKING); 177 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 178 | return true; 179 | } 180 | 181 | //NO CARRIER. 182 | prepareAuxLocate(PSTR("NO CARRIER"), auxLocate); 183 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 184 | { 185 | //DEBUG 186 | //Serial.println("NO CARRIER received."); 187 | setvoiceCallStatus(IDLE_CALL); 188 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 189 | return true; 190 | } 191 | 192 | //BUSY. 193 | prepareAuxLocate(PSTR("BUSY"), auxLocate); 194 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 195 | { 196 | //DEBUG 197 | //Serial.println("BUSY received."); 198 | setvoiceCallStatus(IDLE_CALL); 199 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 200 | return true; 201 | } 202 | 203 | //CALL RECEPTION. 204 | prepareAuxLocate(PSTR("+CLIP:"), auxLocate); 205 | if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate)) 206 | { 207 | theGSM3ShieldV1ModemCore.theBuffer().flush(); 208 | setvoiceCallStatus(RECEIVINGCALL); 209 | return true; 210 | } 211 | 212 | return false; 213 | } 214 | 215 | 216 | -------------------------------------------------------------------------------- /GSM3ShieldV1VoiceProvider.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3ShieldV1VoiceProvider.h -------------------------------------------------------------------------------- /GSM3SoftSerial.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3SoftSerial.cpp -------------------------------------------------------------------------------- /GSM3SoftSerial.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3SoftSerial.h -------------------------------------------------------------------------------- /GSM3VoiceCallService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3VoiceCallService.cpp -------------------------------------------------------------------------------- /GSM3VoiceCallService.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlueVia/Official-Arduino/ac78e3f943c7c005f317294dba6a9d6c02037ea9/GSM3VoiceCallService.h -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | -------------------------------------------------------------------------------- /MemoryFree.cpp: -------------------------------------------------------------------------------- 1 | extern unsigned int __bss_end; 2 | extern unsigned int __heap_start; 3 | extern void *__brkval; 4 | 5 | 6 | #include "MemoryFree.h"; 7 | 8 | 9 | int freeMemory() { 10 | int free_memory; 11 | 12 | if((int)__brkval == 0) 13 | free_memory = ((int)&free_memory) - ((int)&__bss_end); 14 | else 15 | free_memory = ((int)&free_memory) - ((int)__brkval); 16 | 17 | return free_memory; 18 | } 19 | -------------------------------------------------------------------------------- /examples/GsmChatServer/GsmChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | 8 | Circuit: 9 | * GSM shield attached 10 | 11 | created 18 Dec 2009 12 | by David A. Mellis 13 | modified 8 Mar 2012 14 | by Tom Igoe 15 | 16 | */ 17 | 18 | // libraries 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 | // initialize the library instance 30 | GSMClient client; 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 | boolean gotAMessage = false; // whether or not you got a message from the client yet 39 | 40 | uint8_t bufferRead [50]; // read buffer 41 | 42 | void setup() 43 | { 44 | // initialize serial communications 45 | Serial.begin(9600); 46 | 47 | // connection state 48 | boolean notConnected = true; 49 | 50 | // Start GSM shield 51 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 52 | while(notConnected) 53 | { 54 | if((gsmAccess.begin(PINNUMBER)==GSM_READY) & 55 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 56 | notConnected = false; 57 | else 58 | { 59 | Serial.println("Not connected"); 60 | delay(1000); 61 | } 62 | } 63 | 64 | Serial.println("Connected to GPRS network"); 65 | 66 | // Start server 67 | server.begin(); 68 | waitForResponseServer(); 69 | 70 | // Get IP. 71 | IPAddress LocalIP = gprs.getIPAddress(); 72 | if (!waitForResponseServer()) 73 | { 74 | Serial.println("Couldn't get server IP address"); 75 | while(true); 76 | } 77 | else 78 | { 79 | Serial.println("Server IP address="); 80 | Serial.println(LocalIP); 81 | } 82 | } 83 | 84 | void loop() 85 | { 86 | // listen for incoming clients 87 | GSM3MobileClientService client = server.available(); 88 | 89 | // when the client sends the first byte, say hello: 90 | if (client) 91 | { 92 | while (client.connected()) 93 | { 94 | // say hello 95 | if (!gotAMessage) 96 | { 97 | Serial.println("We have a new client"); 98 | client.println("Hello, client!"); 99 | gotAMessage = true; 100 | } 101 | 102 | client.read(bufferRead, 50); 103 | if (waitForResponseGsm()) 104 | { 105 | client.write(bufferRead); 106 | Serial.print((const char *)bufferRead); // print client message 107 | } 108 | delay(100); 109 | } 110 | 111 | } 112 | } 113 | 114 | /* 115 | Wait for the GSM response 116 | */ 117 | bool waitForResponseGsm() 118 | { 119 | unsigned long m=millis(); 120 | while(((millis()-m)< __TIMEOUT__ )&&(gsmAccess.ready()==0)) 121 | { 122 | // wait for a response from the modem: 123 | delay(1000); 124 | } 125 | if (gsmAccess.ready()==1) return true; 126 | else return false; 127 | } 128 | 129 | /* 130 | Wait for the network server response 131 | */ 132 | bool waitForResponseServer() 133 | { 134 | unsigned long m=millis(); 135 | while(((millis()-m)< __TIMEOUT__ )&&(server.ready()==0)) 136 | { 137 | // wait for a response from the modem: 138 | delay(1000); 139 | } 140 | if (server.ready()==1) return true; 141 | else return false; 142 | } 143 | 144 | -------------------------------------------------------------------------------- /examples/GsmCosmClient/GsmCosmClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Cosm sensor client 3 | 4 | This sketch connects an analog sensor to Cosm (http://www.cosm.com) 5 | using a Telefonica GSM/GPRS shield. 6 | 7 | This example has been updated to use version 2.0 of the Cosm.com API. 8 | To make it work, create a feed with a datastream, and give it the ID 9 | sensor1. Or change the code below to match your feed. 10 | 11 | Circuit: 12 | * Analog sensor attached to analog in 0 13 | * GSM shield attached to pins 10, 11, 12, 13 14 | 15 | created 4 March 2012 16 | by Tom Igoe 17 | and adapted for GSM shield by David Del Peral 18 | 19 | This code is in the public domain. 20 | 21 | */ 22 | 23 | // libraries 24 | #include 25 | 26 | // Cosm Client data 27 | #define APIKEY "YOUR API KEY GOES HERE" // replace your cosm api key here 28 | #define FEEDID 00000 // replace your feed ID 29 | #define USERAGENT "My Project" // user agent is the project name 30 | 31 | // PIN Number 32 | #define PINNUMBER "" 33 | 34 | // APN data 35 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN 36 | #define GPRS_LOGIN "login" // replace with your GPRS login 37 | #define GPRS_PASSWORD "password" // replace with your GPRS password 38 | 39 | // initialize the library instance: 40 | GSMClient client; 41 | GPRS gprs; 42 | GSM gsmAccess; // include a 'true' parameter for debug enabled 43 | 44 | // if you don't want to use DNS (and reduce your sketch size) 45 | // use the numeric IP instead of the name for the server: 46 | //IPAddress server(216,52,233,121); // numeric IP for api.cosm.com 47 | char server[] = "api.cosm.com"; // name address for cosm API 48 | 49 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 50 | boolean lastConnected = false; // state of the connection last time through the main loop 51 | const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com 52 | 53 | void setup() 54 | { 55 | // initialize serial communications 56 | Serial.begin(9600); 57 | 58 | // connection state 59 | boolean notConnected = true; 60 | 61 | // Start GSM shield 62 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 63 | while(notConnected) 64 | { 65 | if((gsmAccess.begin(PINNUMBER)==GSM_READY) & 66 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 67 | notConnected = false; 68 | else 69 | { 70 | Serial.println("Not connected"); 71 | delay(1000); 72 | } 73 | } 74 | } 75 | 76 | void loop() 77 | { 78 | // read the analog sensor: 79 | int sensorReading = analogRead(A0); 80 | 81 | // if there's incoming data from the net connection. 82 | // send it out the serial port. This is for debugging 83 | // purposes only: 84 | if (client.available()) 85 | { 86 | char c = client.read(); 87 | Serial.print(c); 88 | } 89 | 90 | // if there's no net connection, but there was one last time 91 | // through the loop, then stop the client: 92 | if (!client.connected() && lastConnected) 93 | { 94 | client.stop(); 95 | } 96 | 97 | // if you're not connected, and ten seconds have passed since 98 | // your last connection, then connect again and send data: 99 | if(!client.connected() && ((millis() - lastConnectionTime) > postingInterval)) 100 | { 101 | sendData(sensorReading); 102 | } 103 | 104 | // store the state of the connection for next time through 105 | // the loop: 106 | lastConnected = client.connected(); 107 | } 108 | 109 | /* 110 | This method makes a HTTP connection to the server. 111 | */ 112 | void sendData(int thisData) 113 | { 114 | // if there's a successful connection: 115 | if (client.connect(server, 80)) 116 | { 117 | Serial.println("connecting..."); 118 | 119 | // send the HTTP PUT request: 120 | client.print("PUT /v2/feeds/"); 121 | client.print(FEEDID); 122 | client.println(".csv HTTP/1.1"); 123 | client.print("Host: api.cosm.com\n"); 124 | client.print("X-ApiKey: "); 125 | client.println(APIKEY); 126 | client.print("User-Agent: "); 127 | client.println(USERAGENT); 128 | client.print("Content-Length: "); 129 | 130 | // calculate the length of the sensor reading in bytes: 131 | // 8 bytes for "sensor1," + number of digits of the data: 132 | int thisLength = 8 + getLength(thisData); 133 | client.println(thisLength); 134 | 135 | // last pieces of the HTTP PUT request: 136 | client.print("Content-Type: text/csv\n"); 137 | client.println("Connection: close"); 138 | client.println(); 139 | 140 | // here's the actual content of the PUT request: 141 | client.print("sensor1,"); 142 | client.println(thisData); 143 | } 144 | else 145 | { 146 | // if you couldn't make a connection: 147 | Serial.println("connection failed"); 148 | Serial.println(); 149 | Serial.println("disconnecting."); 150 | client.stop(); 151 | } 152 | // note the time that the connection was made or attempted 153 | lastConnectionTime = millis(); 154 | } 155 | 156 | /* 157 | This method calculates the number of digits in the 158 | sensor reading. Since each digit of the ASCII decimal 159 | representation is a byte, the number of digits equals 160 | the number of bytes. 161 | */ 162 | int getLength(int someValue) 163 | { 164 | // there's at least one byte: 165 | int digits = 1; 166 | 167 | // continually divide the value by ten, 168 | // adding one to the digit count for each 169 | // time you divide, until you're at 0: 170 | int dividend = someValue /10; 171 | while (dividend > 0) 172 | { 173 | dividend = dividend /10; 174 | digits++; 175 | } 176 | 177 | // return the number of digits: 178 | return digits; 179 | } 180 | 181 | -------------------------------------------------------------------------------- /examples/GsmCosmClientString/GsmCosmClientString.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Cosm sensor client with Strings 3 | 4 | This sketch connects an analog sensor to Cosm (http://www.cosm.com) 5 | using a Telefonica GSM/GPRS shield. 6 | 7 | This example has been updated to use version 2.0 of the Cosm.com API. 8 | To make it work, create a feed with two datastreams, and give them the IDs 9 | sensor1 and sensor2. Or change the code below to match your feed. 10 | 11 | This example uses the String library, which is part of the Arduino core from 12 | version 0019. 13 | 14 | Circuit: 15 | * Analog sensor attached to analog in 0 16 | * GSM shield attached to pins 10, 11, 12, 13 17 | 18 | created 8 March 2012 19 | by Tom Igoe 20 | and adapted for GSM shield by David Del Peral 21 | 22 | This code is in the public domain. 23 | 24 | */ 25 | 26 | // libraries 27 | #include 28 | 29 | // Pachube data 30 | #define APIKEY "YOUR API KEY GOES HERE" // replace your cosm api key here 31 | #define FEEDID 00000 // replace your feed ID 32 | #define USERAGENT "My Project" // user agent is the project name 33 | 34 | // PIN Number 35 | #define PINNUMBER "" 36 | 37 | // APN data 38 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN 39 | #define GPRS_LOGIN "login" // replace with your GPRS login 40 | #define GPRS_PASSWORD "password" // replace with your GPRS password 41 | 42 | // initialize the library instance 43 | GSMClient client; 44 | GPRS gprs; 45 | GSM gsmAccess; // include a 'true' parameter for debug enabled 46 | 47 | // if you don't want to use DNS (and reduce your sketch size) 48 | // use the numeric IP instead of the name for the server: 49 | //IPAddress server(216,52,233,121); // numeric IP for api.cosm.com 50 | char server[] = "api.cosm.com"; // name address for Cosm API 51 | 52 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 53 | boolean lastConnected = false; // state of the connection last time through the main loop 54 | const unsigned long postingInterval = 10*1000; // delay between updates to Pachube.com 55 | 56 | void setup() 57 | { 58 | // initialize serial communications 59 | Serial.begin(9600); 60 | 61 | // connection state 62 | boolean notConnected = true; 63 | 64 | // Start GSM shield 65 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 66 | while(notConnected) 67 | { 68 | if((gsmAccess.begin(PINNUMBER)==GSM_READY) & 69 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 70 | notConnected = false; 71 | else 72 | { 73 | Serial.println("Not connected"); 74 | delay(1000); 75 | } 76 | } 77 | 78 | Serial.println("Connected to GPRS network"); 79 | } 80 | 81 | void loop() 82 | { 83 | // read the analog sensor 84 | int sensorReading = analogRead(A0); 85 | 86 | // convert the data to a String to send it 87 | String dataString = "sensor1,"; 88 | dataString += sensorReading; 89 | 90 | // you can append multiple readings to this String if your 91 | // pachube feed is set up to handle multiple values 92 | int otherSensorReading = analogRead(A1); 93 | dataString += "\nsensor2,"; 94 | dataString += otherSensorReading; 95 | 96 | // if there's incoming data from the net connection. 97 | // send it out the serial port. This is for debugging 98 | // purposes only 99 | if (client.available()) 100 | { 101 | char c = client.read(); 102 | Serial.print(c); 103 | } 104 | 105 | // if there's no net connection, but there was one last time 106 | // through the loop, then stop the client 107 | if (!client.connected() && lastConnected) 108 | { 109 | Serial.println(); 110 | Serial.println("disconnecting."); 111 | client.stop(); 112 | } 113 | 114 | // if you're not connected, and ten seconds have passed since 115 | // your last connection, then connect again and send data 116 | if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) 117 | { 118 | sendData(dataString); 119 | } 120 | // store the state of the connection for next time through 121 | // the loop 122 | lastConnected = client.connected(); 123 | } 124 | 125 | // this method makes a HTTP connection to the server 126 | void sendData(String thisData) 127 | { 128 | // if there's a successful connection: 129 | if (client.connect(server, 80)) 130 | { 131 | Serial.println("connecting..."); 132 | 133 | // send the HTTP PUT request: 134 | client.print("PUT /v2/feeds/"); 135 | client.print(FEEDID); 136 | client.println(".csv HTTP/1.1"); 137 | client.print("Host: api.cosm.com\n"); 138 | client.print("X-ApiKey: "); 139 | client.println(APIKEY); 140 | client.print("User-Agent: "); 141 | client.println(USERAGENT); 142 | client.print("Content-Length: "); 143 | client.println(thisData.length()); 144 | 145 | // last pieces of the HTTP PUT request 146 | client.print("Content-Type: text/csv\n"); 147 | client.println("Connection: close\n"); 148 | client.println(); 149 | 150 | // here's the actual content of the PUT request 151 | client.println(thisData); 152 | } 153 | else 154 | { 155 | // if you couldn't make a connection 156 | Serial.println("connection failed"); 157 | Serial.println(); 158 | Serial.println("disconnecting."); 159 | client.stop(); 160 | } 161 | // note the time that the connection was made or attempted: 162 | lastConnectionTime = millis(); 163 | } 164 | -------------------------------------------------------------------------------- /examples/GsmTwitterClient/GsmTwitterClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | GSM Twitter Client with Strings 3 | 4 | This sketch connects to Twitter using using an Arduino GSM shield. 5 | It parses the XML returned, and looks for this is a tweet 6 | 7 | This example uses the String library, which is part of the Arduino core from 8 | version 0019. 9 | 10 | Circuit: 11 | * GSM shield attached to pins 10, 11, 12, 13 12 | 13 | created 8 Mar 2012 14 | by Tom Igoe 15 | 16 | This code is in the public domain. 17 | 18 | */ 19 | 20 | // libraries 21 | #include 22 | 23 | // PIN Number 24 | #define PINNUMBER "" 25 | 26 | // APN data 27 | #define GPRS_APN "APN" // replace your GPRS APN 28 | #define GPRS_LOGIN "LOGIN" // replace with your GPRS login 29 | #define GPRS_PASSWORD "PASSWORD" // replace with your GPRS password 30 | 31 | // initialize the library instance 32 | GSMClient client; 33 | GPRS gprs; 34 | GSM gsmAccess; // include a 'true' parameter for debug enabled 35 | 36 | const unsigned long requestInterval = 30*1000; // delay between requests; 30 seconds 37 | 38 | // API Twitter URL 39 | char server[] = "api.twitter.com"; 40 | 41 | boolean requested; // whether you've made a request since connecting 42 | unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds 43 | 44 | String currentLine = ""; // string to hold the text from server 45 | String tweet = ""; // string to hold the tweet 46 | boolean readingTweet = false; // if you're currently reading the tweet 47 | 48 | void setup() 49 | { 50 | // reserve space for the strings: 51 | currentLine.reserve(256); 52 | tweet.reserve(150); 53 | 54 | // initialize serial communications 55 | Serial.begin(9600); 56 | 57 | // connection state 58 | boolean notConnected = true; 59 | 60 | // Start GSM shield 61 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 62 | while(notConnected) 63 | { 64 | if((gsmAccess.begin(PINNUMBER)==GSM_READY) & 65 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 66 | notConnected = false; 67 | else 68 | { 69 | Serial.println("Not connected"); 70 | delay(1000); 71 | } 72 | } 73 | 74 | Serial.println("Connected to GPRS network"); 75 | 76 | Serial.println("connecting..."); 77 | connectToServer(); 78 | } 79 | 80 | 81 | 82 | void loop() 83 | { 84 | char c; 85 | if (client.connected()) 86 | { 87 | if (client.available()) 88 | { 89 | // read incoming bytes: 90 | char inChar = client.read(); 91 | 92 | // add incoming byte to end of line: 93 | currentLine += inChar; 94 | 95 | // if you get a newline, clear the line: 96 | if (inChar == '\n') 97 | { 98 | currentLine = ""; 99 | } 100 | 101 | // if the current line ends with , it will 102 | // be followed by the tweet: 103 | if (currentLine.endsWith("")) 104 | { 105 | // tweet is beginning. Clear the tweet string: 106 | readingTweet = true; 107 | tweet = ""; 108 | } 109 | 110 | // if you're currently reading the bytes of a tweet, 111 | // add them to the tweet String: 112 | if (readingTweet) 113 | { 114 | if (inChar != '<') 115 | { 116 | tweet += inChar; 117 | } 118 | else 119 | { 120 | // if you got a "<" character, 121 | // you've reached the end of the tweet: 122 | readingTweet = false; 123 | Serial.println(tweet); 124 | 125 | // close the connection to the server: 126 | client.stop(); 127 | } 128 | } 129 | } 130 | } 131 | else if (millis() - lastAttemptTime > requestInterval) 132 | { 133 | // if you're not connected, and two minutes have passed since 134 | // your last connection, then attempt to connect again: 135 | connectToServer(); 136 | } 137 | } 138 | 139 | /* 140 | Connect to API Twitter server and do a request for timeline 141 | */ 142 | void connectToServer() 143 | { 144 | // attempt to connect, and wait a millisecond: 145 | Serial.println("connecting to server..."); 146 | if (client.connect(server, 80)) 147 | { 148 | Serial.println("making HTTP request..."); 149 | // make HTTP GET request to twitter: 150 | client.println("GET /1/statuses/user_timeline.xml?screen_name=arduinoteam HTTP/1.1"); 151 | client.println("HOST: api.twitter.com"); 152 | client.println(); 153 | } 154 | // note the time of this connect attempt: 155 | lastAttemptTime = millis(); 156 | } 157 | -------------------------------------------------------------------------------- /examples/GsmWebClient/GsmWebClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web client 3 | 4 | This sketch connects to a website using a GSM shield. 5 | 6 | Circuit: 7 | * GSM shield attached 8 | 9 | created 8 Mar 2012 10 | by Tom Igoe 11 | */ 12 | 13 | // libraries 14 | #include 15 | 16 | // PIN Number 17 | #define PINNUMBER "" 18 | 19 | // APN data 20 | #define GPRS_APN "GPRS_APN" // replace your GPRS APN 21 | #define GPRS_LOGIN "login" // replace with your GPRS login 22 | #define GPRS_PASSWORD "password" // replace with your GPRS password 23 | 24 | // initialize the library instance 25 | GSMClient client; 26 | GPRS gprs; 27 | GSM gsmAccess; // include a 'true' parameter for debug enabled 28 | 29 | // This example downloads the URL "http://arduino.cc/" 30 | 31 | // URL, path & port (for example: arduino.cc) 32 | char server[] = "arduino.cc"; 33 | char path[] = "/"; 34 | int port = 80; // 80 for HTTP 35 | 36 | void setup() 37 | { 38 | // initialize serial communications 39 | Serial.begin(9600); 40 | Serial.println("Starting Arduino web client."); 41 | // connection state 42 | boolean notConnected = true; 43 | 44 | // Start GSM shield 45 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 46 | while(notConnected) 47 | { 48 | if((gsmAccess.begin(PINNUMBER)==GSM_READY) & 49 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 50 | notConnected = false; 51 | else 52 | { 53 | Serial.println("Not connected"); 54 | delay(1000); 55 | } 56 | } 57 | 58 | Serial.println("connecting..."); 59 | 60 | // if you get a connection, report back via serial: 61 | if (client.connect(server, port)) 62 | { 63 | Serial.println("connected"); 64 | // Make a HTTP request: 65 | client.print("GET "); 66 | client.print(path); 67 | client.println(" HTTP/1.0"); 68 | client.println(); 69 | } 70 | else 71 | { 72 | // if you didn't get a connection to the server: 73 | Serial.println("connection failed"); 74 | } 75 | } 76 | 77 | void loop() 78 | { 79 | // if there are incoming bytes available 80 | // from the server, read them and print them: 81 | if (client.available()) 82 | { 83 | char c = client.read(); 84 | Serial.print(c); 85 | } 86 | 87 | // if the server's disconnected, stop the client: 88 | if (!client.available() && !client.connected()) 89 | { 90 | Serial.println(); 91 | Serial.println("disconnecting."); 92 | client.stop(); 93 | 94 | // do nothing forevermore: 95 | for(;;) 96 | ; 97 | } 98 | } 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /examples/GsmWebServer/GsmWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 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 | { 37 | // initialize serial communications 38 | Serial.begin(9600); 39 | 40 | // connection state 41 | boolean notConnected = true; 42 | 43 | // Start GSM shield 44 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 45 | while(notConnected) 46 | { 47 | if((gsmAccess.begin(PINNUMBER)==GSM_READY) & 48 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 49 | notConnected = false; 50 | else 51 | { 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 | GSM3MobileClientService client = server.available(); 73 | 74 | 75 | 76 | if (client) 77 | { 78 | while (client.connected()) 79 | { 80 | if (client.available()) 81 | { 82 | Serial.println("Receiving request!"); 83 | bool sendResponse = false; 84 | while(char c=client.read()) { 85 | if (c == '\n') sendResponse = true; 86 | } 87 | 88 | // if you've gotten to the end of the line (received a newline 89 | // character) 90 | if (sendResponse) 91 | { 92 | // send a standard http response header 93 | client.println("HTTP/1.1 200 OK"); 94 | client.println("Content-Type: text/html"); 95 | client.println(); 96 | client.println(""); 97 | // output the value of each analog input pin 98 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 99 | client.print("analog input "); 100 | client.print(analogChannel); 101 | client.print(" is "); 102 | client.print(analogRead(analogChannel)); 103 | client.println("
"); 104 | } 105 | client.println(""); 106 | //necessary delay 107 | delay(1000); 108 | client.stop(); 109 | } 110 | } 111 | } 112 | } 113 | } 114 | 115 | 116 | -------------------------------------------------------------------------------- /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 | 38 | // initialize serial communications 39 | Serial.begin(9600); 40 | 41 | Serial.println("Make Voice Call"); 42 | 43 | // connection state 44 | boolean notConnected = true; 45 | 46 | // Start GSM shield 47 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 48 | while(notConnected) 49 | { 50 | if(gsmAccess.begin(PINNUMBER)==GSM_READY) 51 | notConnected = false; 52 | else 53 | { 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 | 67 | // add any incoming characters to the String: 68 | while (Serial.available() > 0) 69 | { 70 | char inChar = Serial.read(); 71 | // if it's a newline, that means you should make the call: 72 | if (inChar == '\n') 73 | { 74 | // make sure the phone number is not too long: 75 | if (remoteNumber.length() < 20) 76 | { 77 | // let the user know you're calling: 78 | Serial.print("Calling to : "); 79 | Serial.println(remoteNumber); 80 | Serial.println(); 81 | 82 | // Call the remote number 83 | remoteNumber.toCharArray(charbuffer, 20); 84 | 85 | 86 | // Check if the receiving end has picked up the call 87 | if(vcs.voiceCall(charbuffer)) 88 | { 89 | Serial.println("Call Established. Enter line to end"); 90 | // Wait for some input from the line 91 | while(Serial.read()!='\n' && (vcs.getvoiceCallStatus()==TALKING)); 92 | // And hang up 93 | vcs.hangCall(); 94 | } 95 | Serial.println("Call Finished"); 96 | remoteNumber=""; 97 | Serial.println("Enter phone number to call."); 98 | } 99 | else 100 | { 101 | Serial.println("That's too long for a phone number. I'm forgetting it"); 102 | remoteNumber = ""; 103 | } 104 | } 105 | else 106 | { 107 | // add the latest character to the message to send: 108 | if(inChar!='\r') 109 | remoteNumber += inChar; 110 | } 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /examples/ReceiveSMS/ReceiveSMS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SMS receiver 3 | 4 | This sketch, for the Arduino GSM shield, waits for SMS messages 5 | and displays them through the Serial port. 6 | 7 | Circuit: 8 | * GSM shield 9 | 10 | created 25 Feb 2012 11 | by Javier Zorzano / TD 12 | 13 | This example is in the public domain. 14 | */ 15 | 16 | // libraries 17 | #include 18 | 19 | // PIN Number 20 | #define PINNUMBER "" 21 | 22 | // initialize the library instance 23 | GSM gsmAccess; // include a 'true' parameter for debug enabled 24 | GSM_SMS sms; 25 | 26 | char remoteNumber[20]; // Holds the emitting number 27 | 28 | void setup() 29 | { 30 | // initialize serial communications 31 | Serial.begin(9600); 32 | 33 | Serial.println("SMS Messages Receiver"); 34 | 35 | // connection state 36 | boolean notConnected = true; 37 | 38 | // Start GSM shield 39 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 40 | while(notConnected) 41 | { 42 | if(gsmAccess.begin(PINNUMBER)==GSM_READY) 43 | notConnected = false; 44 | else 45 | { 46 | Serial.println("Not connected"); 47 | delay(1000); 48 | } 49 | } 50 | 51 | Serial.println("GSM initialized"); 52 | Serial.println("Waiting for messages"); 53 | } 54 | 55 | void loop() 56 | { 57 | char c; 58 | 59 | // If there are any SMSs available() 60 | if (sms.available()) 61 | { 62 | Serial.println("Message received from:"); 63 | 64 | // Get remote number 65 | sms.remoteNumber(remoteNumber, 20); 66 | Serial.println(remoteNumber); 67 | 68 | // This is just an example of message disposal 69 | // Messages starting with # should be discarded 70 | if(sms.peek()=='#') 71 | { 72 | Serial.println("Discarded SMS"); 73 | sms.flush(); 74 | } 75 | 76 | // Read message bytes and print them 77 | while(c=sms.read()) 78 | Serial.print(c); 79 | 80 | Serial.println("\nEND OF MESSAGE"); 81 | 82 | // delete message from modem memory 83 | sms.flush(); 84 | Serial.println("MESSAGE DELETED"); 85 | } 86 | 87 | delay(1000); 88 | 89 | } 90 | 91 | 92 | -------------------------------------------------------------------------------- /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 and gently hangs, 6 | 7 | Circuit: 8 | * GSM shield 9 | * Voice circuit. 10 | With no voice circuit the call will send nor receive any sound 11 | 12 | created Mar 2012 13 | by Javier Zorzano 14 | 15 | This example is in the public domain. 16 | */ 17 | 18 | // libraries 19 | #include 20 | 21 | // PIN Number 22 | #define PINNUMBER "" 23 | 24 | // initialize the library instance 25 | GSM gsmAccess; // include a 'true' parameter for debug enabled 26 | GSMVoiceCall vcs; 27 | 28 | 29 | char numtel[20]; // buffer for the incoming call 30 | 31 | void setup() 32 | { 33 | // initialize serial communications 34 | Serial.begin(9600); 35 | Serial.println("Receive Voice Call"); 36 | 37 | // connection state 38 | boolean notConnected = true; 39 | 40 | // Start GSM shield 41 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 42 | while(notConnected) 43 | { 44 | if(gsmAccess.begin(PINNUMBER)==GSM_READY) 45 | notConnected = false; 46 | else 47 | { 48 | Serial.println("Not connected"); 49 | delay(1000); 50 | } 51 | } 52 | 53 | // This makes sure the modem notifies correctly incoming events 54 | vcs.hangCall(); 55 | 56 | Serial.println("Waiting Call"); 57 | } 58 | 59 | void loop() 60 | { 61 | // Check the status of the voice call 62 | switch (vcs.getvoiceCallStatus()) 63 | { 64 | case IDLE_CALL: // Nothing is happening 65 | 66 | break; 67 | 68 | case CALLING: // This should never happen, as we are not placing a call 69 | 70 | Serial.println("CALLING"); 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. Enter line to interrupt."); 91 | while(Serial.read()!='\n') 92 | delay(100); 93 | vcs.hangCall(); 94 | Serial.println("HANG. Waiting Call."); 95 | break; 96 | } 97 | delay(1000); 98 | } 99 | 100 | 101 | -------------------------------------------------------------------------------- /examples/SendSMS/SendSMS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SMS sender 3 | 4 | This sketch, for the Arduino GSM shield,sends an SMS message 5 | that you send it through the serial monitor. To make it work, 6 | open the serial monitor, and when you see the READY message, 7 | type a message to send. Make sure the serial monitor is set 8 | to send a newline when you press return. 9 | 10 | Circuit: 11 | * GSM shield 12 | 13 | created 25 Feb 2012 14 | by Tom Igoe 15 | 16 | This example is in the public domain. 17 | */ 18 | 19 | // libraries 20 | #include 21 | 22 | #define PINNUMBER "" 23 | 24 | // initialize the library instance 25 | GSM gsmAccess; // include a 'true' parameter for debug enabled 26 | GSM_SMS sms; 27 | 28 | void setup() 29 | { 30 | // initialize serial communications 31 | Serial.begin(9600); 32 | 33 | Serial.println("SMS Messages Sender"); 34 | 35 | // connection state 36 | boolean notConnected = true; 37 | 38 | // Start GSM shield 39 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 40 | while(notConnected) 41 | { 42 | if(gsmAccess.begin(PINNUMBER)==GSM_READY) 43 | notConnected = false; 44 | else 45 | { 46 | Serial.println("Not connected"); 47 | delay(1000); 48 | } 49 | } 50 | 51 | Serial.println("GSM initialized"); 52 | } 53 | 54 | void loop() 55 | { 56 | 57 | Serial.print("Enter a mobile number: "); 58 | char remoteNumber[20]; // telephone number to send sms 59 | readSerial(remoteNumber); 60 | Serial.println(remoteNumber); 61 | 62 | // sms text 63 | Serial.print("Now, enter SMS content: "); 64 | char txtMsg[200]; 65 | readSerial(txtMsg); 66 | Serial.println("SENDING"); 67 | Serial.println(); 68 | Serial.println("Message:"); 69 | Serial.println(txtMsg); 70 | 71 | // send the message 72 | sms.beginSMS(remoteNumber); 73 | sms.print(txtMsg); 74 | sms.endSMS(); 75 | Serial.println("\nCOMPLETE!\n"); 76 | } 77 | 78 | /* 79 | Read input serial 80 | */ 81 | int readSerial(char result[]) 82 | { 83 | int i = 0; 84 | while(1) 85 | { 86 | while (Serial.available() > 0) 87 | { 88 | char inChar = Serial.read(); 89 | if (inChar == '\n') 90 | { 91 | result[i] = '\0'; 92 | Serial.flush(); 93 | return 0; 94 | } 95 | if(inChar!='\r') 96 | { 97 | result[i] = inChar; 98 | i++; 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /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 21 | 22 | This example is in the public domain. 23 | */ 24 | 25 | // libraries 26 | #include 27 | 28 | // initialize the library instance 29 | GSMBand bandManager; 30 | 31 | void setup() 32 | { 33 | // initialize serial communications 34 | Serial.begin(9600); 35 | 36 | // Beginning the band manager restarts the modem 37 | Serial.println("Restarting modem..."); 38 | bandManager.begin(); 39 | Serial.println("Modem restarted."); 40 | 41 | }; 42 | 43 | 44 | void loop() 45 | { 46 | // Get current band 47 | GSM3GSMBand band; 48 | 49 | band=bandManager.getBand(); 50 | 51 | // Get and print bands printable name 52 | Serial.print("Current band: "); 53 | Serial.println(bandManager.getBandName(band)); 54 | 55 | // If we have no clue on the band value, stop there. 56 | if(band==UNDEFINED) 57 | while(true); 58 | 59 | // Ask user for new band to configure 60 | GSM3GSMBand newBand; 61 | newBand=askUserBand(); 62 | 63 | // Send command to modem to change band 64 | if(newBand!=UNDEFINED) 65 | { 66 | String command; 67 | // Tell the user what we are about to do... 68 | Serial.print("\nConfiguring band "); 69 | Serial.println(bandManager.getBandName(newBand)); 70 | 71 | // Change the band 72 | bool operationSuccess; 73 | operationSuccess=bandManager.setBand(newBand); 74 | 75 | // Tell the user if the operation was OK 76 | if(operationSuccess) 77 | Serial.println("Success"); 78 | else 79 | Serial.println("Error while changing band"); 80 | } 81 | } 82 | 83 | // This function offers the user different options 84 | // through the Serial interface 85 | // The user selects one 86 | GSM3GSMBand askUserBand() 87 | { 88 | GSM3GSMBand result; 89 | Serial.println("Select band:"); 90 | 91 | // Print the different options 92 | Serial.print("1 "); 93 | Serial.println(bandManager.getBandName(EGSM_MODE)); 94 | Serial.print("2 "); 95 | Serial.println(bandManager.getBandName(DCS_MODE)); 96 | Serial.print("3 "); 97 | Serial.println(bandManager.getBandName(PCS_MODE)); 98 | Serial.print("4 "); 99 | Serial.println(bandManager.getBandName(EGSM_DCS_MODE)); 100 | Serial.print("5 "); 101 | Serial.println(bandManager.getBandName(GSM850_PCS_MODE)); 102 | Serial.print("6 "); 103 | Serial.println(bandManager.getBandName(GSM850_EGSM_DCS_PCS_MODE)); 104 | 105 | // Empty the incoming buffer 106 | while(Serial.available()) 107 | Serial.read(); 108 | // Wait for an answer, just look at the first character 109 | while(!Serial.available()); 110 | char c= Serial.read(); 111 | 112 | // Now, according to input, select result 113 | // If the user has not selected something between 1-6 114 | // result in UNDEFINED 115 | 116 | switch(c) 117 | { 118 | case '1': 119 | result=EGSM_MODE; 120 | break; 121 | case '2': 122 | result=DCS_MODE; 123 | break; 124 | case '3': 125 | result=PCS_MODE; 126 | break; 127 | case '4': 128 | result=EGSM_DCS_MODE; 129 | break; 130 | case '5': 131 | result=GSM850_PCS_MODE; 132 | break; 133 | case '6': 134 | result=GSM850_EGSM_DCS_PCS_MODE; 135 | break; 136 | default: 137 | result=UNDEFINED; 138 | }; 139 | 140 | return result; 141 | } 142 | -------------------------------------------------------------------------------- /examples/Tools/GsmScanNetworks/GsmScanNetworks.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example prints out the IMEI number of the SIM card, 4 | then check to see if it's connected to a carrier. If so, 5 | it prints the phone number associated with the card. 6 | Then it scans for nearby networks and prints out their signal strengths. 7 | 8 | Circuit: 9 | * GSM shield attached 10 | 11 | Created 8 Mar 2012 12 | by Tom Igoe, implemented by Javier Carazo 13 | */ 14 | 15 | // libraries 16 | #include 17 | 18 | // PIN Number 19 | #define PINNUMBER "" 20 | 21 | // initialize the library instance 22 | GSM gsmAccess; // include a 'true' parameter for debug enabled 23 | GSMScanner scannerNetworks; 24 | GSMModem modemTest; 25 | GSMBand bandManager; 26 | 27 | // Save data variables 28 | String IMEI = ""; 29 | 30 | // serial monitor result messages 31 | String errortext = "ERROR"; 32 | 33 | void setup() 34 | { 35 | // initialize serial communications 36 | Serial.begin(9600); 37 | Serial.println("GSM networks scanner"); 38 | scannerNetworks.begin(); 39 | 40 | // connection state 41 | boolean notConnected = true; 42 | 43 | // Start GSM shield 44 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 45 | while(notConnected) 46 | { 47 | if(gsmAccess.begin(PINNUMBER)==GSM_READY) 48 | notConnected = false; 49 | else 50 | { 51 | Serial.println("Not connected"); 52 | delay(1000); 53 | } 54 | } 55 | 56 | // get modem parameters 57 | // IMEI, modem unique identifier 58 | Serial.print("Modem IMEI: "); 59 | IMEI = modemTest.getIMEI(); 60 | IMEI.replace("\n",""); 61 | if(IMEI != NULL) 62 | Serial.println(IMEI); 63 | 64 | // get current band 65 | GSM3GSMBand band; 66 | band=bandManager.getBand(); 67 | Serial.print("Current band: "); 68 | Serial.println(bandManager.getBandName(band)); 69 | 70 | // currently connected carrier 71 | Serial.print("Current carrier: "); 72 | Serial.println(scannerNetworks.getCurrentCarrier()); 73 | 74 | // returns strength and ber 75 | // signal strength in 0-31 scale. 31 means power > 51dBm 76 | // BER is the Bit Error Rate. 0-7 scale. 99=not detectable 77 | Serial.print("Signal Strength: "); 78 | Serial.print(scannerNetworks.getSignalStrength()); 79 | Serial.println(" [0-31]"); 80 | } 81 | 82 | void loop() 83 | { 84 | // scan for existing networks, displays a list of networks 85 | Serial.println("Scanning available networks. May take some seconds."); 86 | 87 | Serial.println(scannerNetworks.readNetworks()); 88 | 89 | // currently connected carrier 90 | Serial.print("Current carrier: "); 91 | Serial.println(scannerNetworks.getCurrentCarrier()); 92 | 93 | // returns strength and ber 94 | // signal strength in 0-31 scale. 31 means power > 51dBm 95 | // BER is the Bit Error Rate. 0-7 scale. 99=not detectable 96 | Serial.print("Signal Strength: "); 97 | Serial.print(scannerNetworks.getSignalStrength()); 98 | Serial.println(" [0-31]"); 99 | 100 | } 101 | 102 | -------------------------------------------------------------------------------- /examples/Tools/PinManagement/PinManagement.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example helps you change your pin or remove it. 4 | 5 | Circuit: 6 | * GSM shield attached 7 | 8 | Created 12 Jun 2012 9 | by David del Peral 10 | */ 11 | 12 | // libraries 13 | #include 14 | 15 | // pin manager object 16 | GSMPin pinManager; 17 | 18 | // save input in serial by user 19 | String user_input = ""; 20 | 21 | // authenticated with PIN code 22 | boolean auth = false; 23 | 24 | // serial monitor result messages 25 | String oktext = "OK"; 26 | String errortext = "ERROR"; 27 | 28 | void setup() 29 | { 30 | // initialize serial communications 31 | Serial.begin(9600); 32 | 33 | Serial.println("Change PIN example\n"); 34 | pinManager.begin(); 35 | 36 | // check if the SIM have pin lock 37 | while(!auth){ 38 | int pin_query = pinManager.isPIN(); 39 | if(pin_query == 1) 40 | { 41 | // if SIM is locked, enter PIN code 42 | Serial.print("Enter PIN code: "); 43 | user_input = readSerial(); 44 | // check PIN code 45 | if(pinManager.checkPIN(user_input) == 0) 46 | { 47 | auth = true; 48 | pinManager.setPinUsed(true); 49 | Serial.println(oktext); 50 | } 51 | else 52 | { 53 | // if PIN code was incorrected 54 | Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); 55 | } 56 | } 57 | else if(pin_query == -1) 58 | { 59 | // PIN code is locked, user must enter PUK code 60 | Serial.println("PIN locked. Enter PUK code: "); 61 | String puk = readSerial(); 62 | Serial.print("Now, enter a new PIN code: "); 63 | user_input = readSerial(); 64 | // check PUK code 65 | if(pinManager.checkPUK(puk, user_input) == 0) 66 | { 67 | auth = true; 68 | pinManager.setPinUsed(true); 69 | Serial.println(oktext); 70 | } 71 | else 72 | { 73 | // if PUK o the new PIN are incorrect 74 | Serial.println("Incorrect PUK or invalid new PIN. Try again!."); 75 | } 76 | } 77 | else if(pin_query == -2) 78 | { 79 | // the worst case, PIN and PUK are locked 80 | Serial.println("PIN & PUK locked. Use PIN2/PUK2 in a mobile phone."); 81 | while(true); 82 | } 83 | else 84 | { 85 | // SIM does not requires authetication 86 | Serial.println("No pin necessary."); 87 | auth = true; 88 | } 89 | } 90 | 91 | // start GSM shield 92 | Serial.print("Checking register in GSM network..."); 93 | if(pinManager.checkReg() == 0) 94 | Serial.println(oktext); 95 | // if you are connect by roaming 96 | else if(pinManager.checkReg() == 1) 97 | Serial.println("ROAMING " + oktext); 98 | else 99 | { 100 | // error connection 101 | Serial.println(errortext); 102 | while(true); 103 | } 104 | } 105 | 106 | void loop() 107 | { 108 | // Function loop implements pin management user menu 109 | // Only if you SIM use pin lock, you can change PIN code 110 | // user_op variables save user option 111 | 112 | Serial.println("Choose an option:\n1 - On/Off PIN."); 113 | if(pinManager.getPinUsed()) 114 | Serial.println("2 - Change PIN."); 115 | String user_op = readSerial(); 116 | if(user_op == "1") 117 | { 118 | Serial.println("Enter your PIN code:"); 119 | user_input = readSerial(); 120 | // activate/deactivate PIN lock 121 | pinManager.switchPIN(user_input); 122 | } 123 | else if(user_op == "2" & pinManager.getPinUsed()) 124 | { 125 | Serial.println("Enter your actual PIN code:"); 126 | String oldpin = readSerial(); 127 | Serial.println("Now, enter your new PIN code:"); 128 | String newpin = readSerial(); 129 | // change PIN 130 | pinManager.changePIN(oldpin, newpin); 131 | } 132 | else 133 | { 134 | Serial.println("Incorrect option. Try again!."); 135 | } 136 | delay(1000); 137 | } 138 | 139 | /* 140 | Read input serial 141 | */ 142 | String readSerial() 143 | { 144 | String text = ""; 145 | while(1) 146 | { 147 | while (Serial.available() > 0) 148 | { 149 | char inChar = Serial.read(); 150 | if (inChar == '\n') 151 | { 152 | return text; 153 | } 154 | if(inChar!='\r') 155 | text += inChar; 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /examples/Tools/TelefonicaShieldSW/TelefonicaShieldSW.ino: -------------------------------------------------------------------------------- 1 | // libraries 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // KEY (copy & paste from shield data page at BlueVia Arduino Shield website: arduinoshield.tid.es) 9 | #define KEY "eb70f352b1" 10 | 11 | // APN data 12 | #define GPRS_APN "bluevia.movistar.es" // replace your GPRS APN 13 | #define GPRS_LOGIN "" // replace with your GPRS login 14 | #define GPRS_PASSWORD "" // replace with your GPRS password 15 | 16 | // initialize the library instance 17 | GSM3MobileClientService client(true); 18 | GSM3ShieldV1ClientProvider s1client; 19 | GSM3ShieldV1DataNetworkProvider gprs; 20 | GSM3ShieldV1AccessProvider gsmAccess; // include a 'true' parameter for debug enabled 21 | GSM3ShieldV1DirectModemProvider modemProvider; 22 | 23 | // Telefonica's Shield backend server data 24 | const char hostname[] = "arduinoshield.tid.es"; 25 | const char path[] = "/Arduino/receive.php"; 26 | const int kNetworkTimeout = 30*1000; 27 | const int kNetworkDelay = 1000; 28 | 29 | // transmission variables 30 | uint8_t charReceived = 0; 31 | unsigned long m; 32 | unsigned long delayLong; 33 | 34 | // buffers and I/O variables 35 | #define numAuxCharacteres 39 36 | char ICCID[35]; 37 | char bufAux[2] = ""; 38 | int countAux; 39 | uint8_t LedR, LedG, LedB; //1 input, 0 output 40 | uint8_t DigitalLSB = 112; 41 | uint8_t DigitalMSB = 4/*63*/; 42 | int countInputs = 4; 43 | 44 | // serial monitor variables 45 | uint8_t value; 46 | char errortext[] = "ERROR"; 47 | String pwmtext = "\tPWM\t"; 48 | String intext = "\tIN\t"; 49 | String outext = "\tOUT\t"; 50 | String onetext = "1"; 51 | String zerotext = "0"; 52 | String D4 = "D4"; 53 | String D5 = "D5"; 54 | String D6 = "D6"; 55 | String D8 = "D8"; 56 | String D9 = "D9"; 57 | String D10 = "D10"; 58 | String D11 = "D11"; 59 | String D12 = "D12"; 60 | String D13 = "D13"; 61 | 62 | void setup() 63 | { 64 | // initialize serial communications 65 | Serial.begin(9600); 66 | 67 | // connection state 68 | boolean notConnected = true; 69 | 70 | // Start GSM shield 71 | // If your SIM has PIN, pass it as a parameter of begin() in quotes 72 | while(notConnected) 73 | { 74 | if((gsmAccess.begin()==GSM_READY) & 75 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)) 76 | notConnected = false; 77 | else 78 | { 79 | Serial.println(errortext); 80 | delay(1000); 81 | } 82 | } 83 | 84 | Serial.println("Sending..."); 85 | } 86 | 87 | void loop() 88 | { 89 | // get M2M SIM iccid 90 | getICCID(); 91 | 92 | uint8_t numberBytesICCID = strlen(ICCID); 93 | uint8_t numberKeyField = strlen(KEY) + 6; 94 | uint8_t numberBytes = numberBytesICCID + numberKeyField + numAuxCharacteres + countInputs; 95 | 96 | // error variable 97 | int err = 0; 98 | 99 | // connect to backend service 100 | if(client.connect(hostname, 80)) 101 | { 102 | // make a POST petition with data 103 | client.print("POST "); 104 | client.print(path); 105 | client.println(" HTTP/1.0"); 106 | 107 | // POST request required headers 108 | client.println("Host: arduinoshield.tid.es"); 109 | client.println("Content-Type: application/x-www-form-urlencoded"); 110 | client.print("Content-Length: "); 111 | client.println(numberBytes); 112 | client.println(); 113 | 114 | // send ICCID 115 | client.print(ICCID); 116 | client.print(",#KEY,"); 117 | client.print(KEY); 118 | 119 | // send analog inputs 120 | client.print(",#A,"); 121 | char bufAux[5]; 122 | itoa (analogRead(A0), bufAux, 10); 123 | client.print(bufAux); 124 | client.print(","); 125 | itoa (analogRead(A1), bufAux, 10); 126 | client.print(bufAux); 127 | client.print(","); 128 | itoa (analogRead(A2), bufAux, 10); 129 | client.print(bufAux); 130 | client.print(","); 131 | itoa (analogRead(A3), bufAux, 10); 132 | client.print(bufAux); 133 | client.print(","); 134 | itoa (analogRead(A4), bufAux, 10); 135 | client.print(bufAux); 136 | client.print(","); 137 | itoa (analogRead(A5), bufAux, 10); 138 | client.print(bufAux); 139 | 140 | /*Serial.println(); 141 | Serial.println(DigitalLSB); 142 | Serial.println(DigitalMSB);*/ 143 | 144 | // send digital inputs 145 | client.print(",#D"); 146 | // LSB 147 | for (int pin=4;pin<7;pin++) { 148 | if (DigitalLSB&(1< 0)) contAux++; 429 | //Serial.print(c); 430 | } 431 | }else{ 432 | delay(kNetworkDelay); 433 | } 434 | } 435 | }else{ 436 | Serial.print(errortext); 437 | } 438 | 439 | client.stop(); 440 | 441 | Serial.print("Update: "); 442 | Serial.println(delayLong); 443 | delay(delayLong*1000); 444 | } 445 | 446 | void getICCID() 447 | { 448 | strcpy(ICCID,"cadena=#ICCID,"); 449 | String id_code = modemProvider.writeModemCommand("AT+QCCID", 2000); 450 | id_code.trim(); 451 | id_code.replace("\n",""); 452 | id_code.replace("\r",""); 453 | char id_code_char[id_code.length()-2]; 454 | id_code.toCharArray(id_code_char, id_code.length()-2); 455 | strcat(ICCID,(const char *)id_code_char); 456 | //Serial.println(ICCID); 457 | } 458 | -------------------------------------------------------------------------------- /examples/Tools/TestGPRS/TestGPRS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This test asks your APN data and try to connect 4 | to arduino.cc site by GPRS. 5 | 6 | Circuit: 7 | * GSM shield attached 8 | 9 | Created 18 Jun 2012 10 | by David del Peral 11 | */ 12 | 13 | // libraries 14 | #include 15 | 16 | // PIN Number 17 | #define PINNUMBER "" 18 | 19 | // initialize the library instance 20 | GSM gsmAccess; // GSM access: include a 'true' parameter for debug enabled 21 | GPRS gprsAccess; // GPRS access 22 | GSMClient client; // Client service for TCP connection 23 | 24 | // messages for serial monitor response 25 | String oktext = "OK"; 26 | String errortext = "ERROR"; 27 | 28 | // URL and path (for example: arduino.cc) 29 | char url[] = "arduino.cc"; 30 | char urlproxy[] = "http://arduino.cc"; 31 | char path[] = "/"; 32 | 33 | // variable for save response obtained 34 | String response = ""; 35 | 36 | // use a proxy 37 | boolean use_proxy = false; 38 | 39 | void setup() 40 | { 41 | // initialize serial communications 42 | Serial.begin(9600); 43 | } 44 | 45 | void loop() 46 | { 47 | use_proxy = false; 48 | 49 | // start GSM shield 50 | // if your SIM has PIN, pass it as a parameter of begin() in quotes 51 | Serial.print("Connecting GSM network..."); 52 | if(gsmAccess.begin(PINNUMBER)!=GSM_READY) 53 | { 54 | Serial.println(errortext); 55 | while(true); 56 | } 57 | Serial.println(oktext); 58 | 59 | // read APN introduced by user 60 | char apn[50]; 61 | Serial.print("Enter your APN: "); 62 | readSerial(apn); 63 | Serial.println(apn); 64 | 65 | // Read APN login introduced by user 66 | char login[50]; 67 | Serial.print("Now, enter your login: "); 68 | readSerial(login); 69 | Serial.println(login); 70 | 71 | // read APN password introduced by user 72 | char password[20]; 73 | Serial.print("Finally, enter your password: "); 74 | readSerial(password); 75 | 76 | // hide APN password introduced with asterisks for show in serial monitor 77 | int i; 78 | String asterisks = ""; 79 | for(i=0; i 0) 187 | { 188 | char inChar = Serial.read(); 189 | if (inChar == '\n') 190 | { 191 | result[i] = '\0'; 192 | return 0; 193 | } 194 | if(inChar!='\r') 195 | { 196 | result[i] = inChar; 197 | i++; 198 | } 199 | } 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /examples/Tools/TestModem/TestModem.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example test if your modem is working correctly. 4 | 5 | Circuit: 6 | * GSM shield attached ( 7 | 8 | Created 12 Jun 2012 9 | by David del Peral 10 | */ 11 | 12 | // libraries 13 | #include 14 | 15 | // modem verification object 16 | GSMModem modemTest; 17 | 18 | // IMEI variable 19 | String IMEI = ""; 20 | 21 | // serial monitor result messages 22 | String oktext = "OK"; 23 | String errortext = "ERROR"; 24 | 25 | void setup() 26 | { 27 | // initialize serial communications 28 | Serial.begin(9600); 29 | 30 | // start modem test (reset and check response) 31 | Serial.print("Starting modem test..."); 32 | if(modemTest.begin()) 33 | Serial.println(oktext); 34 | else 35 | Serial.println("ERROR, no modem answer."); 36 | } 37 | 38 | void loop() 39 | { 40 | // get modem IMEI 41 | Serial.print("Checking IMEI..."); 42 | IMEI = modemTest.getIMEI(); 43 | 44 | // check IMEI responsed 45 | if(IMEI != NULL) 46 | { 47 | Serial.println(oktext); 48 | // show IMEI in serial monitor 49 | Serial.println("Modem's IMEI: " + IMEI); 50 | // reset modem for check booting 51 | Serial.print("Reseting modem..."); 52 | modemTest.begin(); 53 | // get and check IMEI one more time 54 | if(modemTest.getIMEI() != NULL) 55 | { 56 | Serial.println(oktext); 57 | Serial.println("TEST COMPLETE!"); 58 | } 59 | else 60 | { 61 | Serial.println(errortext); 62 | } 63 | } 64 | else 65 | { 66 | Serial.println(errortext); 67 | } 68 | while(true); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /examples/proto-examples/GsmChatServer/GsmChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | 8 | Circuit: 9 | * GSM shield attached 10 | 11 | created 18 Dec 2009 12 | by David A. Mellis 13 | modified 8 Mar 2012 14 | by Tom Igoe 15 | 16 | */ 17 | 18 | 19 | 20 | #include 21 | 22 | GprsServer server(23); 23 | 24 | boolean gotAMessage = false; // whether or not you got a message from the client yet 25 | 26 | void setup() { 27 | // initialize serial: 28 | Serial.begin(9600); 29 | 30 | status = gsm.begin(); 31 | if ( status != GSM_CONNECTED) { 32 | Serial.println("Couldn't get a GSM connection"); 33 | while(true); 34 | } 35 | else { 36 | gsm.attachGPRS(); 37 | Serial.println("Connected to GPRS network"); 38 | server.begin(); 39 | printGsmStatus(); 40 | } 41 | } 42 | void loop() { 43 | // wait for a new client: 44 | GprsClient client = server.available(); 45 | 46 | // when the client sends the first byte, say hello: 47 | if (client) { 48 | if (!gotAMessage) { 49 | Serial.println("We have a new client"); 50 | client.println("Hello, client!"); 51 | gotAMessage = true; 52 | } 53 | 54 | // read the bytes incoming from the client: 55 | char thisChar = client.read(); 56 | // echo the bytes back to the client: 57 | server.write(thisChar); 58 | // echo the bytes to the server as well: 59 | Serial.print(thisChar); 60 | } 61 | } 62 | 63 | 64 | void printGsmStatus() { 65 | Serial.print("SIM card IMEI: "); 66 | Serial.println(gsm.imei()); 67 | Serial.print("Band: "); 68 | Serial.println(gsm.getBand()); 69 | 70 | Serial.print("Carrier: "); 71 | Serial.println(gsm.carrier()); 72 | Serial.print("Signal Strength: "); 73 | Serial.print(gsm.getSignalStrength()); 74 | Serial.println("dBm"); 75 | Serial.print("Phone number: "); 76 | Serial.println(gsm.phoneNumber()); 77 | 78 | // print your GSM shield's IP address: 79 | IPAddress ip = gsm.localIP(); 80 | Serial.print("IP Address: "); 81 | Serial.println(ip); 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/proto-examples/GsmPachubeClient/GsmPachubeClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | GSM Pachube sensor client 3 | 4 | This sketch connects an analog sensor to Pachube (http://www.pachube.com) 5 | using an Arduino GSM shield. 6 | 7 | 8 | This example has been updated to use version 2.0 of the Pachube.com API. 9 | To make it work, create a feed with a datastream, and give it the ID 10 | sensor1. Or change the code below to match your feed. 11 | 12 | Circuit: 13 | * Analog sensor attached to analog in 0 14 | * GSM shield attached to pins 10, 11, 12, 13 15 | 16 | created 4 March 2012 17 | by Tom Igoe 18 | 19 | This code is in the public domain. 20 | 21 | */ 22 | 23 | 24 | #include 25 | 26 | 27 | #define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here 28 | #define FEEDID 00000 // replace your feed ID 29 | #define USERAGENT "My Project" // user agent is the project name 30 | 31 | char ssid[] = "yourNetwork"; // your network SSID (name) 32 | char pass[] = "secretPassword"; // your network password 33 | int status = WL_IDLE_STATUS; 34 | 35 | // initialize the library instance: 36 | GprsClient client; 37 | 38 | long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 39 | boolean lastConnected = false; // state of the connection last time through the main loop 40 | const int postingInterval = 10000; //delay between updates to Pachube.com 41 | 42 | void setup() { 43 | Serial.begin(9600); 44 | Serial.println("Attempting to connect to GSM network..."); 45 | Serial.print("SSID: "); 46 | Serial.println(ssid); 47 | 48 | status = gsm.begin(); 49 | if ( status != GSM_CONNECTED) { 50 | Serial.println("Couldn't get a GSM connection"); 51 | while(true); 52 | } 53 | else { 54 | gsm.attachGPRS(); 55 | Serial.println("Connected to GPRS network"); 56 | printGsmStatus(); 57 | } 58 | } 59 | 60 | 61 | void loop() { 62 | // read the analog sensor: 63 | int sensorReading = analogRead(A0); 64 | 65 | // if there's incoming data from the net connection. 66 | // send it out the serial port. This is for debugging 67 | // purposes only: 68 | if (client.available()) { 69 | char c = client.read(); 70 | Serial.print(c); 71 | } 72 | 73 | // if there's no net connection, but there was one last time 74 | // through the loop, then stop the client: 75 | if (!client.connected() && lastConnected) { 76 | Serial.println(); 77 | Serial.println("disconnecting."); 78 | client.stop(); 79 | } 80 | 81 | // if you're not connected, and ten seconds have passed since 82 | // your last connection, then connect again and send data: 83 | if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { 84 | sendData(sensorReading); 85 | } 86 | // store the state of the connection for next time through 87 | // the loop: 88 | lastConnected = client.connected(); 89 | } 90 | 91 | // this method makes a HTTP connection to the server: 92 | void sendData(int thisData) { 93 | // if there's a successful connection: 94 | if (client.connect("www.pachube.com", 80)) { 95 | Serial.println("connecting..."); 96 | // send the HTTP PUT request: 97 | client.print("PUT /v2/feeds/"); 98 | client.print(FEEDID); 99 | client.println(".csv HTTP/1.1"); 100 | client.print("Host: api.pachube.com\n"); 101 | client.print("X-PachubeApiKey: "); 102 | client.println(APIKEY); 103 | client.print("User-Agent: "); 104 | client.println(USERAGENT); 105 | client.print("Content-Length: "); 106 | 107 | // calculate the length of the sensor reading in bytes: 108 | // 8 bytes for "sensor1," + number of digits of the data: 109 | int thisLength = 8 + getLength(thisData); 110 | client.println(thisLength); 111 | 112 | // last pieces of the HTTP PUT request: 113 | client.print("Content-Type: text/csv\n"); 114 | client.println("Connection: close\n"); 115 | 116 | // here's the actual content of the PUT request: 117 | client.print("sensor1,"); 118 | client.println(thisData); 119 | 120 | // note the time that the connection was made: 121 | lastConnectionTime = millis(); 122 | } 123 | else { 124 | // if you couldn't make a connection: 125 | Serial.println("connection failed"); 126 | Serial.println(); 127 | Serial.println("disconnecting."); 128 | client.stop(); 129 | } 130 | lastConnected = client.connected(); 131 | } 132 | 133 | 134 | // This method calculates the number of digits in the 135 | // sensor reading. Since each digit of the ASCII decimal 136 | // representation is a byte, the number of digits equals 137 | // the number of bytes: 138 | 139 | int getLength(int someValue) { 140 | // there's at least one byte: 141 | int digits = 1; 142 | // continually divide the value by ten, 143 | // adding one to the digit count for each 144 | // time you divide, until you're at 0: 145 | int dividend = someValue /10; 146 | while (dividend > 0) { 147 | dividend = dividend /10; 148 | digits++; 149 | } 150 | // return the number of digits: 151 | return digits; 152 | } 153 | 154 | 155 | void printGsmStatus() { 156 | Serial.print("SIM card IMEI: "); 157 | Serial.println(gsm.imei()); 158 | Serial.print("Band: "); 159 | Serial.println(gsm.getBand()); 160 | 161 | Serial.print("Carrier: "); 162 | Serial.println(gsm.carrier()); 163 | Serial.print("Signal Strength: "); 164 | Serial.print(gsm.getSignalStrength()); 165 | Serial.println("dBm"); 166 | Serial.print("Phone number: "); 167 | Serial.println(gsm.phoneNumber()); 168 | 169 | // print your GSM shield's IP address: 170 | IPAddress ip = gsm.localIP(); 171 | Serial.print("IP Address: "); 172 | Serial.println(ip); 173 | } 174 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /examples/proto-examples/GsmScanNetworks/GsmScanNetworks.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example prints out the IMEI number of the SIM card, 4 | then check to see if it's connected to a carrier. If so, 5 | it prints the phone number associated with the card. 6 | Then it scans for nearby networks and prints out their signal strengths. 7 | 8 | 9 | Created 8 Mar 2012 10 | by Tom Igoe 11 | */ 12 | 13 | #include 14 | 15 | void setup() { 16 | // initialize serial: 17 | Serial.begin(9600); 18 | Serial.println("Initializing GSM..."); 19 | // print the IMEI of the SIM card whether connected or not: 20 | Serial.print("SIM card IMEI: "); 21 | Serial.println(gsm.imei()); 22 | Serial.print("Subscriber IMSI: "); 23 | Serial.println(gsm.imsi()); 24 | Serial.print("Band: "); 25 | Serial.println(gsm.getBand()); 26 | 27 | // begin should try to connect to carrier: 28 | if (gsm.begin() == CONNECTED) { 29 | Serial.print("Carrier: "); 30 | Serial.println(gsm.carrier()); 31 | Serial.print("Signal Strength: "); 32 | Serial.print(gsm.getSignalStrength(gsm.carrier())); 33 | Serial.print("Phone number: "); 34 | Serial.println(gsm.phoneNumber()); 35 | } 36 | 37 | // scan for existing networks: 38 | Serial.println("Scanning available networks..."); 39 | listNetworks(); 40 | } 41 | 42 | void loop() { 43 | delay(10000); 44 | // scan for existing networks: 45 | Serial.println("Scanning available networks..."); 46 | listNetworks(); 47 | } 48 | 49 | void listNetworks() { 50 | // scan for nearby networks: 51 | Serial.println("** Scan Networks **"); 52 | byte numNetworks = gsm.scanNetworks(); 53 | 54 | // print the list of networks seen: 55 | Serial.print("Network List:"); 56 | Serial.println(numNetworks); 57 | 58 | // print the network number and name for each network found: 59 | for (int thisNet = 0; thisNetthis is a tweet
6 | 7 | This example uses the String library, which is part of the Arduino core from 8 | version 0019. 9 | 10 | Circuit: 11 | * GSM shield attached to pins 10, 11, 12, 13 12 | 13 | created 8 Mar 2012 14 | by Tom Igoe 15 | 16 | This code is in the public domain. 17 | 18 | */ 19 | 20 | #include 21 | 22 | // initialize the library instance: 23 | GprsClient client; 24 | 25 | const unsigned long requestInterval = 30*1000; // delay between requests; 30 seconds 26 | 27 | IPAddress server(199,59,149,200); // api.twitter.com 28 | 29 | boolean requested; // whether you've made a request since connecting 30 | unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds 31 | 32 | String currentLine = ""; // string to hold the text from server 33 | String tweet = ""; // string to hold the tweet 34 | boolean readingTweet = false; // if you're currently reading the tweet 35 | int status = GSM_IDLE_STATUS; 36 | 37 | void setup() { 38 | // reserve space for the strings: 39 | currentLine.reserve(256); 40 | tweet.reserve(150); 41 | // initialize serial: 42 | Serial.begin(9600); 43 | 44 | status = gsm.begin(); 45 | if ( status != GSM_CONNECTED) { 46 | Serial.println("Couldn't get a GSM connection"); 47 | while(true); 48 | } 49 | else { 50 | gsm.attachGPRS(); 51 | Serial.println("Connected to GPRS network"); 52 | printGsmStatus(); 53 | connectToServer(); 54 | } 55 | } 56 | 57 | 58 | 59 | void loop() 60 | { 61 | if (client.connected()) { 62 | if (client.available()) { 63 | // read incoming bytes: 64 | char inChar = client.read(); 65 | 66 | // add incoming byte to end of line: 67 | currentLine += inChar; 68 | 69 | // if you get a newline, clear the line: 70 | if (inChar == '\n') { 71 | currentLine = ""; 72 | } 73 | // if the current line ends with , it will 74 | // be followed by the tweet: 75 | if ( currentLine.endsWith("")) { 76 | // tweet is beginning. Clear the tweet string: 77 | readingTweet = true; 78 | tweet = ""; 79 | } 80 | // if you're currently reading the bytes of a tweet, 81 | // add them to the tweet String: 82 | if (readingTweet) { 83 | if (inChar != '<') { 84 | tweet += inChar; 85 | } 86 | else { 87 | // if you got a "<" character, 88 | // you've reached the end of the tweet: 89 | readingTweet = false; 90 | Serial.println(tweet); 91 | // close the connection to the server: 92 | client.stop(); 93 | } 94 | } 95 | } 96 | } 97 | else if (millis() - lastAttemptTime > requestInterval) { 98 | // if you're not connected, and two minutes have passed since 99 | // your last connection, then attempt to connect again: 100 | connectToServer(); 101 | } 102 | } 103 | 104 | void connectToServer() { 105 | // attempt to connect, and wait a millisecond: 106 | Serial.println("connecting to server..."); 107 | if (client.connect(server, 80)) { 108 | Serial.println("making HTTP request..."); 109 | // make HTTP GET request to twitter: 110 | client.println("GET /1/statuses/user_timeline.xml?screen_name=arduinoteam HTTP/1.1"); 111 | client.println("HOST:api.twitter.com"); 112 | client.println(); 113 | } 114 | // note the time of this connect attempt: 115 | lastAttemptTime = millis(); 116 | } 117 | 118 | 119 | void printGsmStatus() { 120 | Serial.print("SIM card IMEI: "); 121 | Serial.println(gsm.imei()); 122 | Serial.print("Band: "); 123 | Serial.println(gsm.getBand()); 124 | 125 | Serial.print("Carrier: "); 126 | Serial.println(gsm.carrier()); 127 | Serial.print("Signal Strength: "); 128 | Serial.print(gsm.getSignalStrength()); 129 | Serial.println("dBm"); 130 | Serial.print("Phone number: "); 131 | Serial.println(gsm.phoneNumber()); 132 | 133 | // print your GSM shield's IP address: 134 | IPAddress ip = gsm.localIP(); 135 | Serial.print("IP Address: "); 136 | Serial.println(ip); 137 | } 138 | 139 | -------------------------------------------------------------------------------- /examples/proto-examples/GsmWebClient/GsmWebClient.ino: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Web client 4 | 5 | This sketch connects to a website (http://www.google.com) 6 | using a GSM shield. 7 | 8 | Circuit: 9 | * GSM shield attached 10 | 11 | created 8 Mar 2012 12 | by Tom Igoe 13 | */ 14 | 15 | 16 | 17 | #include 18 | 19 | int status = GSM_IDLE_STATUS; 20 | IPAddress server(74,125,115,105); // Google 21 | 22 | // Initialize the Ethernet client library 23 | // with the IP address and port of the server 24 | // that you want to connect to (port 80 is default for HTTP): 25 | GprsClient client; 26 | 27 | void setup() { 28 | Serial.begin(9600); 29 | 30 | status = gsm.begin(); 31 | if ( status != GSM_CONNECTED) { 32 | Serial.println("Couldn't get a GSM connection"); 33 | while(true); 34 | } 35 | else { 36 | gsm.attachGPRS(); 37 | Serial.println("Connected to GPRS network"); 38 | printGsmStatus(); 39 | Serial.println("\nStarting connection to server..."); 40 | // if you get a connection, report back via serial: 41 | if (client.connect(server, 80)) { 42 | Serial.println("connected to server"); 43 | // Make a HTTP request: 44 | client.println("GET /search?q=arduino HTTP/1.0"); 45 | client.println(); 46 | } 47 | } 48 | } 49 | 50 | void loop() { 51 | // if there are incoming bytes available 52 | // from the server, read them and print them: 53 | if (client.available()) { 54 | char c = client.read(); 55 | Serial.print(c); 56 | } 57 | 58 | // if the server's disconnected, stop the client: 59 | if (!client.connected()) { 60 | Serial.println(); 61 | Serial.println("disconnecting from server."); 62 | client.stop(); 63 | 64 | // do nothing forevermore: 65 | while(true); 66 | } 67 | } 68 | 69 | 70 | void printGsmStatus() { 71 | Serial.print("SIM card IMEI: "); 72 | Serial.println(gsm.imei()); 73 | Serial.print("Band: "); 74 | Serial.println(gsm.getBand()); 75 | 76 | Serial.print("Carrier: "); 77 | Serial.println(gsm.carrier()); 78 | Serial.print("Signal Strength: "); 79 | Serial.print(gsm.getSignalStrength()); 80 | Serial.println("dBm"); 81 | Serial.print("Phone number: "); 82 | Serial.println(gsm.phoneNumber()); 83 | 84 | // print your GSM shield's IP address: 85 | IPAddress ip = gsm.localIP(); 86 | Serial.print("IP Address: "); 87 | Serial.println(ip); 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /examples/proto-examples/GsmWebServer/GsmWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 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 | 16 | 17 | #include 18 | 19 | int status = GSM_IDLE_STATUS; 20 | 21 | GprsServer server(80); 22 | 23 | void setup() { 24 | // initialize serial: 25 | Serial.begin(9600); 26 | 27 | status = gsm.begin(); 28 | if ( status != GSM_CONNECTED) { 29 | Serial.println("Couldn't get a GSM connection"); 30 | while(true); 31 | } 32 | else { 33 | gsm.attachGPRS(); 34 | Serial.println("Connected to GPRS network"); 35 | server.begin(); 36 | printGsmStatus(); 37 | } 38 | } 39 | 40 | void loop() { 41 | // listen for incoming clients 42 | GprsClient client = server.available(); 43 | if (client) { 44 | // an http request ends with a blank line 45 | boolean currentLineIsBlank = true; 46 | while (client.connected()) { 47 | if (client.available()) { 48 | char c = client.read(); 49 | // if you've gotten to the end of the line (received a newline 50 | // character) and the line is blank, the http request has ended, 51 | // so you can send a reply 52 | if (c == '\n' && currentLineIsBlank) { 53 | // send a standard http response header 54 | client.println("HTTP/1.1 200 OK"); 55 | client.println("Content-Type: text/html"); 56 | client.println(); 57 | client.println(""); 58 | // output the value of each analog input pin 59 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 60 | client.print("analog input "); 61 | client.print(analogChannel); 62 | client.print(" is "); 63 | client.print(analogRead(analogChannel)); 64 | client.println("
"); 65 | } 66 | client.println(""); 67 | break; 68 | } 69 | if (c == '\n') { 70 | // you're starting a new line 71 | currentLineIsBlank = true; 72 | } 73 | else if (c != '\r') { 74 | // you've gotten a character on the current line 75 | currentLineIsBlank = false; 76 | } 77 | } 78 | } 79 | // give the web browser time to receive the data 80 | delay(1); 81 | // close the connection: 82 | client.stop(); 83 | } 84 | } 85 | 86 | 87 | void printGsmStatus() { 88 | Serial.print("SIM card IMEI: "); 89 | Serial.println(gsm.imei()); 90 | Serial.print("Band: "); 91 | Serial.println(gsm.getBand()); 92 | 93 | Serial.print("Carrier: "); 94 | Serial.println(gsm.carrier()); 95 | Serial.print("Signal Strength: "); 96 | Serial.print(gsm.getSignalStrength()); 97 | Serial.println("dBm"); 98 | Serial.print("Phone number: "); 99 | Serial.println(gsm.phoneNumber()); 100 | 101 | // print your GSM shield's IP address: 102 | IPAddress ip = gsm.localIP(); 103 | Serial.print("IP Address: "); 104 | Serial.println(ip); 105 | } 106 | 107 | 108 | --------------------------------------------------------------------------------