OmEspHelpers
OmOta.h
1 #include "OmEspHelpers.h"
2 
3 #ifndef NOT_ARDUINO
4 
5 #ifndef __OmEta__
6 #define __OmEta__
7 
8 #ifdef ARDUINO_ARCH_ESP8266
9 #include <ESP8266WiFi.h>
10 #include <ESP8266WiFi.h>
11 #include <ESP8266mDNS.h>
12 #include <ESP8266WebServer.h>
13 #include <Updater.h>
14 #include "OmWebPages.h"
15 #include "OmWebServer.h"
16 
17 #define _ESPWEBSERVER ESP8266WebServer
18 #endif
19 
20 #ifdef ARDUINO_ARCH_ESP32
21 #include <WiFi.h>
22 #include <ESPmDNS.h>
23 #include <WebServer.h>
24 #include <Update.h>
25 
26 #define _ESPWEBSERVER WebServer
27 #endif
28 
29 typedef enum
30 {
31  OSS_BEGIN = 0, // once at beginning
32  OSS_WIFI_CONNECTING, // while trying to connect
33  OSS_WIFI_FAIL, // if connection did fail. will keep calling this.
34  OSS_WIFI_SUCCESS, // once when connection established
35  OSS_IDLE, // called repeatedly while serving the Update web page
36  OSS_UPLOAD_START, // called once to begin upload, progress = bytes total
37  OSS_UPLOADING, // called repeatedly during upload, progress = bytes so far
38  OSS_UPLOADED, // called once when the upload is complete, progress = bytes got, reboot imminent
39 } EOtaSetupState;
40 
41 typedef void (* OtaStatusProc)(EOtaSetupState, unsigned int progress);
42 
43 void otaSetup(const char *ssid, const char *password, const char *bonjourName);
44 void otaSetStatusProc(OtaStatusProc statusProc);
45 void otaLoop(void) ;
46 
47 
49 {
50  private:
51  _ESPWEBSERVER *serverPtr = NULL;
52  OtaStatusProc statusProc = NULL;
53  bool otaMode = false;
54  char bonjourName[64];
55  bool rebootOnGet = false;
56 
57  void doProc(EOtaSetupState state, int progress);
58  bool doAWiFiTry(String ssid, String password, int &wifiDots);
59  EOtaSetupState lastState = OSS_BEGIN;
60 
61  String ssidActuallyConnected;
62  long long otaStarted = 0;
63 
64  public:
65  const char *defaultSignature = "OmOta_xyzzy"; // can manually reassign before use...
66 
67 #define OOC_STRING_LEN 20
68  // you can just read these.
69  char otaBonjourName[OOC_STRING_LEN];
70  char otaWifiSsid[OOC_STRING_LEN];
71  char otaWifiPassword[OOC_STRING_LEN];
72 
73  void addEeFields();
74 
78  bool setup(const char *wifiSsid, const char *wifiPassword, const char *wifiBonjour = NULL, OtaStatusProc statusProc = NULL);
79 
82  bool setup(OtaStatusProc statusProc = NULL);
83 
84 
88  bool loop();
89 
93  void rebootToOta();
94 
97  void addUpdateControl();
98 
101  const char *getIpAddress();
102 
105  void addWifiConfigForm();
106 
108  void retrieveWifiConfig();
109 };
110 
111 // magics into existence if you use it.
112 extern OmOtaClass OmOta;
113 
114 #endif // __OmEta__
115 
116 #endif
OmOtaClass::getIpAddress
const char * getIpAddress()
Definition: OmOta.cpp:445
OmOtaClass::addWifiConfigForm
void addWifiConfigForm()
Definition: OmOta.cpp:436
OmOtaClass::addUpdateControl
void addUpdateControl()
Definition: OmOta.cpp:387
OmOtaClass
Definition: OmOta.h:49
OmOtaClass::retrieveWifiConfig
void retrieveWifiConfig()
Definition: OmOta.cpp:418
OmOtaClass::loop
bool loop()
Definition: OmOta.cpp:325
OmOtaClass::rebootToOta
void rebootToOta()
Definition: OmOta.cpp:371
OmOtaClass::setup
bool setup(const char *wifiSsid, const char *wifiPassword, const char *wifiBonjour=NULL, OtaStatusProc statusProc=NULL)
Definition: OmOta.cpp:151