forked from Akcelerometry_drgania_WMT/PI_mikrokontroler
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#ifndef NETWORK_H
|
|
#define NETWORK_H
|
|
|
|
#include "esp_log.h"
|
|
#include <Arduino.h>
|
|
#include <Config.h>
|
|
|
|
#ifdef ESP32
|
|
#include <WiFi.h>
|
|
#include <WebServer.h>
|
|
#include <ESPmDNS.h>
|
|
#include <DNSServer.h>
|
|
#elif defined(ESP8266)
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266mDNS.h>
|
|
#include <DNSServer.h>
|
|
#endif
|
|
//#include <Pinout.h>
|
|
//#include <IPAddress.h>
|
|
//#include <WiFiUdp.h>
|
|
|
|
//#include <WiFiClientSecureBearSSL.h>
|
|
|
|
// OTA
|
|
#include <HTTPUpdate.h>
|
|
#include <WiFiClientSecure.h>
|
|
#include <functional>
|
|
// OTA
|
|
|
|
class WiFiManager {
|
|
public:
|
|
WiFiManager();
|
|
void begin();
|
|
void connectToWiFi();
|
|
void setupAccessPoint(const char *newSSID, const char *newPassword);
|
|
void checkWiFiConnection();
|
|
void updateLED();
|
|
void setupMDNS();
|
|
void ReadConnection();
|
|
bool isConnected(); // Zwraca stan połączenia
|
|
bool convertCharToIPAddress(const char *str, IPAddress& ip);
|
|
void ledBlink(); // Z innego projektu - niepotrzebne, bo nie ma LED WiFi...
|
|
bool isWiFiOK(); // True, gdy WiFi połączone i false, gdy brak połączenia
|
|
int rssiToPercent(int rssi); // rssi na procenty
|
|
int8_t getRSSI();
|
|
|
|
void handleClient();
|
|
void startCaptivePortal();
|
|
void handleRoot();
|
|
void handleSave();
|
|
void handleNotFound();
|
|
|
|
/**
|
|
* Aktualizacja systemu przez internet z adresu config.updateUrl.
|
|
* @param allowInsecureTLS true => dla https wyłącz weryfikację certyfikatu.
|
|
* @param progressCb callback progress (opcjonalnie) (bytes, total).
|
|
* @return true, jeśli update zakończony sukcesem (urządzenie się zrestartuje).
|
|
*/
|
|
bool performOTAUpdate(bool allowInsecureTLS = true, std::function<void(int,int)> progressCb = nullptr);
|
|
|
|
int8_t rssi = 0;
|
|
bool useDHCP = true;
|
|
IPAddress local_IP;
|
|
IPAddress gateway;
|
|
IPAddress subnet;
|
|
IPAddress dns;
|
|
String ssidAP = "ACCEL666";
|
|
String passwordAP = "12345678";
|
|
|
|
private:
|
|
bool isAccessPoint = false;
|
|
bool captivePortalActive = false;
|
|
WebServer server{80};
|
|
DNSServer dnsServer;
|
|
int expectedCaptchaAnswer = 0;
|
|
};
|
|
|
|
#endif // WIFIMANAGER_H
|