Firmware for an ad-hoc mesh network of Internet-of-Things devices based on LoRa (Long Range radio) that can be deployed quickly and cheaply.
DuckNet.h
Go to the documentation of this file.
1 
13 #ifndef DUCKNET_H_
14 #define DUCKNET_H_
15 
16 #include <WString.h>
17 #include "cdpcfg.h"
18 
19 #ifdef CDPCFG_WIFI_NONE
20 
21 #include "DuckLora.h"
22 #include "DuckUtils.h"
23 
24 #else
25 #include <ArduinoOTA.h>
26 #include <DNSServer.h>
27 #include <ESPAsyncWebServer.h>
28 #include <ESPmDNS.h>
29 #include <Update.h>
30 #include <WiFi.h>
31 #include <WiFiClientSecure.h>
32 #include <esp_int_wdt.h>
33 #include <esp_task_wdt.h>
34 
35 #include "../DuckError.h"
36 #include "DuckEsp.h"
37 #include "DuckLora.h"
38 #include "DuckUtils.h"
39 #include "OTAPage.h"
40 #include "index.h"
41 
42 #endif
43 
44 #define AP_SCAN_INTERVAL_MS 10
45 
51 class DuckNet {
52 public:
58  static DuckNet* getInstance();
59 
60 #ifdef CDPCFG_WIFI_NONE
61  void setupWebServer(bool createCaptivePortal = false, String html = "") {}
62  void setupWifiAp(const char* accessPoint = "🆘 DUCK EMERGENCY PORTAL") {}
63  int setupDns() {}
64  void setupInternet(String ssid, String password) {}
65  bool ssidAvailable(String val = "") {return false;}
66  void setSsid(String val) {}
67  void setPassword(String val) {}
68  String getSsid() {return "";}
69  String getPassword() {return "";}
70  void setDeviceId(String deviceId) {}
71  bool isWifiConnected() {return false;}
72 #else
73 
82  void setupWebServer(bool createCaptivePortal = false, String html = "");
83 
89  void setupWifiAp(const char* accessPoint = "🆘 DUCK EMERGENCY PORTAL");
90 
96  int setupDns();
97 
104  void setupInternet(String ssid, String password);
105 
112  bool ssidAvailable(String val = "");
113 
119  void setSsid(String val);
120 
126  void setPassword(String val);
127 
133  String getSsid();
134 
140  String getPassword();
141 
147  void setDeviceId(String deviceId);
148 
154  bool isWifiConnected() { return (WiFi.status() == WL_CONNECTED); }
155 
156  static DNSServer dnsServer;
157 #endif
158 
159 private :
160  DuckNet();
161  DuckNet(DuckNet const&) = delete;
162  DuckNet& operator=(DuckNet const&) = delete;
163  static DuckNet* instance;
164 
165  DuckLora* _duckLora;
166  String _deviceId;
167 
168  static const byte DNS_PORT;
169  static const char* DNS;
170  static const char* AP;
171  String portal = "";
172  String ssid = "";
173  String password = "";
174 };
175 
176 
177 #endif
DuckNet::getPassword
String getPassword()
Get the WiFi password ssid.
DuckNet::setDeviceId
void setDeviceId(String deviceId)
Set the Duck's device id.
DuckNet::setupWebServer
void setupWebServer(bool createCaptivePortal=false, String html="")
Set up the WebServer.
DuckNet::setupInternet
void setupInternet(String ssid, String password)
Set up internet access.
DuckLora
Internal LoRa chip abstraction.
Definition: DuckLora.h:58
DuckNet::dnsServer
static DNSServer dnsServer
Definition: DuckNet.h:156
index.h
DuckNet::getSsid
String getSsid()
Get the WiFi network ssid.
DuckNet::setSsid
void setSsid(String val)
Set the WiFi network ssid.
DuckNet::setupWifiAp
void setupWifiAp(const char *accessPoint="🆘 DUCK EMERGENCY PORTAL")
Set up the WiFi access point.
DuckNet::ssidAvailable
bool ssidAvailable(String val="")
Checks if the given ssid is available.
DuckLora.h
This file is internal to CDP and provides the library access to onboard LoRa module functions as well...
DuckUtils.h
This file is internal to CDP and provides some common utility methods.
DuckNet::isWifiConnected
bool isWifiConnected()
Provide Wifi connection status.
Definition: DuckNet.h:154
DuckNet
Internal network abstraction.
Definition: DuckNet.h:51
DuckNet::setupDns
int setupDns()
Set up DNS.
DuckNet::getInstance
static DuckNet * getInstance()
Get a singletom instance of the DuckNet class.
DuckNet::setPassword
void setPassword(String val)
Set the WiFi password.
OTAPage.h
DuckEsp.h
This file is internal to CDP and provides ESP32 specific implementations.
cdpcfg.h
CDP central compile-time configuration file.