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: HTTPClient NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of HTTPClient_HelloWorld_IDW01M1 by
main.cpp
00001 00002 #include "mbed.h" 00003 #include "TCPSocket.h" 00004 #include "HTTPClient.h" 00005 InterruptIn mybutton(USER_BUTTON); 00006 char str[30], str2[30]; 00007 DigitalOut myled(LED1); 00008 SpwfSAInterface spwf(D8, D2, PC_12, PC_8, false); 00009 HTTPClient http(spwf); 00010 int ret; 00011 int i=0,y=1,x=-1,h=0; 00012 bool connessione=false; 00013 // Funzione servita all'occorrenza dell'interrupt 00014 void premuto() 00015 { 00016 if (i==0) 00017 { 00018 connessione=true; 00019 h=1; 00020 } 00021 else 00022 { 00023 connessione=false; 00024 h=2; 00025 } 00026 i=i+y; 00027 y=y*x; 00028 } 00029 int main() 00030 { 00031 // Assegna all'interrupt la funzione premuto 00032 mybutton.fall(&premuto); 00033 while(1) 00034 { 00035 if (h==1) 00036 { 00037 //CONNESSIONE ALL'ACCESS POINT 00038 printf("\n\r"); 00039 printf("Connessione all'Access Point\n\r"); 00040 spwf.connect("eliappsk","Pluto2018", NSAPI_SECURITY_WPA2); 00041 const char *ip = spwf.get_ip_address(); 00042 printf("Indirizzo IP: %s\n\r", ip); 00043 h=0; 00044 } 00045 if (h==2) 00046 { 00047 printf("\n\r"); 00048 spwf.disconnect(); 00049 printf ("WIFI Disconnesso\n\r"); 00050 h=0; 00051 } 00052 if (i==1) 00053 { 00054 //LETTURA DEI DATI 00055 printf("\n\r"); 00056 printf("Lettura Dati...\n\r"); 00057 ret = http.get("http://www.itirenatoelia.gov.it/allegati/hello4.html", str, 30, HTTP_CLIENT_DEFAULT_TIMEOUT); 00058 if (!ret) 00059 { 00060 printf("Dati Letti Con Successo - Letti %d Caratteri\n\r", strlen(str)); 00061 printf("Risultato: %s\n\r", str); 00062 } 00063 else 00064 { 00065 printf("Errore - ret = %d - Codice Errore HTTP = %d\n\r", ret, http.getHTTPResponseCode()); 00066 } 00067 00068 //POSTARE I DATI 00069 myled=!myled; 00070 strcpy(str2,str); 00071 HTTPMap map; 00072 HTTPText inText(str, 30); 00073 map.put("nome",str); 00074 printf("\n\r"); 00075 printf("Invio Dati...\n\r"); 00076 ret = http.post("http://www.itirenatoelia.gov.it/allegati/scrivi.php", map, &inText, HTTP_CLIENT_DEFAULT_TIMEOUT); 00077 if (!ret) 00078 { 00079 printf("Dati Inviati Con Successo - Scritti %d Caratteri\n\r", strlen(str2)); 00080 printf("Risultato: %s\n\r", str2); 00081 00082 } 00083 else 00084 { 00085 printf("Errore - ret = %d - Codice Errore HTTP = %d\n\r", ret, http.getHTTPResponseCode()); 00086 } 00087 myled=!myled; 00088 } 00089 wait(5); 00090 } 00091 }
Generated on Wed Jul 20 2022 01:14:31 by
1.7.2
