Jan Kamidra
/
Mbed_A9G_test
Test
Diff: main.cpp
- Revision:
- 6:b38819d5db73
- Parent:
- 5:70b84276766a
- Child:
- 7:90bb5b736fe4
--- a/main.cpp Fri Mar 25 21:06:34 2022 +0000 +++ b/main.cpp Tue Mar 29 18:34:56 2022 +0000 @@ -6,7 +6,7 @@ BufferedSerial uart(PD_5,PD_6, 115200); // UART TX, RX ATCmdParser module(&uart,"\r\n"); -bool modulInit(int simPin = 0); +bool modulInit(int simPin); bool sendSMS(string phoneNum, string text); // setup @@ -15,8 +15,8 @@ module.debug_on(true); module.set_timeout(1000); - if(modulInit()){ - if(sendSMS("+123123456789", "Testerino")){ + if(modulInit(1234)){ // replace 1234 with your Pin code of your SIM card or replace it with 0, when your SIM have no Pin code. + if(sendSMS("+123123456789", "Testerino")){ // replace +123123456789 with destination Phone number printf("SMS sended\n"); } } @@ -55,8 +55,7 @@ } // Wait for network registration - string network_status[] = { "not registered", - "not searching", + string network_status[] = { "not registered, not searching", "registered, home network", "not registered, but is searching", "registration denied", @@ -66,9 +65,12 @@ debug_if(DEBUG, "Connecting to network...\n"); module.set_timeout(10000); for(int i=0;i<5;i++){ - module.recv("+CREG: %d",&state); - if(state == 1)break; - debug_if(DEBUG, "State: %s...\n",network_status[state].c_str()); + if(module.recv("+CREG: %d",&state)){ + if(state == 1)break; + debug_if(DEBUG, "State: %s...\n",network_status[state].c_str()); + } else { + debug_if(DEBUG, "State: timeout\n"); + } thread_sleep_for(500); } if(state == 1){ @@ -93,7 +95,7 @@ debug_if(DEBUG, "Set mode failed!\n"); } - module.set_timeout(5000); + module.set_timeout(10000); module.send("AT+CMGS=\"%s\"", phoneNum.c_str()); if(module.recv(">")){ debug_if(DEBUG, "Sms mode was set to %d\n", mode);