Demo having the purpose to provide some examples about HTTP and HTTPS procedures.
Dependencies: C027_Support mbed
This demo has the purpose to provide some examples about HTTP and HTTPS procedures.
In details are implemented the following actions referring freely available online services:
- HTTP and HTTPS HEAD command -> www.developer.mbed.org
- HTTP and HTTPS GET command -> www.developer.mbed.org
- HTTP and HTTPS DELETE command -> www.httpbin.org
- HTTP and HTTPS PUT command -> www.httpbin.org
- HTTP and HTTPS POST file command -> www.posttestserver.com
- HTTP and HTTPS POST data command -> www.posttestserver.com
Please don't use confidential data when trying out the reported examples.
As default, the httpInData variable is set to "Hello World" (see source code).
main.cpp@0:c25f7731ecc3, 2016-01-22 (annotated)
- Committer:
- fdilenarda
- Date:
- Fri Jan 22 14:17:13 2016 +0000
- Revision:
- 0:c25f7731ecc3
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fdilenarda | 0:c25f7731ecc3 | 1 | #include "mbed.h" |
fdilenarda | 0:c25f7731ecc3 | 2 | |
fdilenarda | 0:c25f7731ecc3 | 3 | //------------------------------------------------------------------------------------ |
fdilenarda | 0:c25f7731ecc3 | 4 | /* This demo has the purpose to provide some examples about HTTP procedures. |
fdilenarda | 0:c25f7731ecc3 | 5 | In details are implemented the following actions referring freely available online services: |
fdilenarda | 0:c25f7731ecc3 | 6 | |
fdilenarda | 0:c25f7731ecc3 | 7 | - HTTP and HTTPS HEAD command -> www.developer.mbed.org |
fdilenarda | 0:c25f7731ecc3 | 8 | - HTTP and HTTPS GET command -> www.developer.mbed.org |
fdilenarda | 0:c25f7731ecc3 | 9 | - HTTP and HTTPS DELETE command -> www.httpbin.org |
fdilenarda | 0:c25f7731ecc3 | 10 | - HTTP and HTTPS PUT command -> www.httpbin.org |
fdilenarda | 0:c25f7731ecc3 | 11 | - HTTP and HTTPS POST file command -> www.posttestserver.com |
fdilenarda | 0:c25f7731ecc3 | 12 | - HTTP and HTTPS POST data command -> www.posttestserver.com |
fdilenarda | 0:c25f7731ecc3 | 13 | |
fdilenarda | 0:c25f7731ecc3 | 14 | P.S.: Please don't use confidential data when trying out the reported examples. |
fdilenarda | 0:c25f7731ecc3 | 15 | As default, the httpInData variable is set to "Hello World" (see below). |
fdilenarda | 0:c25f7731ecc3 | 16 | */ |
fdilenarda | 0:c25f7731ecc3 | 17 | #include "MDM.h" |
fdilenarda | 0:c25f7731ecc3 | 18 | //------------------------------------------------------------------------------------ |
fdilenarda | 0:c25f7731ecc3 | 19 | // You need to configure these cellular modem / SIM parameters. |
fdilenarda | 0:c25f7731ecc3 | 20 | // These parameters are ignored for LISA-C200 variants and can be left NULL. |
fdilenarda | 0:c25f7731ecc3 | 21 | //------------------------------------------------------------------------------------ |
fdilenarda | 0:c25f7731ecc3 | 22 | //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. |
fdilenarda | 0:c25f7731ecc3 | 23 | #define SIMPIN NULL |
fdilenarda | 0:c25f7731ecc3 | 24 | /*! The APN of your network operator SIM, sometimes it is "internet" check your |
fdilenarda | 0:c25f7731ecc3 | 25 | contract with the network operator. You can also try to look-up your settings in |
fdilenarda | 0:c25f7731ecc3 | 26 | google: https://www.google.de/search?q=APN+list */ |
fdilenarda | 0:c25f7731ecc3 | 27 | #define APN NULL |
fdilenarda | 0:c25f7731ecc3 | 28 | //! Set the user name for your APN, or NULL if not needed |
fdilenarda | 0:c25f7731ecc3 | 29 | #define USERNAME NULL |
fdilenarda | 0:c25f7731ecc3 | 30 | //! Set the password for your APN, or NULL if not needed |
fdilenarda | 0:c25f7731ecc3 | 31 | #define PASSWORD NULL |
fdilenarda | 0:c25f7731ecc3 | 32 | //------------------------------------------------------------------------------------ |
fdilenarda | 0:c25f7731ecc3 | 33 | // You need to configure the buffer data size |
fdilenarda | 0:c25f7731ecc3 | 34 | //------------------------------------------------------------------------------------ |
fdilenarda | 0:c25f7731ecc3 | 35 | //! Set the buffer size to 2048 bytes |
fdilenarda | 0:c25f7731ecc3 | 36 | //#define LARGE_DATA |
fdilenarda | 0:c25f7731ecc3 | 37 | //! Set the buffer size to 1024 bytes |
fdilenarda | 0:c25f7731ecc3 | 38 | #define MEDIUM_DATA |
fdilenarda | 0:c25f7731ecc3 | 39 | //------------------------------------------------------------------------------------ |
fdilenarda | 0:c25f7731ecc3 | 40 | |
fdilenarda | 0:c25f7731ecc3 | 41 | int main(void) |
fdilenarda | 0:c25f7731ecc3 | 42 | { |
fdilenarda | 0:c25f7731ecc3 | 43 | int ret; |
fdilenarda | 0:c25f7731ecc3 | 44 | #if defined(LARGE_DATA) |
fdilenarda | 0:c25f7731ecc3 | 45 | printf("Set the buffer size to 2048 bytes\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 46 | char buf[2048] = ""; |
fdilenarda | 0:c25f7731ecc3 | 47 | #elif defined(MEDIUM_DATA) |
fdilenarda | 0:c25f7731ecc3 | 48 | printf("Set the buffer size to 1024 bytes\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 49 | char buf[1024] = ""; |
fdilenarda | 0:c25f7731ecc3 | 50 | #else |
fdilenarda | 0:c25f7731ecc3 | 51 | printf("Set the buffer size to 512 bytes\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 52 | char buf[512] = ""; |
fdilenarda | 0:c25f7731ecc3 | 53 | #endif |
fdilenarda | 0:c25f7731ecc3 | 54 | //give time to module for powering up (ms) |
fdilenarda | 0:c25f7731ecc3 | 55 | wait_ms(1000); |
fdilenarda | 0:c25f7731ecc3 | 56 | // Create the modem object |
fdilenarda | 0:c25f7731ecc3 | 57 | MDMSerial mdm; |
fdilenarda | 0:c25f7731ecc3 | 58 | //mdm.setDebug(4); // enable this for debugging issues |
fdilenarda | 0:c25f7731ecc3 | 59 | // initialize the modem |
fdilenarda | 0:c25f7731ecc3 | 60 | MDMParser::DevStatus devStatus = {}; |
fdilenarda | 0:c25f7731ecc3 | 61 | MDMParser::NetStatus netStatus = {}; |
fdilenarda | 0:c25f7731ecc3 | 62 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
fdilenarda | 0:c25f7731ecc3 | 63 | mdm.dumpDevStatus(&devStatus); |
fdilenarda | 0:c25f7731ecc3 | 64 | if (mdmOk) { |
fdilenarda | 0:c25f7731ecc3 | 65 | #if 0 |
fdilenarda | 0:c25f7731ecc3 | 66 | // file system API |
fdilenarda | 0:c25f7731ecc3 | 67 | const char* filename = "File"; |
fdilenarda | 0:c25f7731ecc3 | 68 | char buf[] = "Hello World"; |
fdilenarda | 0:c25f7731ecc3 | 69 | printf("writeFile \"%s\"\r\n", buf); |
fdilenarda | 0:c25f7731ecc3 | 70 | if (mdm.writeFile(filename, buf, sizeof(buf))) |
fdilenarda | 0:c25f7731ecc3 | 71 | { |
fdilenarda | 0:c25f7731ecc3 | 72 | memset(buf, 0, sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 73 | int len = mdm.readFile(filename, buf, sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 74 | if (len >= 0) |
fdilenarda | 0:c25f7731ecc3 | 75 | printf("readFile %d \"%.*s\"\r\n", len, len, buf); |
fdilenarda | 0:c25f7731ecc3 | 76 | mdm.delFile(filename); |
fdilenarda | 0:c25f7731ecc3 | 77 | } |
fdilenarda | 0:c25f7731ecc3 | 78 | #endif |
fdilenarda | 0:c25f7731ecc3 | 79 | |
fdilenarda | 0:c25f7731ecc3 | 80 | // wait until we are connected |
fdilenarda | 0:c25f7731ecc3 | 81 | mdmOk = mdm.registerNet(&netStatus); |
fdilenarda | 0:c25f7731ecc3 | 82 | mdm.dumpNetStatus(&netStatus); |
fdilenarda | 0:c25f7731ecc3 | 83 | } |
fdilenarda | 0:c25f7731ecc3 | 84 | if (mdmOk) |
fdilenarda | 0:c25f7731ecc3 | 85 | { |
fdilenarda | 0:c25f7731ecc3 | 86 | // http://www.geckobeach.com/cellular/secrets/gsmcodes.php |
fdilenarda | 0:c25f7731ecc3 | 87 | // http://de.wikipedia.org/wiki/USSD-Codes |
fdilenarda | 0:c25f7731ecc3 | 88 | const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION" |
fdilenarda | 0:c25f7731ecc3 | 89 | printf("Ussd Send Command %s\r\n", ussd); |
fdilenarda | 0:c25f7731ecc3 | 90 | ret = mdm.ussdCommand(ussd, buf); |
fdilenarda | 0:c25f7731ecc3 | 91 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 92 | printf("Ussd Got Answer: \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 93 | |
fdilenarda | 0:c25f7731ecc3 | 94 | // join the internet connection |
fdilenarda | 0:c25f7731ecc3 | 95 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
fdilenarda | 0:c25f7731ecc3 | 96 | if (ip != NOIP) |
fdilenarda | 0:c25f7731ecc3 | 97 | { |
fdilenarda | 0:c25f7731ecc3 | 98 | mdm.dumpIp(ip); |
fdilenarda | 0:c25f7731ecc3 | 99 | |
fdilenarda | 0:c25f7731ecc3 | 100 | printf("HTTP and HTTPS management\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 101 | char httpInData[] = "Hello World"; //input data for some HTTP commands |
fdilenarda | 0:c25f7731ecc3 | 102 | char httpInFile[48] = "http_in.txt"; //file where saving HTTP commands data |
fdilenarda | 0:c25f7731ecc3 | 103 | char httpOutFile[48] = "http_out.txt"; //file where saving HTTP commands results |
fdilenarda | 0:c25f7731ecc3 | 104 | |
fdilenarda | 0:c25f7731ecc3 | 105 | int httpProfile = mdm.httpFindProfile(); //get the HTTP profile identifier |
fdilenarda | 0:c25f7731ecc3 | 106 | if (httpProfile >= 0) |
fdilenarda | 0:c25f7731ecc3 | 107 | { |
fdilenarda | 0:c25f7731ecc3 | 108 | printf("Make an HTTP and HTTPS HEAD Request\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 109 | if(mdm.httpResetProfile(httpProfile)) |
fdilenarda | 0:c25f7731ecc3 | 110 | { |
fdilenarda | 0:c25f7731ecc3 | 111 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SERVER_NAME,"developer.mbed.org")) |
fdilenarda | 0:c25f7731ecc3 | 112 | { |
fdilenarda | 0:c25f7731ecc3 | 113 | mdm.httpSetBlocking(httpProfile, 10000); //timeout is 10000 ms: not blocking procedure |
fdilenarda | 0:c25f7731ecc3 | 114 | |
fdilenarda | 0:c25f7731ecc3 | 115 | //HTTP HEAD command |
fdilenarda | 0:c25f7731ecc3 | 116 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_HEAD, |
fdilenarda | 0:c25f7731ecc3 | 117 | "/media/uploads/mbed_official/hello.txt", |
fdilenarda | 0:c25f7731ecc3 | 118 | httpOutFile,NULL,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 119 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 120 | printf("HTTP HEAD result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 121 | |
fdilenarda | 0:c25f7731ecc3 | 122 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SECURE,"1")) //HTTP Secure option enabled |
fdilenarda | 0:c25f7731ecc3 | 123 | { |
fdilenarda | 0:c25f7731ecc3 | 124 | //HTTPS HEAD command |
fdilenarda | 0:c25f7731ecc3 | 125 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_HEAD, |
fdilenarda | 0:c25f7731ecc3 | 126 | "/media/uploads/mbed_official/hello.txt", |
fdilenarda | 0:c25f7731ecc3 | 127 | httpOutFile,NULL,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 128 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 129 | printf("HTTPS HEAD result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 130 | } else { |
fdilenarda | 0:c25f7731ecc3 | 131 | printf("Abnormal condition during the set of HTTP secure option\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 132 | } |
fdilenarda | 0:c25f7731ecc3 | 133 | |
fdilenarda | 0:c25f7731ecc3 | 134 | //delete the HTTP output file |
fdilenarda | 0:c25f7731ecc3 | 135 | mdm.delFile(httpOutFile); |
fdilenarda | 0:c25f7731ecc3 | 136 | } else { |
fdilenarda | 0:c25f7731ecc3 | 137 | printf("Abnormal condition during the set of the HTTP server name\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 138 | } |
fdilenarda | 0:c25f7731ecc3 | 139 | } else { |
fdilenarda | 0:c25f7731ecc3 | 140 | printf("Abnormal condition during the reset of HTTP profile %d\r\n", httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 141 | } |
fdilenarda | 0:c25f7731ecc3 | 142 | |
fdilenarda | 0:c25f7731ecc3 | 143 | printf("Make an HTTP and HTTPS GET Request\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 144 | if(mdm.httpResetProfile(httpProfile)) |
fdilenarda | 0:c25f7731ecc3 | 145 | { |
fdilenarda | 0:c25f7731ecc3 | 146 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SERVER_NAME,"developer.mbed.org")) |
fdilenarda | 0:c25f7731ecc3 | 147 | { |
fdilenarda | 0:c25f7731ecc3 | 148 | mdm.httpSetBlocking(httpProfile, 10000); //timeout is 10000 ms: not blocking procedure |
fdilenarda | 0:c25f7731ecc3 | 149 | |
fdilenarda | 0:c25f7731ecc3 | 150 | //HTTP GET command |
fdilenarda | 0:c25f7731ecc3 | 151 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_GET, |
fdilenarda | 0:c25f7731ecc3 | 152 | "/media/uploads/mbed_official/hello.txt", |
fdilenarda | 0:c25f7731ecc3 | 153 | httpOutFile,NULL,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 154 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 155 | printf("HTTP GET result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 156 | |
fdilenarda | 0:c25f7731ecc3 | 157 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SECURE,"1")) //HTTP Secure option enabled |
fdilenarda | 0:c25f7731ecc3 | 158 | { |
fdilenarda | 0:c25f7731ecc3 | 159 | //HTTPS GET command |
fdilenarda | 0:c25f7731ecc3 | 160 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_GET, |
fdilenarda | 0:c25f7731ecc3 | 161 | "/media/uploads/mbed_official/hello.txt", |
fdilenarda | 0:c25f7731ecc3 | 162 | httpOutFile,NULL,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 163 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 164 | printf("HTTPS GET result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 165 | } else { |
fdilenarda | 0:c25f7731ecc3 | 166 | printf("Abnormal condition during the set of HTTP secure option\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 167 | } |
fdilenarda | 0:c25f7731ecc3 | 168 | |
fdilenarda | 0:c25f7731ecc3 | 169 | //delete the HTTP output file |
fdilenarda | 0:c25f7731ecc3 | 170 | mdm.delFile(httpOutFile); |
fdilenarda | 0:c25f7731ecc3 | 171 | } else { |
fdilenarda | 0:c25f7731ecc3 | 172 | printf("Abnormal condition during the set of the HTTP server name\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 173 | } |
fdilenarda | 0:c25f7731ecc3 | 174 | } else { |
fdilenarda | 0:c25f7731ecc3 | 175 | printf("Abnormal condition during the reset of HTTP profile %d\r\n", httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 176 | } |
fdilenarda | 0:c25f7731ecc3 | 177 | |
fdilenarda | 0:c25f7731ecc3 | 178 | printf("Make an HTTP and HTTPS DELETE Request\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 179 | if(mdm.httpResetProfile(httpProfile)) |
fdilenarda | 0:c25f7731ecc3 | 180 | { |
fdilenarda | 0:c25f7731ecc3 | 181 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SERVER_NAME,"httpbin.org")) |
fdilenarda | 0:c25f7731ecc3 | 182 | { |
fdilenarda | 0:c25f7731ecc3 | 183 | mdm.httpSetBlocking(httpProfile, 10000); //timeout is 10000 ms: not blocking procedure |
fdilenarda | 0:c25f7731ecc3 | 184 | |
fdilenarda | 0:c25f7731ecc3 | 185 | //HTTP DELETE command |
fdilenarda | 0:c25f7731ecc3 | 186 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_DELETE,"/delete", \ |
fdilenarda | 0:c25f7731ecc3 | 187 | httpOutFile,NULL,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 188 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 189 | printf("HTTP DELETE result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 190 | |
fdilenarda | 0:c25f7731ecc3 | 191 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SECURE,"1")) //HTTP Secure option enabled |
fdilenarda | 0:c25f7731ecc3 | 192 | { |
fdilenarda | 0:c25f7731ecc3 | 193 | //HTTPS DELETE command |
fdilenarda | 0:c25f7731ecc3 | 194 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_DELETE,"/delete", \ |
fdilenarda | 0:c25f7731ecc3 | 195 | httpOutFile,NULL,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 196 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 197 | printf("HTTPS DELETE result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 198 | } else { |
fdilenarda | 0:c25f7731ecc3 | 199 | printf("Abnormal condition during the set of HTTP secure option\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 200 | } |
fdilenarda | 0:c25f7731ecc3 | 201 | |
fdilenarda | 0:c25f7731ecc3 | 202 | //delete the HTTP output file |
fdilenarda | 0:c25f7731ecc3 | 203 | mdm.delFile(httpOutFile); |
fdilenarda | 0:c25f7731ecc3 | 204 | |
fdilenarda | 0:c25f7731ecc3 | 205 | } else { |
fdilenarda | 0:c25f7731ecc3 | 206 | printf("Abnormal condition during the set of the HTTP server name\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 207 | } |
fdilenarda | 0:c25f7731ecc3 | 208 | } else { |
fdilenarda | 0:c25f7731ecc3 | 209 | printf("Abnormal condition during the reset of HTTP profile %d\r\n", httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 210 | } |
fdilenarda | 0:c25f7731ecc3 | 211 | |
fdilenarda | 0:c25f7731ecc3 | 212 | printf("Make an HTTP and HTTPS PUT Request\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 213 | if(mdm.httpResetProfile(httpProfile)) |
fdilenarda | 0:c25f7731ecc3 | 214 | { |
fdilenarda | 0:c25f7731ecc3 | 215 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SERVER_NAME,"httpbin.org")) |
fdilenarda | 0:c25f7731ecc3 | 216 | { |
fdilenarda | 0:c25f7731ecc3 | 217 | if(mdm.writeFile(httpInFile,httpInData,sizeof(httpInData))) |
fdilenarda | 0:c25f7731ecc3 | 218 | { |
fdilenarda | 0:c25f7731ecc3 | 219 | mdm.httpSetBlocking(httpProfile, 10000); //timeout is 10000 ms: not blocking procedure |
fdilenarda | 0:c25f7731ecc3 | 220 | |
fdilenarda | 0:c25f7731ecc3 | 221 | //HTTP PUT command |
fdilenarda | 0:c25f7731ecc3 | 222 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_PUT,"/put", \ |
fdilenarda | 0:c25f7731ecc3 | 223 | httpOutFile,httpInFile,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 224 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 225 | printf("HTTP PUT result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 226 | |
fdilenarda | 0:c25f7731ecc3 | 227 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SECURE,"1")) //HTTP Secure option enabled |
fdilenarda | 0:c25f7731ecc3 | 228 | { |
fdilenarda | 0:c25f7731ecc3 | 229 | //HTTPS PUT command |
fdilenarda | 0:c25f7731ecc3 | 230 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_PUT,"/put", \ |
fdilenarda | 0:c25f7731ecc3 | 231 | httpOutFile,httpInFile,NULL,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 232 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 233 | printf("HTTPS PUT result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 234 | } else { |
fdilenarda | 0:c25f7731ecc3 | 235 | printf("Abnormal condition during the set of HTTP secure option\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 236 | } |
fdilenarda | 0:c25f7731ecc3 | 237 | |
fdilenarda | 0:c25f7731ecc3 | 238 | //delete the HTTP input file |
fdilenarda | 0:c25f7731ecc3 | 239 | mdm.delFile(httpInFile); |
fdilenarda | 0:c25f7731ecc3 | 240 | |
fdilenarda | 0:c25f7731ecc3 | 241 | //delete the HTTP output file |
fdilenarda | 0:c25f7731ecc3 | 242 | mdm.delFile(httpOutFile); |
fdilenarda | 0:c25f7731ecc3 | 243 | } else { |
fdilenarda | 0:c25f7731ecc3 | 244 | printf("Abnormal condition during the writing of the HTTP input file\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 245 | } |
fdilenarda | 0:c25f7731ecc3 | 246 | } else { |
fdilenarda | 0:c25f7731ecc3 | 247 | printf("Abnormal condition during the set of the HTTP server name\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 248 | } |
fdilenarda | 0:c25f7731ecc3 | 249 | } else { |
fdilenarda | 0:c25f7731ecc3 | 250 | printf("Abnormal condition during the reset of HTTP profile %d\r\n", httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 251 | } |
fdilenarda | 0:c25f7731ecc3 | 252 | |
fdilenarda | 0:c25f7731ecc3 | 253 | printf("Make an HTTP and HTTPS POST file command Request\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 254 | if(mdm.httpResetProfile(httpProfile)) |
fdilenarda | 0:c25f7731ecc3 | 255 | { |
fdilenarda | 0:c25f7731ecc3 | 256 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SERVER_NAME,"posttestserver.com")) |
fdilenarda | 0:c25f7731ecc3 | 257 | { |
fdilenarda | 0:c25f7731ecc3 | 258 | if(mdm.writeFile(httpInFile,httpInData,sizeof(httpInData))) |
fdilenarda | 0:c25f7731ecc3 | 259 | { |
fdilenarda | 0:c25f7731ecc3 | 260 | mdm.httpSetBlocking(httpProfile, 10000); //timeout is 10000 ms: not blocking procedure |
fdilenarda | 0:c25f7731ecc3 | 261 | |
fdilenarda | 0:c25f7731ecc3 | 262 | //HTTP POST file command |
fdilenarda | 0:c25f7731ecc3 | 263 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_POST_FILE,"/post.php", \ |
fdilenarda | 0:c25f7731ecc3 | 264 | httpOutFile,httpInFile,1,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 265 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 266 | printf("HTTP POST file command result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 267 | |
fdilenarda | 0:c25f7731ecc3 | 268 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SECURE,"1")) //HTTP Secure option enabled |
fdilenarda | 0:c25f7731ecc3 | 269 | { |
fdilenarda | 0:c25f7731ecc3 | 270 | //HTTPS POST file command |
fdilenarda | 0:c25f7731ecc3 | 271 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_POST_FILE,"/post.php", \ |
fdilenarda | 0:c25f7731ecc3 | 272 | httpOutFile,httpInFile,1,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 273 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 274 | printf("HTTPS POST file command result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 275 | } else { |
fdilenarda | 0:c25f7731ecc3 | 276 | printf("Abnormal condition during the set of HTTP secure option\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 277 | } |
fdilenarda | 0:c25f7731ecc3 | 278 | //delete the HTTP input file |
fdilenarda | 0:c25f7731ecc3 | 279 | mdm.delFile(httpInFile); |
fdilenarda | 0:c25f7731ecc3 | 280 | |
fdilenarda | 0:c25f7731ecc3 | 281 | //delete the HTTP output file |
fdilenarda | 0:c25f7731ecc3 | 282 | mdm.delFile(httpOutFile); |
fdilenarda | 0:c25f7731ecc3 | 283 | } else { |
fdilenarda | 0:c25f7731ecc3 | 284 | printf("Abnormal condition during the writing of the HTTP input file\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 285 | } |
fdilenarda | 0:c25f7731ecc3 | 286 | } else { |
fdilenarda | 0:c25f7731ecc3 | 287 | printf("Abnormal condition during the set of the HTTP server name\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 288 | } |
fdilenarda | 0:c25f7731ecc3 | 289 | } else { |
fdilenarda | 0:c25f7731ecc3 | 290 | printf("Abnormal condition during the reset of HTTP profile %d\r\n", httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 291 | } |
fdilenarda | 0:c25f7731ecc3 | 292 | |
fdilenarda | 0:c25f7731ecc3 | 293 | printf("Make an HTTP and HTTPS POST data command Request\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 294 | if(mdm.httpResetProfile(httpProfile)) |
fdilenarda | 0:c25f7731ecc3 | 295 | { |
fdilenarda | 0:c25f7731ecc3 | 296 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SERVER_NAME,"posttestserver.com")) |
fdilenarda | 0:c25f7731ecc3 | 297 | { |
fdilenarda | 0:c25f7731ecc3 | 298 | if(mdm.writeFile(httpInFile,httpInData,sizeof(httpInData))) |
fdilenarda | 0:c25f7731ecc3 | 299 | { |
fdilenarda | 0:c25f7731ecc3 | 300 | mdm.httpSetBlocking(httpProfile, 10000); //timeout is 10000 ms: not blocking procedure |
fdilenarda | 0:c25f7731ecc3 | 301 | |
fdilenarda | 0:c25f7731ecc3 | 302 | //HTTP POST data command |
fdilenarda | 0:c25f7731ecc3 | 303 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_POST_DATA,"/post.php", \ |
fdilenarda | 0:c25f7731ecc3 | 304 | httpOutFile,httpInData,1,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 305 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 306 | printf("HTTP POST data command result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 307 | |
fdilenarda | 0:c25f7731ecc3 | 308 | if (mdm.httpSetPar(httpProfile,MDMParser::HTTP_SECURE,"1")) //HTTP Secure option enabled |
fdilenarda | 0:c25f7731ecc3 | 309 | { |
fdilenarda | 0:c25f7731ecc3 | 310 | //HTTPS POST data command |
fdilenarda | 0:c25f7731ecc3 | 311 | ret = mdm.httpCommand(httpProfile,MDMParser::HTTP_POST_DATA,"/post.php", \ |
fdilenarda | 0:c25f7731ecc3 | 312 | httpOutFile,httpInData,1,NULL,buf,sizeof(buf)); |
fdilenarda | 0:c25f7731ecc3 | 313 | if (ret > 0) |
fdilenarda | 0:c25f7731ecc3 | 314 | printf("HTTPS POST data command result \"%*s\"\r\n", ret, buf); |
fdilenarda | 0:c25f7731ecc3 | 315 | } else { |
fdilenarda | 0:c25f7731ecc3 | 316 | printf("Abnormal condition during the set of HTTP secure option\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 317 | } |
fdilenarda | 0:c25f7731ecc3 | 318 | |
fdilenarda | 0:c25f7731ecc3 | 319 | //delete the HTTP input file |
fdilenarda | 0:c25f7731ecc3 | 320 | mdm.delFile(httpInFile); |
fdilenarda | 0:c25f7731ecc3 | 321 | |
fdilenarda | 0:c25f7731ecc3 | 322 | //delete the HTTP output file |
fdilenarda | 0:c25f7731ecc3 | 323 | mdm.delFile(httpOutFile); |
fdilenarda | 0:c25f7731ecc3 | 324 | } else { |
fdilenarda | 0:c25f7731ecc3 | 325 | printf("Abnormal condition during the writing of the HTTP input file\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 326 | } |
fdilenarda | 0:c25f7731ecc3 | 327 | } else { |
fdilenarda | 0:c25f7731ecc3 | 328 | printf("Abnormal condition during the set of the HTTP server name\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 329 | } |
fdilenarda | 0:c25f7731ecc3 | 330 | } else { |
fdilenarda | 0:c25f7731ecc3 | 331 | printf("Abnormal condition during the reset of HTTP profile %d\r\n", httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 332 | } |
fdilenarda | 0:c25f7731ecc3 | 333 | |
fdilenarda | 0:c25f7731ecc3 | 334 | //free current HTTP profile |
fdilenarda | 0:c25f7731ecc3 | 335 | mdm.httpFreeProfile(httpProfile); |
fdilenarda | 0:c25f7731ecc3 | 336 | } else { |
fdilenarda | 0:c25f7731ecc3 | 337 | printf("Abnormal condition: no available HTTP profiles\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 338 | } |
fdilenarda | 0:c25f7731ecc3 | 339 | |
fdilenarda | 0:c25f7731ecc3 | 340 | // disconnect |
fdilenarda | 0:c25f7731ecc3 | 341 | mdm.disconnect(); |
fdilenarda | 0:c25f7731ecc3 | 342 | } |
fdilenarda | 0:c25f7731ecc3 | 343 | } |
fdilenarda | 0:c25f7731ecc3 | 344 | else |
fdilenarda | 0:c25f7731ecc3 | 345 | { |
fdilenarda | 0:c25f7731ecc3 | 346 | //in this case the mdmOk is set to false |
fdilenarda | 0:c25f7731ecc3 | 347 | printf("Please verify the SIM status and the network coverage\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 348 | } |
fdilenarda | 0:c25f7731ecc3 | 349 | printf("Final loop: start\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 350 | int maxLoops = 3; |
fdilenarda | 0:c25f7731ecc3 | 351 | const int wait = 1000; |
fdilenarda | 0:c25f7731ecc3 | 352 | for (int i=0; i < maxLoops; i++) |
fdilenarda | 0:c25f7731ecc3 | 353 | { |
fdilenarda | 0:c25f7731ecc3 | 354 | if (mdmOk) |
fdilenarda | 0:c25f7731ecc3 | 355 | { |
fdilenarda | 0:c25f7731ecc3 | 356 | // check the network status |
fdilenarda | 0:c25f7731ecc3 | 357 | if (mdm.checkNetStatus(&netStatus)) { |
fdilenarda | 0:c25f7731ecc3 | 358 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
fdilenarda | 0:c25f7731ecc3 | 359 | } |
fdilenarda | 0:c25f7731ecc3 | 360 | } |
fdilenarda | 0:c25f7731ecc3 | 361 | wait_ms(wait); |
fdilenarda | 0:c25f7731ecc3 | 362 | } |
fdilenarda | 0:c25f7731ecc3 | 363 | printf("Final loop: end\r\n"); |
fdilenarda | 0:c25f7731ecc3 | 364 | mdm.powerOff(); |
fdilenarda | 0:c25f7731ecc3 | 365 | return 0; |
fdilenarda | 0:c25f7731ecc3 | 366 | } |