C027_Support library test

Dependencies:   C027_Support

Dependents:   C027_SupportTest_xively_location software_test_v1

Fork of Seeed_GPRS_Library_HelloWorld by wei zou

When running this example make sure you have:

  • edited the SIM PIN, APN, USER and PASSWORD for you network operator
  • have inserted a SIM card with enough credits
  • the antennas connected
  • have good reception (especially for GPS)
  • installed the mbed CDC drivers if you run windows
  • connected a terminal program, such as teraterm

The example will connect the modem to the network and attach it. I will place a post request to download a file from mbed website. It will do a USSD request and finally wait for incoming SMS. It will try to answer your SMS (try asking "where are you").

You should see a similar output in your preferred console program:

C027 Support Example
Device Init
Device Status:
  Device:       SARA-G350
  Power Save:   Active
  SIM:          Ready
  CCID:         xxxxxxxxxxxxxxxxxxxxxxxxxxx
  IMEI:         xxxxxxxxxxxxxxxxxxx
  IMSI:         xxxxxxxxxxxxxxxxxxx
  Manufacturer: u-blox
  Model:        SARA-G350
  Version:      08.49
Network Check
Network Status:
  Registration:       Home
  Signal Strength:    -87 dBm
  Operator:           Swisscom
  Phone Number:       +41xxxxxxxxxxx
Network Join
  IP Address: xx.xx.xx.xx
Socket Create
Socket Connect
Make a Http Post Request
Socket Send
Socket Recving
Socket 0: 337 bytes pending
Socket 0: 145 bytes pending
Socket 0: closed by remote host
Socket Recv "HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Thu, 10 Apr 2014 13:09:02 GMT
Content-Type: text/plain
Connection: close
Last-Modified: Fri, 27 Jul 2012 13:30:34 GMT
Cache-Control: max-age=36000
Expires: Thu, 10 Apr 2014 20:43:53 GMT
Vary: Accept-Encoding
X-Mystery-Header: 260358892
X-be: web0_prod_sjc
Age: 8709

Hello world!
"
Socket Close
Socket Free
Network Disconnect
Send Ussd Command *#134#
Got Ussd Answer: "UNKNOWN APPLICATION"
Checking SMS and GPS
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
...
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
Network Status:
  Registration:       Home
  Signal Strength:    -89 dBm
  Operator:           Swisscom
  Phone Number:       +41xxxxxxxxx
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
...
Committer:
lawliet
Date:
Tue Feb 25 06:04:29 2014 +0000
Revision:
0:4e3cb26f6019
Child:
2:b77151f111a9
Initial Version Of Seeed GPRS Library HelloWorld

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lawliet 0:4e3cb26f6019 1 /*
lawliet 0:4e3cb26f6019 2 main.cpp
lawliet 0:4e3cb26f6019 3 2013 Copyright (c) Seeed Technology Inc. All right reserved.
lawliet 0:4e3cb26f6019 4
lawliet 0:4e3cb26f6019 5 Author:lawliet zou(lawliet.zou@gmail.com)
lawliet 0:4e3cb26f6019 6 2014-02-18
lawliet 0:4e3cb26f6019 7
lawliet 0:4e3cb26f6019 8 This library is free software; you can redistribute it and/or
lawliet 0:4e3cb26f6019 9 modify it under the terms of the GNU Lesser General Public
lawliet 0:4e3cb26f6019 10 License as published by the Free Software Foundation; either
lawliet 0:4e3cb26f6019 11 version 2.1 of the License, or (at your option) any later version.
lawliet 0:4e3cb26f6019 12
lawliet 0:4e3cb26f6019 13 This library is distributed in the hope that it will be useful,
lawliet 0:4e3cb26f6019 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
lawliet 0:4e3cb26f6019 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
lawliet 0:4e3cb26f6019 16 Lesser General Public License for more details.
lawliet 0:4e3cb26f6019 17
lawliet 0:4e3cb26f6019 18 You should have received a copy of the GNU Lesser General Public
lawliet 0:4e3cb26f6019 19 License along with this library; if not, write to the Free Software
lawliet 0:4e3cb26f6019 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
lawliet 0:4e3cb26f6019 21 */
lawliet 0:4e3cb26f6019 22
lawliet 0:4e3cb26f6019 23 #include "GPRSInterface.h"
lawliet 0:4e3cb26f6019 24 #include "mbed.h"
lawliet 0:4e3cb26f6019 25
lawliet 0:4e3cb26f6019 26 #if defined(TARGET_LPC11U24)//SEEEDUINO_ARCH
lawliet 0:4e3cb26f6019 27 #define PIN_TX P1_22
lawliet 0:4e3cb26f6019 28 #define PIN_RX P1_21
lawliet 0:4e3cb26f6019 29 #elif defined(TARGET_LPC1768)//SEEEDUINO_ARCH_PRO
lawliet 0:4e3cb26f6019 30 #define PIN_TX P0_0
lawliet 0:4e3cb26f6019 31 #define PIN_RX P0_1
lawliet 0:4e3cb26f6019 32 #else //please redefine the following pins
lawliet 0:4e3cb26f6019 33 #define PIN_TX
lawliet 0:4e3cb26f6019 34 #define PIN_RX
lawliet 0:4e3cb26f6019 35 #endif
lawliet 0:4e3cb26f6019 36
lawliet 0:4e3cb26f6019 37 GPRSInterface gprsInterface(PIN_TX,PIN_RX,19200,"cmnet",NULL,NULL);
lawliet 0:4e3cb26f6019 38
lawliet 0:4e3cb26f6019 39 int main(void)
lawliet 0:4e3cb26f6019 40 {
lawliet 0:4e3cb26f6019 41 // use DHCP
lawliet 0:4e3cb26f6019 42 gprsInterface.init();
lawliet 0:4e3cb26f6019 43
lawliet 0:4e3cb26f6019 44 // attempt DHCP
lawliet 0:4e3cb26f6019 45 while(false == gprsInterface.connect()) {
lawliet 0:4e3cb26f6019 46 wait(2);
lawliet 0:4e3cb26f6019 47 }
lawliet 0:4e3cb26f6019 48
lawliet 0:4e3cb26f6019 49 // successful DHCP
lawliet 0:4e3cb26f6019 50 printf("IP Address is %s\n", gprsInterface.getIPAddress());
lawliet 0:4e3cb26f6019 51
lawliet 0:4e3cb26f6019 52 TCPSocketConnection sock;
lawliet 0:4e3cb26f6019 53 if(false == sock.connect("mbed.org", 80)) {
lawliet 0:4e3cb26f6019 54 return -1;
lawliet 0:4e3cb26f6019 55 }
lawliet 0:4e3cb26f6019 56
lawliet 0:4e3cb26f6019 57 char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
lawliet 0:4e3cb26f6019 58 sock.send_all(http_cmd, sizeof(http_cmd)-1);
lawliet 0:4e3cb26f6019 59
lawliet 0:4e3cb26f6019 60 char buffer[512];
lawliet 0:4e3cb26f6019 61 int ret;
lawliet 0:4e3cb26f6019 62 while (true) {
lawliet 0:4e3cb26f6019 63 ret = sock.receive(buffer, sizeof(buffer)-1);
lawliet 0:4e3cb26f6019 64 if (ret <= 0)
lawliet 0:4e3cb26f6019 65 break;
lawliet 0:4e3cb26f6019 66 buffer[ret] = '\0';
lawliet 0:4e3cb26f6019 67 printf("Recv %d bytes:\n%s\n",ret,buffer);
lawliet 0:4e3cb26f6019 68 }
lawliet 0:4e3cb26f6019 69 sock.close();
lawliet 0:4e3cb26f6019 70 gprsInterface.disconnect();
lawliet 0:4e3cb26f6019 71
lawliet 0:4e3cb26f6019 72 return 0;
lawliet 0:4e3cb26f6019 73 }