Example program demonstrating use of HTTP or HTTPS protocol over a cellular connection with httpbin.org using the MTSAS library. (Demonstrates GET,POST,basic-auth)
Diff: main.cpp
- Revision:
- 0:0be90fca1622
- Child:
- 1:7a2c5889a55d
diff -r 000000000000 -r 0be90fca1622 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jul 24 19:10:18 2014 +0000 @@ -0,0 +1,66 @@ +#include "mbed.h" +#include "mtsas.h" + +int main(){ + //Modify to match your apn if you are using an HSPA radio with a SIM card + const char APN[] = "internet"; + + //HTTP Test server is httpbin.org, the RequestLine is the HTTP request string + const char RequestLine[] = "GET /get HTTP/1.1\r\nHost: httpbin.org\r\nContent-type: application/MTSAS-DEV\r\nContent-length: 0\r\n\r\n"; + + //Response character array to read in the HTTP response + char read_response[4096] = {0}; + + /** STMicro Nucelo F401RE + * The supported jumper configurations of the MTSAS do not line up with + * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX + * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2) + * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to + * Serial1 TX (Shield pin D8). + * Uncomment the following line to use the STMicro Nuceleo F401RE + */ + MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6); + + /** Freescale KL46Z + * To configure the pins for the Freescale KL46Z board, use configuration B + * for the SocketModem. The TX pin should be jumped to pin D2 (JP8), and the + * RX pin should be jumped to pin D9 (JP9). + * Uncomment te following line to use the Freescale KL46Z board + */ + //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6); + + /** Freescale KL64F + * To configure the pins for the Freescale KL46Z board, use configuration A + * for the SocketModem. The TX pin should be jumped to pin D1 (JP8), and the + * RX pin should be jumped to pin D0 (JP9). + * Uncomment te following line to use the Freescale KL46F board + */ + //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6); + + //Sets the baudrate for communicating with the radio + io->baud(115200); + + Cellular* radio = CellularFactory::create(io); + radio->setApn(APN); + wait(10); + + //Establish PPP link + radio->connect(); + + //Open TCP socket to httpbin.org + radio->open("httpbin.org", 80, IPStack::TCP); + + //Send HTTP request + radio->write(RequestLine, sizeof(RequestLine), 2000); + printf("HTTP Request sent:[%s]\n",RequestLine); + + //Read HTTP response from server + radio->read(read_response, 4097, 2000); + printf("HTTP Response read:[%s]\n", read_response); + + //Disconnect PPP link + radio->disconnect(); + + printf("End of example code\n"); + return 0; +} \ No newline at end of file