This is Wi-Fi interface of WizFi310 for mbed os 5
Dependents: mbed-os-example-wifi
Diff: WizFi310Interface.cpp
- Revision:
- 1:8e468bb83e1e
- Parent:
- 0:d0e3f515f99d
--- a/WizFi310Interface.cpp Mon Dec 18 23:25:46 2017 +0000 +++ b/WizFi310Interface.cpp Tue Dec 19 16:59:33 2017 +0900 @@ -30,6 +30,10 @@ #ifndef WIZFI310_MISC_TIMEOUT #define WIZFI310_MISC_TIMEOUT 500 #endif +#ifndef WIZFI310_OPEN_CLOSE_TIMEOUT +#define WIZFI310_OPEN_CLOSE_TIMEOUT 10000 +#endif + #ifndef WIZFI310_DELAY_MS #define WIZFI310_DELAY_MS 300 #endif @@ -163,6 +167,21 @@ return _wizfi310.scan(res, count); } +nsapi_error_t WizFi310Interface::gethostbyname(const char *host, + SocketAddress *address, nsapi_version_t version) +{ + char host_ip[16]; + + if( !_wizfi310.dns_lookup(host,host_ip) ){ + return NSAPI_ERROR_DNS_FAILURE; + } + if ( !address->set_ip_address(host_ip) ){ + return NSAPI_ERROR_DNS_FAILURE; + } + + return NSAPI_ERROR_OK; +} + struct wizfi310_socket { int id; nsapi_protocol_t proto; @@ -173,13 +192,13 @@ int WizFi310Interface::socket_open(void **handle, nsapi_protocol_t proto) { - // Look for an unused socket + // Look for an unused socket int id = -1; for (int i=0; i<WIZFI310_SOCKET_COUNT; i++) { if (!_ids[i]){ id = i; - _ids[i] = true; + //_ids[i] = true; break; } } @@ -197,6 +216,7 @@ socket->proto = proto; socket->connected = false; *handle = socket; + return 0; } @@ -204,7 +224,7 @@ { struct wizfi310_socket *socket = (struct wizfi310_socket *)handle; int err = 0; - _wizfi310.setTimeout(WIZFI310_MISC_TIMEOUT); + _wizfi310.setTimeout(WIZFI310_OPEN_CLOSE_TIMEOUT); if (socket->connected && !_wizfi310.close(socket->id)) { err = NSAPI_ERROR_DEVICE_ERROR; @@ -229,7 +249,7 @@ int WizFi310Interface::socket_connect(void *handle, const SocketAddress &addr) { struct wizfi310_socket *socket = (struct wizfi310_socket *)handle; - _wizfi310.setTimeout(WIZFI310_MISC_TIMEOUT); + _wizfi310.setTimeout(WIZFI310_OPEN_CLOSE_TIMEOUT); const char *proto = (socket->proto == NSAPI_UDP) ? "UCN" : "TCN"; if (!_wizfi310.open(proto, socket->id, addr.get_ip_address(), addr.get_port())) { @@ -237,6 +257,7 @@ } socket->connected = true; + _ids[socket->id] = true; return 0; }