-
Notifications
You must be signed in to change notification settings - Fork 24
Driver compatible with 2.0 Espressif firmware #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,13 @@ class ESP8266 | |
* see @a nsapi_error | ||
*/ | ||
int scan(WiFiAccessPoint *res, unsigned limit); | ||
/**Perform a dns query | ||
* | ||
* @param name Hostname to resolve | ||
* @param ip Buffer to store IP address | ||
* @return 0 true on success, false on failure | ||
*/ | ||
bool dns_lookup(const char* name, char* ip); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: pointers side with names: bool dns_lookup(const char *name, char *ip); |
||
|
||
/** | ||
* Open a socketed connection | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,30 @@ int ESP8266Interface::connect() | |
return NSAPI_ERROR_OK; | ||
} | ||
|
||
nsapi_error_t ESP8266Interface::gethostbyname(const char* name, SocketAddress *address, nsapi_version_t version) | ||
{ | ||
if (address->set_ip_address(name)) { | ||
if (version != NSAPI_UNSPEC && address->get_ip_version() != version) { | ||
return NSAPI_ERROR_DNS_FAILURE; | ||
} | ||
|
||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
char* ipbuff = (char*)malloc(256); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a string representation of an IP address? We have a define for the max size you should use (NSAPI_IP_SIZE). Also you should either check for out of memory (malloc returns NULL) or use |
||
int ret = 0; | ||
|
||
if(!_esp.dns_lookup(name, ipbuff)) | ||
{ | ||
ret = NSAPI_ERROR_DEVICE_ERROR; | ||
} | ||
else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: spaces after ifs, brackets on same line as conditionals: if (!_esp.dns_lookup(name, ipbuff)) {
ret = NSAPI_ERROR_DEVICE_ERROR;
} else {
address->set_ip_address(ipbuff);
} |
||
address->set_ip_address(ipbuff); | ||
} | ||
free(ipbuff); | ||
return ret; | ||
} | ||
|
||
int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security) | ||
{ | ||
memset(ap_ssid, 0, sizeof(ap_ssid)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,21 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface | |
*/ | ||
virtual int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, | ||
uint8_t channel = 0); | ||
|
||
|
||
/** Translates a hostname to an IP address with specific version | ||
* | ||
* The hostname may be either a domain name or an IP address. If the | ||
* hostname is an IP address, no network transactions will be performed. | ||
* | ||
* | ||
* @param host Hostname to resolve | ||
* @param address Destination for the host SocketAddress | ||
* @param version IP version of address to resolve, NSAPI_UNSPEC indicates | ||
* version is chosen by the stack (defaults to NSAPI_UNSPEC) | ||
* @return 0 on success, negative error code on failure | ||
*/ | ||
virtual nsapi_error_t gethostbyname(const char* name, SocketAddress *address, nsapi_version_t version); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for conforming to the dox-style 👍 |
||
|
||
/** Set the WiFi network credentials | ||
* | ||
* @param ssid Name of the network to connect to | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: newline above?