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

Dependencies:   a3gs mbed

Fork of PHSShield_httpGET by phs fan

main.cpp

Committer:
phsfan
Date:
2015-03-20
Revision:
0:15b79ec85118
Child:
1:c2c4efc7a033

File content as of revision 0:15b79ec85118:

#include "mbed.h"
#include "a3gs.h"

Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);

A3GS a3gs(p28, p27, p29, p23, p11, 9600); // tx, rx, interrupt, power, regulator

const char *server = "developer.mbed.org";
const char *path = "/media/uploads/phsfan/hello.txt";
const char *head = "Accept: text/html\r\nConnection: Keep-Alive";
int port = 80;

int main() {
    pc.baud(115200);
    pc.printf("*** PHS test\r\n");

    a3gs.start();
    if (a3gs.begin()) {
        error("Could not connect");
    }
    myled = 1;

    char buf[a3gsMAX_RESULT_LENGTH + 1];
    if (a3gs.httpGET(server, port, path, buf, sizeof(buf) - 1, 0, head) == 0) {
        pc.printf("OK!\r\n");
        pc.printf(buf);
        for (;;) {
            int r = a3gs.read(buf, sizeof(buf) - 1);
            if (r > 0) {
                pc.printf(buf);
            } else {
                break;
            }
        }
    } else {
        pc.printf("Can't get HTTP response from %s\r\n", server);
    }
    a3gs.disconnectTCP();

    wait(1);
    pc.printf("bye\r\n");
    a3gs.end();
    a3gs.shutdown();
    myled = 0;
}