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.
Dependencies: ESP8266Interface HTTPClient-SSL WebSocketClient mbed-rtos mbed
Fork of ESP8266_HTTP_HelloWorld by
main.cpp@15:4b246689e0e2, 2015-06-05 (annotated)
- Committer:
- sarahmarshy
- Date:
- Fri Jun 05 21:10:48 2015 +0000
- Revision:
- 15:4b246689e0e2
- Parent:
- 14:1f0a842f8750
- Child:
- 16:e3d152c9f6e0
New demossid;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| michaeljkoster | 0:6a891da014a3 | 1 | #include "mbed.h" |
| sarahmarshy | 14:1f0a842f8750 | 2 | #include "HTTPClient.h" |
| michaeljkoster | 0:6a891da014a3 | 3 | #include "ESP8266Interface.h" |
| mbedAustin | 9:91fe783e1dd4 | 4 | #include "TCPSocketConnection.h" |
| sarahmarshy | 12:978788c2156c | 5 | #include "TCPSocketServer.h" |
| sarahmarshy | 12:978788c2156c | 6 | #include "Websocket.h" |
| sarahmarshy | 12:978788c2156c | 7 | |
| sarahmarshy | 15:4b246689e0e2 | 8 | ESP8266Interface wifi(D1,D0,D2,"demossid","",115200); // TX,RX,Reset,SSID,Password,Baud |
| mbedAustin | 7:d2c97b20d237 | 9 | RawSerial pc(USBTX, USBRX); // tx, rx |
| sarahmarshy | 14:1f0a842f8750 | 10 | HTTPClient http; |
| sarahmarshy | 14:1f0a842f8750 | 11 | char str[512]; |
| sarahmarshy | 14:1f0a842f8750 | 12 | int main() |
| sarahmarshy | 14:1f0a842f8750 | 13 | { |
| mbedAustin | 3:5175e53017e4 | 14 | pc.baud(115200); |
| sarahmarshy | 12:978788c2156c | 15 | wifi.init(); //Reset |
| sarahmarshy | 12:978788c2156c | 16 | wifi.connect(); //Use DHCP |
| mbedAustin | 7:d2c97b20d237 | 17 | |
| sarahmarshy | 14:1f0a842f8750 | 18 | //GET |
| sarahmarshy | 14:1f0a842f8750 | 19 | pc.printf("\nTrying to fetch page...\n"); |
| sarahmarshy | 14:1f0a842f8750 | 20 | int ret = http.get("http://191.239.57.70/", str, 128); |
| sarahmarshy | 14:1f0a842f8750 | 21 | if (!ret) { |
| sarahmarshy | 14:1f0a842f8750 | 22 | pc.printf("Page fetched successfully - read %d characters\n", strlen(str)); |
| sarahmarshy | 14:1f0a842f8750 | 23 | pc.printf("Result: %s\n", str); |
| sarahmarshy | 14:1f0a842f8750 | 24 | } else { |
| sarahmarshy | 14:1f0a842f8750 | 25 | pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
| sarahmarshy | 12:978788c2156c | 26 | } |
| sarahmarshy | 14:1f0a842f8750 | 27 | //POST |
| sarahmarshy | 14:1f0a842f8750 | 28 | HTTPMap map; |
| sarahmarshy | 14:1f0a842f8750 | 29 | HTTPText inText(str, 512); |
| sarahmarshy | 14:1f0a842f8750 | 30 | map.put("Hello", "World"); |
| sarahmarshy | 14:1f0a842f8750 | 31 | map.put("test", "1234"); |
| sarahmarshy | 14:1f0a842f8750 | 32 | printf("\nTrying to post data...\n"); |
| sarahmarshy | 14:1f0a842f8750 | 33 | ret = http.post("http://54.175.222.246/post", map, &inText); |
| sarahmarshy | 14:1f0a842f8750 | 34 | if (!ret) |
| sarahmarshy | 14:1f0a842f8750 | 35 | { |
| sarahmarshy | 14:1f0a842f8750 | 36 | printf("Executed POST successfully - read %d characters\n", strlen(str)); |
| sarahmarshy | 14:1f0a842f8750 | 37 | printf("Result: %s\n", str); |
| sarahmarshy | 14:1f0a842f8750 | 38 | } |
| sarahmarshy | 14:1f0a842f8750 | 39 | else |
| sarahmarshy | 14:1f0a842f8750 | 40 | { |
| sarahmarshy | 14:1f0a842f8750 | 41 | printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
| sarahmarshy | 14:1f0a842f8750 | 42 | } |
| sarahmarshy | 14:1f0a842f8750 | 43 | |
| mbedAustin | 9:91fe783e1dd4 | 44 | } |
| sarahmarshy | 14:1f0a842f8750 | 45 |
