emw312 driver
Fork of emw3162-driver by
Revision 4:2ab7d68a654c, committed 2017-01-12
- Comitter:
- sarahmarshy
- Date:
- Thu Jan 12 17:21:34 2017 -0600
- Parent:
- 3:0f0c97fee74d
- Commit message:
- Updated to mbed-os
Changed in this revision
EMW3162Interface.cpp | Show annotated file Show diff for this revision Revisions of this file |
EMW3162Interface.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/EMW3162Interface.cpp Thu Jan 12 22:40:59 2017 +0000 +++ b/EMW3162Interface.cpp Thu Jan 12 17:21:34 2017 -0600 @@ -34,10 +34,7 @@ _esp.attach(this, &EMW3162Interface::event); } -int EMW3162Interface::connect( - const char *ssid, - const char *pass, - nsapi_security_t security) +int EMW3162Interface::connect() { _esp.setTimeout(EMW3162_CONNECT_TIMEOUT); @@ -49,7 +46,7 @@ return NSAPI_ERROR_DHCP_FAILURE; } - if (!_esp.connect(ssid, pass)) { + if (!_esp.connect(ap_ssid, ap_pass)) { return NSAPI_ERROR_NO_CONNECTION; } @@ -60,6 +57,35 @@ return 0; } +int EMW3162Interface::connect(const char *ssid, const char *pass, nsapi_security_t security, + uint8_t channel) +{ + if (channel != 0) { + return NSAPI_ERROR_UNSUPPORTED; + } + + set_credentials(ssid, pass, security); + return connect(); +} + +int EMW3162Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security) +{ + memset(ap_ssid, 0, sizeof(ap_ssid)); + strncpy(ap_ssid, ssid, sizeof(ap_ssid)); + + memset(ap_pass, 0, sizeof(ap_pass)); + strncpy(ap_pass, pass, sizeof(ap_pass)); + + ap_sec = security; + + return 0; +} + +int EMW3162Interface::set_channel(uint8_t channel) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + int EMW3162Interface::disconnect() { _esp.setTimeout(EMW3162_MISC_TIMEOUT); @@ -81,6 +107,15 @@ return _esp.getMACAddress(); } +int EMW3162Interface::scan(WiFiAccessPoint *res, unsigned count){ + return NSAPI_ERROR_UNSUPPORTED; +} + +int8_t EMW3162Interface::get_rssi() +{ + return NSAPI_ERROR_UNSUPPORTED; +} + struct EMW3162_socket { int id; int socketId; @@ -158,7 +193,7 @@ return 0; } -int EMW3162Interface::socket_accept(void **handle, void *server) +int EMW3162Interface::socket_accept(void *handle, void **socket, SocketAddress *address) { return NSAPI_ERROR_UNSUPPORTED; }
--- a/EMW3162Interface.h Thu Jan 12 22:40:59 2017 +0000 +++ b/EMW3162Interface.h Thu Jan 12 17:21:34 2017 -0600 @@ -45,10 +45,36 @@ * @param security Type of encryption for connection * @return 0 on success, negative error code on failure */ - virtual int connect( - const char *ssid, - const char *pass, - nsapi_security_t security = NSAPI_SECURITY_NONE); + virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, + uint8_t channel = 0); + + /** Start the interface + * + * Attempts to connect to a WiFi network. Requires ssid and passphrase to be set. + * If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned. + * + * @return 0 on success, negative error code on failure + */ + virtual int connect(); + + /** Set the WiFi network credentials + * + * @param ssid Name of the network to connect to + * @param pass Security passphrase to connect to the network + * @param security Type of encryption for connection + * (defaults to NSAPI_SECURITY_NONE) + * @return 0 on success, or error code on failure + */ + virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE); + + /** Set the WiFi network channel - NOT SUPPORTED + * + * This function is not supported and will return NSAPI_ERROR_UNSUPPORTED + * + * @param channel Channel on which the connection is to be made, or 0 for any (Default: 0) + * @return Not supported, returns NSAPI_ERROR_UNSUPPORTED + */ + virtual int set_channel(uint8_t channel); /** Stop the interface * @return 0 on success, negative on failure @@ -64,6 +90,24 @@ * @return MAC address of the interface */ virtual const char *get_mac_address(); + + /** Gets the current radio signal strength for active connection + * + * @return Connection strength in dBm (negative value) + */ + virtual int8_t get_rssi(); + + /** Scan for available networks + * + * This function will block. + * + * @param ap Pointer to allocated array to store discovered AP + * @param count Size of allocated @a res array, or 0 to only count available AP + * @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0) + * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error + * see @a nsapi_error + */ + virtual int scan(WiFiAccessPoint *res, unsigned count); protected: /** Open a socket @@ -110,7 +154,7 @@ * @note This call is not-blocking, if this call would block, must * immediately return NSAPI_ERROR_WOULD_WAIT */ - virtual int socket_accept(void **handle, void *server); + virtual int socket_accept(void *handle, void **socket, SocketAddress *address); /** Send data to the remote host * @param handle Socket handle @@ -176,7 +220,9 @@ private: EMW3162 _esp; bool _ids[EMW3162_SOCKET_COUNT]; - + char ap_ssid[33]; + char ap_pass[64]; + nsapi_security_t ap_sec; void event(); struct { void (*callback)(void *);