Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:e20a75d47720, committed 2014-08-05
- Comitter:
- Vanger
- Date:
- Tue Aug 05 14:43:29 2014 +0000
- Parent:
- 1:7a2c5889a55d
- Child:
- 3:85181c1324f2
- Commit message:
- Removed APN value
Changed in this revision
--- a/main.cpp Thu Jul 24 20:03:05 2014 +0000
+++ b/main.cpp Tue Aug 05 14:43:29 2014 +0000
@@ -3,13 +3,16 @@
int main(){
//Modify to match your apn if you are using an HSPA radio with a SIM card
- const char APN[] = "internet";
+ const char APN[] = "";
+
+ /* Sets the log level for INFO level. INFO is a midway log level, available levels are: TRACE, DEBUG, INFO, WARNING, ERROR, FATAL, NONE */
+ MTSLog::setLogLevel(MTSLog::INFO_LEVEL);
- //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";
+ //Receive buffer
+ char rbuf[4000];
- //Response character array to read in the HTTP response
- char read_response[4096] = {0};
+ //url strings for HTTP requests, httpbin.org is a public website for fielding test HTTP requests
+ string url, base_url = "http://httpbin.org:80", url_get = "/get";
/** STMicro Nucelo F401RE
* The supported jumper configurations of the MTSAS do not line up with
@@ -40,26 +43,43 @@
//Sets the baudrate for communicating with the radio
io->baud(115200);
+ //Initialize radio configurations
Cellular* radio = CellularFactory::create(io);
+ if( ! radio) {
+ logFatal("Radio initialization failed");
+ }
+ radio->configureSignals(D4,D7,RESET);
+ Transport::setTransport(radio);
+
+ //Set up HTTP interface
+ HTTPClient* http = new HTTPClient();
+ HTTPText* receive = new HTTPText(rbuf);
+
+ //Set APN value
radio->setApn(APN);
//Establish PPP link
radio->connect();
- //Open TCP socket to httpbin.org
- radio->open("httpbin.org", 80, IPStack::TCP);
+ //Format HTTP Get request
+ url = base_url + url_get;
- //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);
+ //Send HTTP GET request
+ for (int i = 0; i < 10; i++) {
+ if(http->get(url.c_str(), receive, 5000) == HTTP_OK) {
+ http->get(url.c_str(), receive, 5000);
+ logInfo("HTTP get succeeded");
+ break;
+ }
+ if (i >= 10) {
+ logError("HTTP GET failed");
+ }
+ wait(1);
+ }
//Disconnect PPP link
radio->disconnect();
- printf("End of example code\n");
+ logInfo("End of example code\n");
return 0;
}
\ No newline at end of file
--- a/mtsas-dev.lib Thu Jul 24 20:03:05 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/teams/Multi-Hackers/code/mtsas-dev/#c532bba7e716
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mtsas.lib Tue Aug 05 14:43:29 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Multi-Hackers/code/mtsas/#b599bdb14c12