X-NUCLEO-IDW01M1 Wi-Fi expansion board mbed OS 2 ("Classic") library. mbed OS 5 library also available (see below).
Dependencies: SPWF01SA
Dependents: SpwfInterface_NSAPI_Testsv2 Nucleo_read_a0_thingspace Nucleo_read_a0_thingspace_mems Cayenne-X-NUCLEO-IDW01M1 ... more
Fork of X_NUCLEO_IDW01M1v2 by
Introduction
X_NUCLEO_IDW01M1 is a mbed library for the Wi-Fi expansion board X-NUCLEO-IDW01M1 compatible with STM32 Nucleo.
The software can be used for building Wi-Fi applications with the SPWF01SA module. It is an implementation of the NetworkSocketAPI library from mbed OS 2 ("Classic").
mbed OS 5 library can instead be found at this link.
Firmware Library
The X_NUCLEO_IDW01M1 library comes with a sample application (HelloWorld_IDW01M1v2) and a NSAPI test suite application (SpwfInterface_NSAPI_Testsv2).
This library is only supported on NUCLEO platforms and any platforms with Arduino connector. However connection to arduino needs to be done manually using 4 wires for Vdd, Gnd, Rx and Tx. Example applications have more specific details on exact connections to be used.
The features of the library are :
- Supports mbed OS 2 ("Classic") NetworkSocketAPI
- Supports both client sockets
- Configuration of USART pins to be used
Class SpwfSAInterface is intended to represent the X-NUCLEO-IDW01M1 expansion board with the SPWF module.
The expansion board is basically featuring the component:
- a SPWF01SA Serial-to-Wi-Fi module
Example Applications
NSAPI Test Suite
Revision 14:4ec13009341c, committed 2017-01-02
- Comitter:
- mapellil
- Date:
- Mon Jan 02 14:50:17 2017 +0000
- Parent:
- 13:0368732b5b9d
- Child:
- 15:0a075334e0e9
- Commit message:
- Added TLS secure socket API; updated SPWF01SA library
Changed in this revision
--- a/SPWF01SA.lib Tue Nov 22 14:38:43 2016 +0000 +++ b/SPWF01SA.lib Mon Jan 02 14:50:17 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/SPWF01SA/#419285201dba +https://developer.mbed.org/teams/ST/code/SPWF01SA/#6b79352bc1fa
--- a/SpwfInterface.cpp Tue Nov 22 14:38:43 2016 +0000
+++ b/SpwfInterface.cpp Mon Jan 02 14:50:17 2017 +0000
@@ -49,6 +49,7 @@
int server_port;
nsapi_protocol_t proto;
bool connected;
+ bool secure;
};
@@ -67,7 +68,8 @@
{
memset(_ids, 0, sizeof(_ids));
isInitialized = false;
- isListening = false;
+ isListening = false;
+ isSecure = false;
}
SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, PinName reset, PinName wakeup, bool debug)
@@ -76,6 +78,7 @@
memset(_ids, 0, sizeof(_ids));
isInitialized = false;
isListening = false;
+ isSecure = false;
}
/**
@@ -154,6 +157,31 @@
return (_spwf.disconnect());
}
+/**
+* @brief set UTC time on wifi module
+* @param time since epoch in UTC format
+* @retval true on succes
+*/
+int SpwfSAInterface::set_time(time_t ctTime)
+{
+ return (_spwf.settime(ctTime));
+}
+
+int SpwfSAInterface::set_TLS_certificate(char *cert, unsigned int size, CertType_t type)
+{
+ return (_spwf.setTLScertificate(cert, size, type));
+}
+
+int SpwfSAInterface::set_TLS_SRV_domain(char *domain, CertType_t type)
+{
+ return (_spwf.setTLSSRVdomain(domain, type));
+}
+
+int SpwfSAInterface::clean_TLS_certificate(CertType_t type)
+{
+ return (_spwf.cleanTLScertificate(type));
+}
+
/**
* @brief Get the local IP address
* @param none
@@ -195,11 +223,43 @@
socket->server_port = id;
socket->proto = proto;
socket->connected = false;
+ if (isSecure_socket()) socket->secure = true;
+ else socket->secure = false;
*handle = socket;
return 0;
}
/**
+* @brief set secure mode for all the subsequently created sockets
+* @param none
+* @retval void
+*/
+void SpwfSAInterface::set_secure_sockets(void)
+{
+ isSecure = true;
+}
+
+/**
+* @brief set unsecure mode for all the subsequently created sockets
+* @param none
+* @retval void
+*/
+void SpwfSAInterface::set_unsecure_sockets(void)
+{
+ isSecure = false;
+}
+
+/**
+* @brief Return the interface security mode set
+* @param none
+* @retval true if secure
+*/
+bool SpwfSAInterface::isSecure_socket(void)
+{
+ return isSecure;
+}
+
+/**
* @brief connect to a remote socket
* @param handle: Pointer to socket handle
* addr: Address to connect to
@@ -207,12 +267,16 @@
*/
int SpwfSAInterface::socket_connect(void *handle, const SocketAddress &addr)
{
- int sock_id = 99;
+// int sock_id = 99;
+ int sock_id = -1;
+ const char* proto;
struct spwf_socket *socket = (struct spwf_socket *)handle;
-
- const char *proto = (socket->proto == NSAPI_UDP) ? "u" : "t";//"s" for secure socket?
+ if (socket->secure)
+ proto="s";
+ else
+ proto=(socket->proto == NSAPI_UDP) ? "u" : "t";
- if (!_spwf.open(proto, &sock_id, addr.get_ip_address(), addr.get_port())) {;//sock ID is allocated NOW
+ if (!_spwf.open(proto, &sock_id, addr.get_ip_address(), addr.get_port())) {//sock ID is allocated NOW
return NSAPI_ERROR_DEVICE_ERROR;
}
--- a/SpwfInterface.h Tue Nov 22 14:38:43 2016 +0000
+++ b/SpwfInterface.h Mon Jan 02 14:50:17 2017 +0000
@@ -42,6 +42,7 @@
#define SPWFSA_SOCKET_COUNT 8
#define SERVER_SOCKET_NO 9
+
/** SpwfSAInterface class
* Implementation of the NetworkStack for the SPWF Device
*/
@@ -56,9 +57,17 @@
virtual int connect(const char *ssid,
const char *pass,
nsapi_security_t security = NSAPI_SECURITY_NONE);
-
virtual int disconnect();
- virtual const char *get_mac_address();
+ virtual const char *get_mac_address();
+
+ // implementation of secure sockets
+ virtual void set_secure_sockets(void); // to be called before socket creation if TLS/SSL is required
+ virtual void set_unsecure_sockets(void); // to be called after socket creation to set unsecure mode (deft)
+ virtual bool isSecure_socket(void);
+ virtual int set_time(time_t ctTime); // TLS/SSL requires correct system time to check certificates
+ virtual int set_TLS_certificate(char * cert, unsigned int size, CertType_t type); // root cert in PEM format
+ virtual int set_TLS_SRV_domain(char * domain, CertType_t type); // secure server domain
+ virtual int clean_TLS_certificate(CertType_t type);
void debug(const char * string);
//Implementation of NetworkStack
@@ -87,6 +96,7 @@
bool _ids[SPWFSA_SOCKET_COUNT];
bool isListening;
bool isInitialized;
+ bool isSecure;
};

X-NUCLEO-IDW01M1 Wi-Fi expansion board