OmEspHelpers
OmOta.h
1 #include "OmEspHelpers.h"
2 
3 #ifndef __OmEta__
4 #define __OmEta__
5 
6 #ifdef ARDUINO_ARCH_ESP8266
7 #include <ESP8266WiFi.h>
8 #include <ESP8266WiFi.h>
9 #include <ESP8266mDNS.h>
10 #include <ESP8266WebServer.h>
11 #include <Updater.h>
12 #include "OmWebPages.h"
13 
14 #define _ESPWEBSERVER ESP8266WebServer
15 #endif
16 
17 #ifdef ARDUINO_ARCH_ESP32
18 #include <WiFi.h>
19 #include <ESPmDNS.h>
20 #include <WebServer.h>
21 #include <Update.h>
22 
23 #define _ESPWEBSERVER WebServer
24 #endif
25 
26 typedef enum
27 {
28  OSS_BEGIN = 0, // once at beginning
29  OSS_WIFI_CONNECTING, // while trying to connect
30  OSS_WIFI_FAIL, // if connection did fail. will keep calling this.
31  OSS_WIFI_SUCCESS, // once when connection established
32  OSS_IDLE, // called repeatedly while serving the Update web page
33  OSS_UPLOAD_START, // called once to begin upload, progress = bytes total
34  OSS_UPLOADING, // called repeatedly during upload, progress = bytes so far
35  OSS_UPLOADED, // called once when the upload is complete, progress = bytes got, reboot imminent
36 } EOtaSetupState;
37 
38 typedef void (* OtaStatusProc)(EOtaSetupState, unsigned int progress);
39 
40 void otaSetup(const char *ssid, const char *password, const char *bonjourName);
41 void otaSetStatusProc(OtaStatusProc statusProc);
42 void otaLoop(void) ;
43 
44 
46 {
47  private:
48  OmEeprom *ee = NULL; // the one you passed, or the one we create.
49  _ESPWEBSERVER *serverPtr = NULL;
50  OtaStatusProc statusProc = NULL;
51  bool otaMode = false;
52  char bonjourName[64];
53  bool rebootOnGet = false;
54 
55  void doProc(EOtaSetupState state, int progress);
56  EOtaSetupState lastState = OSS_BEGIN;
57 
58  public:
60  void addEeFields(OmEeprom &ee);
61 
63  bool setup(const char *wifiSsid, const char *wifiPassword, const char *wifiBonjour = NULL, OtaStatusProc statusProc = NULL);
64 
68  bool loop();
69 
73  void rebootToOta();
74 
78 
81  const char *getIpAddress();
82 };
83 
84 // magics into existence if you use it.
85 extern OmOtaClass OmOta;
86 
87 #endif // __OmEta__
OmOtaClass::addEeFields
void addEeFields(OmEeprom &ee)
Definition: OmOta.cpp:82
OmOtaClass::getIpAddress
const char * getIpAddress()
Definition: OmOta.cpp:309
OmOtaClass
Definition: OmOta.h:46
OmOtaClass::loop
bool loop()
Definition: OmOta.cpp:232
OmOtaClass::rebootToOta
void rebootToOta()
Definition: OmOta.cpp:267
OmWebPages
A class that routes and serves web pages, and manages control values, typically works with OmWebServe...
Definition: OmWebPages.h:122
OmEeprom
Wrapper for eeprom, lets you structure fields and check signature.
Definition: OmEeprom.h:32
OmOtaClass::addUpdateControl
void addUpdateControl(OmWebPages &p)
Definition: OmOta.cpp:282
OmOtaClass::setup
bool setup(const char *wifiSsid, const char *wifiPassword, const char *wifiBonjour=NULL, OtaStatusProc statusProc=NULL)
Definition: OmOta.cpp:88