esp8266_web_settings beta
WifiSetup.h
1/*
2 * Copyright (c) 2021, 2022 G. R. McDorman
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#pragma once
24
25#include "grmcdorman/device/Device.h"
26
27#include <DNSServer.h>
28
29namespace grmcdorman::device
30{
48 class WifiSetup: public Device
49 {
50 public:
51 WifiSetup();
52
58 void set_defaults() override;
59 void setup() override;
60 void loop() override;
61 bool publish(DynamicJsonDocument &json) const override;
62 DynamicJsonDocument as_json() const override;
70 const String &get_configured_local_hostname() const
71 {
72 return hostname.get();
73 }
82 bool get_is_published() const override
83 {
84 return false;
85 }
86 private:
87 void connect_to_ap();
88 StringSetting hostname;
89 StringSetting ssid;
90 PasswordSetting password;
91 ToggleSetting use_dhcp;
92 StringSetting ip_address;
93 StringSetting subnet_mask;
94 StringSetting default_gateway;
95 ToggleSetting auto_dns;
96 StringSetting dns_1;
97 StringSetting dns_2;
98 UnsignedIntegerSetting connection_timeout;
99 ToggleSetting publish_rssi;
100
101 bool tried_connect_on_setup = false;
102
103 std::unique_ptr<DNSServer> dns_server;
104 };
105}
The generic device interface.
Definition: Device.h:46
This "device" supports WiFi configuration.
Definition: WifiSetup.h:49
void loop() override
Main loop.
Definition: WifiSetup.cpp:206
bool publish(DynamicJsonDocument &json) const override
Publish the value and attributes.
Definition: WifiSetup.cpp:226
bool get_is_published() const override
Get whether the device readings have been published.
Definition: WifiSetup.h:82
const String & get_configured_local_hostname() const
Get the local host name.
Definition: WifiSetup.h:70
void set_defaults() override
Set defaults.
Definition: WifiSetup.cpp:94
DynamicJsonDocument as_json() const override
Get the values, as a JSON document.
Definition: WifiSetup.cpp:239
void setup() override
Setup the device.
Definition: WifiSetup.cpp:99