Fix bind, remove hard coded ip
This commit is contained in:
parent
35045f0eab
commit
92593aa7a1
|
@ -131,7 +131,17 @@ socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_o
|
|||
bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t *self,
|
||||
const char *host, size_t hostlen, uint32_t port) {
|
||||
struct sockaddr_in bind_addr;
|
||||
bind_addr.sin_addr.s_addr = inet_addr(host);
|
||||
const char *broadcast = "<broadcast>";
|
||||
uint32_t ip;
|
||||
if (hostlen == 0) {
|
||||
ip = IPADDR_ANY;
|
||||
} else if (hostlen == strlen(broadcast) &&
|
||||
memcmp(host, broadcast, strlen(broadcast)) == 0) {
|
||||
ip = IPADDR_BROADCAST;
|
||||
} else {
|
||||
ip = inet_addr(host);
|
||||
}
|
||||
bind_addr.sin_addr.s_addr = ip;
|
||||
bind_addr.sin_family = AF_INET;
|
||||
bind_addr.sin_port = htons(port);
|
||||
|
||||
|
@ -141,7 +151,6 @@ bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t *self,
|
|||
mp_raise_RuntimeError(translate("Cannot set socket options"));
|
||||
}
|
||||
int result = lwip_bind(self->num, (struct sockaddr *)&bind_addr, sizeof(bind_addr));
|
||||
ESP_LOGE(TAG, "bind result %d", result);
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -220,11 +220,9 @@ void supervisor_start_web_workflow(void) {
|
|||
common_hal_socketpool_socket_settimeout(&listening, 0);
|
||||
// Bind to any ip.
|
||||
// TODO: Make this port .env configurable.
|
||||
const char *ip = "192.168.1.94";
|
||||
common_hal_socketpool_socket_bind(&listening, ip, strlen(ip), 80);
|
||||
common_hal_socketpool_socket_bind(&listening, "", 0, 80);
|
||||
common_hal_socketpool_socket_listen(&listening, 1);
|
||||
|
||||
|
||||
mp_int_t api_password_len = dotenv_get_key("/.env", "CIRCUITPY_WEB_API_PASSWORD", _api_password + 1, sizeof(_api_password) - 2);
|
||||
if (api_password_len > 0) {
|
||||
_api_password[0] = ':';
|
||||
|
|
Loading…
Reference in New Issue