1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-12-24 11:21:24 +03:00

Added API to set static IP and DNS server

This commit is contained in:
Mimmo La Fauci
2013-03-21 09:24:07 +01:00
parent 9c30c73c2b
commit dc3102d2f4
13 changed files with 15997 additions and 15682 deletions

View File

@@ -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()
{

View File

@@ -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
*

View File

@@ -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,