see: https://developer.mbed.org/users/phsfan/notebook/phsshield/

Dependencies:   a3gs mbed

Fork of PHSShield_httpGET by phs fan

Committer:
phsfan
Date:
Thu Apr 30 04:46:04 2015 +0000
Revision:
3:952c3b733e4a
Parent:
2:12760b453533
fix Content-Type

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phsfan 0:15b79ec85118 1 #include "mbed.h"
phsfan 0:15b79ec85118 2 #include "a3gs.h"
phsfan 0:15b79ec85118 3
phsfan 0:15b79ec85118 4 Serial pc(USBTX, USBRX);
phsfan 0:15b79ec85118 5 DigitalOut myled(LED1);
phsfan 0:15b79ec85118 6
phsfan 2:12760b453533 7 // tx, rx, interrupt, power, regulator
phsfan 2:12760b453533 8 A3GS a3gs(p28, p27, p29, p23, p11, 9600); // mbeduino (LPC1768)
phsfan 2:12760b453533 9 //A3GS a3gs(PA_11, PA_12, D2, D6, D7, 9600); // Nucleo STM32F401RE
phsfan 0:15b79ec85118 10
phsfan 0:15b79ec85118 11 const char *server = "developer.mbed.org";
phsfan 0:15b79ec85118 12 const char *path = "/media/uploads/phsfan/hello.txt";
phsfan 3:952c3b733e4a 13 const char *head = "Content-Type: application/x-www-form-urlencoded";
phsfan 0:15b79ec85118 14 int port = 80;
phsfan 0:15b79ec85118 15
phsfan 0:15b79ec85118 16 int main() {
phsfan 0:15b79ec85118 17 pc.baud(115200);
phsfan 1:c2c4efc7a033 18 pc.printf("*** PHS httpGET\r\n");
phsfan 0:15b79ec85118 19
phsfan 0:15b79ec85118 20 a3gs.start();
phsfan 0:15b79ec85118 21 if (a3gs.begin()) {
phsfan 0:15b79ec85118 22 error("Could not connect");
phsfan 0:15b79ec85118 23 }
phsfan 0:15b79ec85118 24 myled = 1;
phsfan 0:15b79ec85118 25
phsfan 0:15b79ec85118 26 char buf[a3gsMAX_RESULT_LENGTH + 1];
phsfan 0:15b79ec85118 27 if (a3gs.httpGET(server, port, path, buf, sizeof(buf) - 1, 0, head) == 0) {
phsfan 0:15b79ec85118 28 pc.printf("OK!\r\n");
phsfan 0:15b79ec85118 29 pc.printf(buf);
phsfan 0:15b79ec85118 30 for (;;) {
phsfan 0:15b79ec85118 31 int r = a3gs.read(buf, sizeof(buf) - 1);
phsfan 0:15b79ec85118 32 if (r > 0) {
phsfan 0:15b79ec85118 33 pc.printf(buf);
phsfan 0:15b79ec85118 34 } else {
phsfan 0:15b79ec85118 35 break;
phsfan 0:15b79ec85118 36 }
phsfan 0:15b79ec85118 37 }
phsfan 1:c2c4efc7a033 38 pc.printf("\r\n");
phsfan 0:15b79ec85118 39 } else {
phsfan 0:15b79ec85118 40 pc.printf("Can't get HTTP response from %s\r\n", server);
phsfan 0:15b79ec85118 41 }
phsfan 1:c2c4efc7a033 42
phsfan 1:c2c4efc7a033 43 wait(3);
phsfan 0:15b79ec85118 44 a3gs.disconnectTCP();
phsfan 0:15b79ec85118 45 pc.printf("bye\r\n");
phsfan 0:15b79ec85118 46 a3gs.end();
phsfan 0:15b79ec85118 47 a3gs.shutdown();
phsfan 0:15b79ec85118 48 myled = 0;
phsfan 0:15b79ec85118 49 }