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
Diff: SpwfInterface.cpp
- Revision:
- 13:0368732b5b9d
- Parent:
- 9:4cd89586b370
- Child:
- 14:4ec13009341c
diff -r 1f2aba8a1b00 -r 0368732b5b9d SpwfInterface.cpp
--- a/SpwfInterface.cpp Thu Nov 03 06:57:03 2016 +0000
+++ b/SpwfInterface.cpp Tue Nov 22 14:38:43 2016 +0000
@@ -62,13 +62,21 @@
* debug : not used
* @retval none
*/
-SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, bool debug)
- : _spwf(tx, rx, debug)
+SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, bool debug)
+ : _spwf(tx, rx, PC_12, PC_8, debug)
+{
+ memset(_ids, 0, sizeof(_ids));
+ isInitialized = false;
+ isListening = false;
+}
+
+SpwfSAInterface::SpwfSAInterface(PinName tx, PinName rx, PinName reset, PinName wakeup, bool debug)
+ : _spwf(tx, rx, reset, wakeup, debug)
{
memset(_ids, 0, sizeof(_ids));
isInitialized = false;
isListening = false;
-}
+}
/**
* @brief SpwfSAInterface destructor
@@ -87,7 +95,6 @@
*/
int SpwfSAInterface::init(void)
{
- _spwf.setTimeout(SPWF_MISC_TIMEOUT);
if(_spwf.startup(0)) {
isInitialized=true;
return true;
@@ -115,9 +122,7 @@
if(!init())
return NSAPI_ERROR_DEVICE_ERROR;
}
-
- _spwf.setTimeout(SPWF_CONNECT_TIMEOUT);
-
+
switch(security)
{
case NSAPI_SECURITY_NONE:
@@ -181,7 +186,7 @@
{
int id = -1;
- struct spwf_socket *socket = new struct spwf_socket;
+ struct spwf_socket *socket = new struct spwf_socket;
if (!socket) {
return NSAPI_ERROR_NO_SOCKET;
}
@@ -271,7 +276,6 @@
{
struct spwf_socket *socket = (struct spwf_socket *)handle;
int err = 0;
- _spwf.setTimeout(SPWF_MISC_TIMEOUT);
if(socket->id!=-1)
{
@@ -330,19 +334,16 @@
struct spwf_socket *socket = (struct spwf_socket *)handle;
int32_t recv;
- _spwf.setTimeout(SPWF_RECV_TIMEOUT);
-
//CHECK:Receive for both Client and Server Sockets same?
recv = _spwf.recv(socket->id, (char*)data, (uint32_t)size);
if (recv < 0) {
//wait_ms(1);//delay of 1ms <for F4>??
//printf(".");
if (recv == -1) return NSAPI_ERROR_WOULD_BLOCK;//send this if we want to block call (else timeout will happen)
- else return NSAPI_ERROR_DEVICE_ERROR;
+ else if (recv == -2)return NSAPI_ERROR_DEVICE_ERROR;
+ else if (recv == -3)return NSAPI_ERROR_NO_CONNECTION;
}
-
- return recv;
-
+ return recv;
}
/**
@@ -356,7 +357,7 @@
int SpwfSAInterface::socket_sendto(void *handle, const SocketAddress &addr, const void *data, unsigned size)
{
struct spwf_socket *socket = (struct spwf_socket *)handle;
- if (!socket->connected) {
+ if (!socket->connected) {
int err = socket_connect(socket, addr);
if (err < 0) {
return err;
@@ -402,3 +403,45 @@
{
//_spwf.debug_print(string);
}
+
+/**
+* @brief Set the socket options
+* Not used
+* @param handle: Pointer to handle
+* level: SOL_SOCKET
+* optname: option name
+* optval: pointer to option value
+* optlen: option length
+@retval NSAPI Error Type
+*/
+int SpwfSAInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
+{
+// struct spwf_socket *socket = (struct spwf_socket *)handle;
+
+ switch (optname) {
+ case NSAPI_REUSEADDR: /*!< Allow bind to reuse local addresses */
+ case NSAPI_KEEPALIVE: /*!< Enables sending of keepalive messages */
+ case NSAPI_LINGER: /*!< Keeps close from returning until queues empty */
+ case NSAPI_SNDBUF: /*!< Sets send buffer size */
+ case NSAPI_RCVBUF: /*!< Sets recv buffer size */
+ default:
+ printf("SpwfSAInterface::setsockopt> ERROR!!!! Unknown optname: %d \r\n", optname);
+ return -1;
+ }
+ return NSAPI_ERROR_UNSUPPORTED;
+}
+
+/**
+* @brief Get the socket options
+* Not used
+* @param handle: Pointer to handle
+* level: SOL_SOCKET
+* optname: option name
+* optval: pointer to option value
+* optlen: pointer to option length
+@retval NSAPI Error Type
+*/
+int SpwfSAInterface::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
+{
+ return NSAPI_ERROR_UNSUPPORTED;
+}

X-NUCLEO-IDW01M1 Wi-Fi expansion board