mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
parent
65d30437f0
commit
a8e3786d38
@ -16,6 +16,17 @@ extern "C"
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "LwipIntf.h"
|
#include "LwipIntf.h"
|
||||||
|
|
||||||
|
// wifi_station_hostname is SDK's station(=global) hostname location
|
||||||
|
// - It is never nullptr but wifi_station_get_hostname()
|
||||||
|
// can return nullptr when STA is down
|
||||||
|
// - Because WiFi is started in off mode at boot time,
|
||||||
|
// wifi_station_set/get_hostname() is now no more used
|
||||||
|
// because setting hostname firt does not work anymore
|
||||||
|
// - wifi_station_hostname is overwritten by SDK when wifi is
|
||||||
|
// woken up in WiFi::mode()
|
||||||
|
//
|
||||||
|
extern "C" char* wifi_station_hostname;
|
||||||
|
|
||||||
// args | esp order arduino order
|
// args | esp order arduino order
|
||||||
// ---- + --------- -------------
|
// ---- + --------- -------------
|
||||||
// local_ip | local_ip local_ip
|
// local_ip | local_ip local_ip
|
||||||
@ -66,7 +77,7 @@ bool LwipIntf::ipAddressReorder(const IPAddress& local_ip, const IPAddress& arg1
|
|||||||
*/
|
*/
|
||||||
String LwipIntf::hostname(void)
|
String LwipIntf::hostname(void)
|
||||||
{
|
{
|
||||||
return wifi_station_get_hostname();
|
return wifi_station_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,7 +86,7 @@ String LwipIntf::hostname(void)
|
|||||||
*/
|
*/
|
||||||
const char* LwipIntf::getHostname(void)
|
const char* LwipIntf::getHostname(void)
|
||||||
{
|
{
|
||||||
return wifi_station_get_hostname();
|
return wifi_station_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,12 +147,9 @@ bool LwipIntf::hostname(const char* aHostname)
|
|||||||
DEBUGV("hostname '%s' is not compliant with RFC952\n", aHostname);
|
DEBUGV("hostname '%s' is not compliant with RFC952\n", aHostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = wifi_station_set_hostname(aHostname);
|
bool ret = true;
|
||||||
if (!ret)
|
|
||||||
{
|
strcpy(wifi_station_hostname, aHostname);
|
||||||
DEBUGV("WiFi.hostname(%s): wifi_station_set_hostname() failed\n", aHostname);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we should inform dhcp server for this change, using lwip_renew()
|
// now we should inform dhcp server for this change, using lwip_renew()
|
||||||
// looping through all existing interface
|
// looping through all existing interface
|
||||||
@ -149,7 +157,7 @@ bool LwipIntf::hostname(const char* aHostname)
|
|||||||
for (netif* intf = netif_list; intf; intf = intf->next)
|
for (netif* intf = netif_list; intf; intf = intf->next)
|
||||||
{
|
{
|
||||||
// unconditionally update all known interfaces
|
// unconditionally update all known interfaces
|
||||||
intf->hostname = wifi_station_get_hostname();
|
intf->hostname = wifi_station_hostname;
|
||||||
|
|
||||||
if (netif_dhcp_data(intf) != nullptr)
|
if (netif_dhcp_data(intf) != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,9 @@ extern "C" {
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "include/WiFiState.h"
|
#include "include/WiFiState.h"
|
||||||
|
|
||||||
|
// see comments on wifi_station_hostname in LwipIntf.cpp
|
||||||
|
extern "C" char* wifi_station_hostname; // sdk's hostname location
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------------
|
||||||
// ------------------------------------------------- Generic WiFi function -----------------------------------------------
|
// ------------------------------------------------- Generic WiFi function -----------------------------------------------
|
||||||
// -----------------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------------
|
||||||
@ -419,7 +422,10 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char backup_hostname [33] { 0 }; // hostname is 32 chars long (RFC)
|
||||||
|
|
||||||
if (m != WIFI_OFF && wifi_fpm_get_sleep_type() != NONE_SLEEP_T) {
|
if (m != WIFI_OFF && wifi_fpm_get_sleep_type() != NONE_SLEEP_T) {
|
||||||
|
memcpy(backup_hostname, wifi_station_hostname, sizeof(backup_hostname));
|
||||||
// wifi starts asleep by default
|
// wifi starts asleep by default
|
||||||
wifi_fpm_do_wakeup();
|
wifi_fpm_do_wakeup();
|
||||||
wifi_fpm_close();
|
wifi_fpm_close();
|
||||||
@ -452,6 +458,9 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (backup_hostname[0])
|
||||||
|
memcpy(wifi_station_hostname, backup_hostname, sizeof(backup_hostname));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,10 +309,12 @@ extern "C"
|
|||||||
return wifi_station_get_config(config);
|
return wifi_station_get_config(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
char wifi_station_get_hostname_str[128];
|
extern "C" char* wifi_station_hostname; // exists in nonosdk
|
||||||
|
char wifi_station_hostname_str[33] { "esposix" };
|
||||||
|
char* wifi_station_hostname = wifi_station_hostname_str;
|
||||||
const char* wifi_station_get_hostname(void)
|
const char* wifi_station_get_hostname(void)
|
||||||
{
|
{
|
||||||
return strcpy(wifi_station_get_hostname_str, "esposix");
|
return wifi_station_hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wifi_station_get_reconnect_policy()
|
bool wifi_station_get_reconnect_policy()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user