mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge remote-tracking branch 'mlafauci/wifishield-bugfix' into HEAD
This commit is contained in:
@ -98,6 +98,31 @@ int WiFiClass::begin(char* ssid, const char *passphrase)
|
||||
return status;
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip)
|
||||
{
|
||||
WiFiDrv::config(1, (uint32_t)local_ip, 0, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip, IPAddress gateway)
|
||||
{
|
||||
WiFiDrv::config(2, (uint32_t)local_ip, (uint32_t)gateway, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
|
||||
{
|
||||
WiFiDrv::config(3, (uint32_t)local_ip, (uint32_t)gateway, (uint32_t)subnet);
|
||||
}
|
||||
|
||||
void WiFiClass::setDNS(IPAddress dns_server1)
|
||||
{
|
||||
WiFiDrv::setDNS(1, (uint32_t)dns_server1, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::setDNS(IPAddress dns_server1, IPAddress dns_server2)
|
||||
{
|
||||
WiFiDrv::setDNS(2, (uint32_t)dns_server1, (uint32_t)dns_server2);
|
||||
}
|
||||
|
||||
int WiFiClass::disconnect()
|
||||
{
|
||||
return WiFiDrv::disconnect();
|
||||
|
@ -59,6 +59,41 @@ public:
|
||||
*/
|
||||
int begin(char* ssid, const char *passphrase);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
*/
|
||||
void config(IPAddress local_ip);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
* param gateway : Static gateway configuration
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress gateway);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
* param gateway: Static gateway configuration
|
||||
* param subnet: Static Subnet mask
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
|
||||
|
||||
/* Change DNS Ip configuration
|
||||
*
|
||||
* param dns_server1: ip configuration for DNS server 1
|
||||
*/
|
||||
void setDNS(IPAddress dns_server1);
|
||||
|
||||
/* Change DNS Ip configuration
|
||||
*
|
||||
* param dns_server1: ip configuration for DNS server 1
|
||||
* param dns_server2: ip configuration for DNS server 2
|
||||
*
|
||||
*/
|
||||
void setDNS(IPAddress dns_server1, IPAddress dns_server2);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
|
@ -131,12 +131,11 @@ void WiFiClient::stop() {
|
||||
ServerDrv::stopClient(_sock);
|
||||
WiFiClass::_state[_sock] = NA_STATE;
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
int count = 0;
|
||||
// wait maximum 5 secs for the connection to close
|
||||
while (status() != CLOSED && ++count < 50)
|
||||
delay(100);
|
||||
|
||||
// wait a second for the connection to close
|
||||
while (status() != CLOSED && millis() - start < 1000)
|
||||
delay(1);
|
||||
_sock = 255;
|
||||
}
|
||||
|
||||
@ -150,7 +149,7 @@ uint8_t WiFiClient::connected() {
|
||||
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
|
||||
s == FIN_WAIT_2 || s == TIME_WAIT ||
|
||||
s == SYN_SENT || s== SYN_RCVD ||
|
||||
(s == CLOSE_WAIT && !available()));
|
||||
(s == CLOSE_WAIT));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,55 @@ int8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
void WiFiDrv::config(uint8_t validParams, uint32_t local_ip, uint32_t gateway, uint32_t subnet)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_IP_CONFIG_CMD, PARAM_NUMS_4);
|
||||
SpiDrv::sendParam((uint8_t*)&validParams, 1, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)&local_ip, 4, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)&gateway, 4, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)&subnet, 4, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(SET_IP_CONFIG_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
void WiFiDrv::setDNS(uint8_t validParams, uint32_t dns_server1, uint32_t dns_server2)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_DNS_CONFIG_CMD, PARAM_NUMS_3);
|
||||
SpiDrv::sendParam((uint8_t*)&validParams, 1, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)&dns_server1, 4, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)&dns_server2, 4, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(SET_DNS_CONFIG_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int8_t WiFiDrv::disconnect()
|
||||
{
|
||||
|
@ -90,6 +90,27 @@ public:
|
||||
*/
|
||||
static int8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
|
||||
|
||||
/* Set ip configuration disabling dhcp client
|
||||
*
|
||||
* param validParams: set the number of parameters that we want to change
|
||||
* i.e. validParams = 1 means that we'll change only ip address
|
||||
* validParams = 3 means that we'll change ip address, gateway and netmask
|
||||
* param local_ip: Static ip configuration
|
||||
* param gateway: Static gateway configuration
|
||||
* param subnet: Static subnet mask configuration
|
||||
*/
|
||||
static void config(uint8_t validParams, uint32_t local_ip, uint32_t gateway, uint32_t subnet);
|
||||
|
||||
/* Set DNS ip configuration
|
||||
*
|
||||
* param validParams: set the number of parameters that we want to change
|
||||
* i.e. validParams = 1 means that we'll change only dns_server1
|
||||
* validParams = 2 means that we'll change dns_server1 and dns_server2
|
||||
* param dns_server1: Static DNS server1 configuration
|
||||
* param dns_server2: Static DNS server2 configuration
|
||||
*/
|
||||
static void setDNS(uint8_t validParams, uint32_t dns_server1, uint32_t dns_server2);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
|
@ -27,6 +27,8 @@ enum {
|
||||
SET_PASSPHRASE_CMD = 0x11,
|
||||
SET_KEY_CMD = 0x12,
|
||||
TEST_CMD = 0x13,
|
||||
SET_IP_CONFIG_CMD = 0x14,
|
||||
SET_DNS_CONFIG_CMD = 0x15,
|
||||
|
||||
GET_CONN_STATUS_CMD = 0x20,
|
||||
GET_IPADDR_CMD = 0x21,
|
||||
|
Reference in New Issue
Block a user