mbed 5.4 with sleep mode

Dependencies:   C027_Support mbed-dev

Fork of C027_SupportTest_coap by Umar Naeem

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 }