An example program using NucleoL476RG with X-Nucleo-IDW01M1 wifi shield to sends analog data to Ubidots IoT Provider
Dependencies: NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of TLS_HelloWorld_IDW01M1 by
Complete tutorial at https://www.hackster.io/rreicher/nucleol476rg-to-ubidots-00d173
Revision 12:7b6b23225fd0, committed 2017-01-16
- Comitter:
- mapellil
- Date:
- Mon Jan 16 13:20:06 2017 +0000
- Parent:
- 11:0b4472769b08
- Child:
- 13:12401835892c
- Commit message:
- Removed unsecure socket connection (only secure socket connection with server authentication)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jan 13 15:31:35 2017 +0000
+++ b/main.cpp Mon Jan 16 13:20:06 2017 +0000
@@ -81,8 +81,8 @@
int err;
char * ssid = "STM";
char * seckey = "STMDemo";
-
- pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
+
+ pc.printf("\r\nTLS_HelloWorld mbed Application\r\n");
pc.printf("\r\nconnecting to AP\r\n");
if(spwf.connect(ssid, seckey, NSAPI_SECURITY_WPA2)) {
@@ -92,42 +92,8 @@
return -1;
}
- const char *ip = spwf.get_ip_address();
- const char *mac = spwf.get_mac_address();
-
- pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP");
- pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC");
-
- SocketAddress addr(&spwf, "st.com");
- pc.printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address());
-
- pc.printf("\r\nconnecting to http://4.ifcfg.me\r\n");
-
+// Start Secure Socket connection test (one way server autentication only)
TCPSocket socket(&spwf);
- err = socket.connect("4.ifcfg.me", 23);
- if(err!=0)
- {
- pc.printf("\r\nCould not connect to Socket, err = %d!!\r\n", err);
- return -1;
- } else pc.printf("\r\nconnected to host server\r\n");
-
- char buffer[100];
- int count = 0;
- pc.printf("\r\nReceiving Data\r\n");
- count = socket.recv(buffer, sizeof buffer);
-
- if(count > 0)
- {
- buffer [count]='\0';
- printf("%s\r\n", buffer);
- }
- else pc.printf("\r\nData not received\r\n");
-
- pc.printf("\r\nClosing Socket\r\n");
- socket.close();
- pc.printf("\r\nUnsecure Socket Test complete.\r\n");
-
-// Start Secure Socket connection test (one way server autentication only)
time_t ctTime;
ctTime = time(NULL);
printf ("Start Secure Socket connection with one way server autentication test\n\r");
@@ -146,6 +112,7 @@
// NOTE: the Wifi API set_secure_mode() and set_unsecure_mode() refers to the whole interface so the socket must be created / opened after
// having set the desidered mode (deft unsecure).
//#define SEC_MODE1 // two possible ways to secure connect a socket are shown
+ SocketAddress addr(&spwf, "");
spwf.gethostbyname(&addr,"www.mbed.com"); // ask DNS to resolve URL/IP
addr.set_port(443);
spwf.set_secure_mode();
