Merge pull request #1492 from openmv/nina_driver_updates

Nina WiFi driver fixes.
This commit is contained in:
Ibrahim Abd Elkader 2022-01-05 18:56:39 +02:00 committed by GitHub
commit fb71aa33ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -477,16 +477,17 @@ int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set) {
ARG_BYTE(3), // Valid number of args.
{ip_len, ifconfig->ip_addr},
{gw_len, ifconfig->gateway_addr},
{sub_len, ifconfig->subnet_addr})) != SPI_ACK) {
{sub_len, ifconfig->subnet_addr})) != 0) {
return -1;
}
uint8_t dns2[4] = {8, 8, 8, 8};
if (nina_send_command_read_ack(NINA_CMD_SET_DNS_CONFIG,
3, ARG_8BITS,
NINA_ARGS(
ARG_BYTE(1), // Valid number of args.
{dns_len, ifconfig->dns_addr},
{dns_len, ifconfig->dns_addr})) != SPI_ACK) {
{dns_len, dns2})) != SPI_ACK) {
return -1;
}

View File

@ -149,6 +149,11 @@ static mp_obj_t py_nina_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_m
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!"));
}
// Disconnect active connections first.
if (nina_isconnected()) {
nina_disconnect();
}
if (self->itf == NINA_WIFI_MODE_STA) {
// Initialize WiFi in Station mode.
if (nina_connect(ssid, security, key, 0) != 0) {
@ -425,7 +430,7 @@ static mp_uint_t py_nina_socket_send(mod_network_socket_obj_t *socket, const byt
if (ret == NINA_ERROR_TIMEOUT) {
// The socket is Not closed on timeout when calling functions that accept a timeout.
*_errno = MP_ETIMEDOUT;
return 0;
return -1;
} else if (ret < 0) {
// Close the socket on any other errors.
*_errno = ret;
@ -441,7 +446,7 @@ static mp_uint_t py_nina_socket_recv(mod_network_socket_obj_t *socket, byte *buf
if (ret == NINA_ERROR_TIMEOUT) {
// The socket is Not closed on timeout when calling functions that accept a timeout.
*_errno = MP_ETIMEDOUT;
return 0;
return -1;
} else if (ret < 0) {
// Close the socket on any other errors.
*_errno = ret;
@ -475,7 +480,7 @@ static mp_uint_t py_nina_socket_sendto(mod_network_socket_obj_t *socket,
if (ret == NINA_ERROR_TIMEOUT) {
// The socket is Not closed on timeout when calling functions that accept a timeout.
*_errno = MP_ETIMEDOUT;
return 0;
return -1;
} else if (ret < 0) {
*_errno = ret;
py_nina_socket_close(socket);
@ -496,7 +501,7 @@ static mp_uint_t py_nina_socket_recvfrom(mod_network_socket_obj_t *socket,
if (ret == NINA_ERROR_TIMEOUT) {
// The socket is Not closed on timeout when calling functions that accept a timeout.
*_errno = MP_ETIMEDOUT;
return 0;
return -1;
} else if (ret < 0) {
// Close the socket on any other errors.
*_errno = ret;