Initial tests DNS

master
Martin Ger 2018-06-22 12:51:04 +02:00
rodzic b9f3656c09
commit c71a6d1f07
5 zmienionych plików z 57 dodań i 0 usunięć

Wyświetl plik

@ -176,6 +176,10 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
os_sprintf_flash(response, "time\r\nset [ntp_server|ntp_interval|ntp_timezone|ntp_time|ntp_weekday] <val>\r\n");
to_console(response);
#endif
#ifdef DNS_RESP
os_sprintf_flash(response, "set dns_name <name>\r\n");
to_console(response);
#endif
#ifdef MQTT_CLIENT
os_sprintf_flash(response, "set [mqtt_host|mqtt_port|mqtt_ssl|mqtt_user|mqtt_password|mqtt_id] <val>\r\n");
to_console(response);
@ -213,6 +217,12 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
// if static DNS, add it
os_sprintf(response, config.dns_addr.addr ? "DNS: %d.%d.%d.%d\r\n" : "", IP2STR(&config.dns_addr));
to_console(response);
#ifdef DNS_RESP
if (strcmp(config.broker_dns_name, "none")!=0 && config.ap_on) {
os_sprintf(response, "DNS name: %s\r\n", config.broker_dns_name);
to_console(response);
}
#endif
#ifdef MDNS
if (config.mdns_mode) {
os_sprintf(response, "mDNS: %s interface\r\n", config.mdns_mode==1 ? "STA": "SoftAP");
@ -1026,6 +1036,14 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
goto command_handled;
}
#endif
#ifdef DNS_RESP
if (strcmp(tokens[1], "dns_name") == 0) {
os_strncpy(config.broker_dns_name, tokens[2], 32);
config.mqtt_host[31] = 0;
os_sprintf_flash(response, "DNS name set\r\n");
goto command_handled;
}
#endif
#ifdef MQTT_CLIENT
if (strcmp(tokens[1], "mqtt_host") == 0) {
os_strncpy(config.mqtt_host, tokens[2], 32);

Wyświetl plik

@ -63,6 +63,9 @@ void ICACHE_FLASH_ATTR config_load_default(sysconfig_p config) {
config->ntp_interval = 300000000;
config->ntp_timezone = 0;
#endif
#ifdef DNS_RESP
os_sprintf(config->broker_dns_name, "%s", "none");
#endif
#ifdef GPIO
#ifdef GPIO_PWM
config->pwm_period = 5000;

Wyświetl plik

@ -81,6 +81,9 @@ typedef struct
uint32_t ntp_interval; // Sync interval in usec
int16_t ntp_timezone; // Timezone (hour offset to GMT)
#endif
#ifdef DNS_RESP
uint8_t broker_dns_name[32]; // DNS name of the MQTT broker in the SoftAP network, "none" if empty
#endif
#ifdef GPIO
#ifdef GPIO_PWM
uint32_t pwm_period; // PWM period

Wyświetl plik

@ -88,6 +88,12 @@
//
#define MDNS 1
//
// Define this if you want to have access the DNS responder.
// Experimental feature - not yet tested
//
//#define DNS_RESP 1
//
// Define this to support the "scan" command for AP search
//

Wyświetl plik

@ -26,6 +26,10 @@ uint64_t t_ntp_resync = 0;
static struct mdns_info mdnsinfo;
#endif
#ifdef DNS_RESP
#include "dns_responder.h"
#endif
#ifdef SCRIPTED
#include "lang.h"
#include "pub_list.h"
@ -752,6 +756,24 @@ void ICACHE_FLASH_ATTR mqtt_got_retained(retained_entry *topic) {
}
#ifdef DNS_RESP
int ICACHE_FLASH_ATTR get_A_Record(uint8_t addr[4], const char domain_name[])
{
if (strcmp(config.broker_dns_name, domain_name) == 0) {
*(uint32_t*)addr = config.network_addr.addr;
return 0;
} else {
return -1;
}
}
int ICACHE_FLASH_ATTR get_AAAA_Record(uint8_t addr[16], const char domain_name[])
{
return -1;
}
#endif
void user_init() {
struct ip_info info;
@ -843,6 +865,11 @@ void user_init() {
wifi_set_opmode(STATIONAP_MODE);
user_set_softap_wifi_config();
do_ip_config = true;
#ifdef DNS_RESP
if (strcmp(config.broker_dns_name, "none")!=0) {
dns_resp_init(DNS_MODE_AP);
}
#endif
} else {
wifi_set_opmode(STATION_MODE);
}