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)
main.cpp
- Committer:
- Vanger
- Date:
- 2014-07-24
- Revision:
- 1:7a2c5889a55d
- Parent:
- 0:0be90fca1622
- Child:
- 2:e20a75d47720
File content as of revision 1:7a2c5889a55d:
#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); //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:\n\n%s\n\n",RequestLine); //Read HTTP response from server radio->read(read_response, 4097, 2000); printf("HTTP Response read:\n\n%s\n\n", read_response); //Disconnect PPP link radio->disconnect(); printf("End of example code\n"); return 0; }