ESP8266NodeMCUInterface_HTTP
Dependencies: mbed mbed-rtos ESP8266NodeMCUInterface_HTTP
Dependents: ESP8266NodeMCUInterface_HTTP
main.cpp
00001 #include "mbed.h" 00002 #include "HTTPClient.h" 00003 #include "ESP8266Interface.h" 00004 #include "TCPSocketConnection.h" 00005 #include "Websocket.h" 00006 #include <string> 00007 00008 ESP8266Interface wifi(PC_10, PC_11, PC_13,9600); // TX,RX,Reset,Baud 00009 Serial pc(USBTX, USBRX); // tx, rx 00010 HTTPClient http; 00011 00012 const char* ssid = "IskonWLAN"; 00013 const char* pwd = "AB123456CD"; 00014 char str[512]; 00015 00016 int main() 00017 { 00018 pc.baud(9600); 00019 00020 pc.printf("\r\nIntializing hardware...\r\n"); 00021 if(wifi.init()) { 00022 pc.printf("Hardware intialized!\r\n"); 00023 pc.printf("\nTrying to connect to WiFi: %s...\r\n", ssid); 00024 00025 if(wifi.connect(ssid,pwd)) { 00026 pc.printf("WiFi: %s is connected!\r\n", ssid); 00027 00028 if(wifi.is_connected()) { 00029 pc.printf("IP Adress: %s\r\n",wifi.getIPAddress()); 00030 } 00031 else { 00032 pc.printf("No IP adress -> sonething went wrong with connection -> not connected \r\n"); 00033 } 00034 } 00035 else { 00036 pc.printf("Conenction fail!\r\n"); 00037 } 00038 } 00039 else { 00040 pc.printf("Hardware not intialized!\r\n"); 00041 } 00042 00043 wait(1); 00044 00045 00046 //GET 00047 // pc.printf("\nTrying to fetch page using GET...\n\r"); 00048 // int ret = http.get("http://54.175.222.246/get", str, 512);//IP address is httpbin.org/get 00049 // if (!ret) { 00050 // pc.printf("Page fetched successfully - read %d characters\n\r", strlen(str)); 00051 // pc.printf("Result: %s\n\r", str); 00052 // } else { 00053 // pc.printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode()); 00054 // } 00055 00056 00057 00058 //POST 00059 HTTPMap map; 00060 HTTPText inText(str, 512); 00061 map.put("Hello", "World"); 00062 map.put("test", "1234"); 00063 printf("\nTrying to POST data to httpbin.org/post...\n\r"); 00064 int ret = http.post("http://88.99.30.27/~slimelhr/TestPOST/post.php", map, &inText);//IP address is httpbin.org/post 00065 if (!ret) 00066 { 00067 printf("Executed POST successfully - read %d characters\n\r", strlen(str)); 00068 printf("Result: %s\n\r", str); 00069 } 00070 else 00071 { 00072 printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode()); 00073 } 00074 }
Generated on Thu Jul 28 2022 21:34:35 by 1.7.2