Made HAN Configuration access point into a library

This commit is contained in:
Vegar Westerlund 2019-06-09 23:21:32 +02:00
parent 711500a581
commit 4fb17239f0
7 changed files with 53 additions and 28 deletions

View File

@ -5,14 +5,14 @@
*/
#include <DallasTemperature.h>
#include <OneWire.h>
#include <ArduinoJson.h>
#include <DallasTemperature.h>
#include <MQTT.h>
#include <OneWire.h>
#include <ESP8266WiFi.h>
#include "HanConfigAp.h"
#include "HanReader.h"
#include "HanToJson.h"
#include "configuration.h"
#include "accesspoint.h"
#define WIFI_CONNECTION_TIMEOUT 30000;
#define TEMP_SENSOR_PIN 5 // Temperature sensor connected to GPIO5
@ -23,7 +23,7 @@ DallasTemperature tempSensor(&oneWire);
long lastTempDebug = 0;
// Object used to boot as Access Point
accesspoint ap;
HanConfigAp ap;
// WiFi client and MQTT client
WiFiClient *client;

View File

@ -0,0 +1,9 @@
name=HanConfigAp
version=1.0.0
author=roarfred
maintainer=roarfred <not@important.com>
sentence=HAN Configuraiton accesspoint
paragraph=HAN Configuraiton accesspoint
category=Sensors
url=https://github.com/roarfred/AmsToMqttBridge
architectures=*

View File

@ -1,17 +1,17 @@
//
//
//
#include "HanConfigAp.h"
#include "accesspoint.h"
#if defined(ESP8266)
ESP8266WebServer HanConfigAp::server(80);
#elif defined(ESP32) // ARDUINO_ARCH_ESP32
WebServer HanConfigAp::server(80);
#endif
Stream* HanConfigAp::debugger;
ESP8266WebServer accesspoint::server(80);
Stream* accesspoint::debugger;
bool accesspoint::hasConfig() {
bool HanConfigAp::hasConfig() {
return config.hasConfig();
}
void accesspoint::setup(int accessPointButtonPin, Stream* debugger)
void HanConfigAp::setup(int accessPointButtonPin, Stream* debugger)
{
this->debugger = debugger;
@ -71,7 +71,7 @@ void accesspoint::setup(int accessPointButtonPin, Stream* debugger)
}
}
bool accesspoint::loop() {
bool HanConfigAp::loop() {
if (isActivated)
{
//DNS
@ -87,7 +87,7 @@ bool accesspoint::loop() {
}
/** Handle root or redirect to captive portal */
void accesspoint::handleRoot() {
void HanConfigAp::handleRoot() {
println("Serving / over http...");
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
@ -102,7 +102,7 @@ void accesspoint::handleRoot() {
}
void accesspoint::handleSave() {
void HanConfigAp::handleSave() {
configuration *config = new configuration();
String temp;
@ -145,13 +145,17 @@ void accesspoint::handleSave() {
println("Saving configuration now...");
if (accesspoint::debugger) config->print(accesspoint::debugger);
if (HanConfigAp::debugger) config->print(HanConfigAp::debugger);
if (config->save())
{
println("Successfully saved. Will roboot now.");
String html = "<html><body><h1>Successfully Saved!</h1><h3>Device is restarting now...</h3></form>";
server.send(200, "text/html", html);
#if defined(ESP8266)
ESP.reset();
#elif defined(ESP32)
ESP.restart();
#endif
}
else
{
@ -161,19 +165,19 @@ void accesspoint::handleSave() {
}
}
size_t accesspoint::print(const char* text)
size_t HanConfigAp::print(const char* text)
{
if (debugger) debugger->print(text);
}
size_t accesspoint::println(const char* text)
size_t HanConfigAp::println(const char* text)
{
if (debugger) debugger->println(text);
}
size_t accesspoint::print(const Printable& data)
size_t HanConfigAp::print(const Printable& data)
{
if (debugger) debugger->print(data);
}
size_t accesspoint::println(const Printable& data)
size_t HanConfigAp::println(const Printable& data)
{
if (debugger) debugger->println(data);
}

View File

@ -9,12 +9,20 @@
#include "WProgram.h"
#endif
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ESP32) // ARDUINO_ARCH_ESP32
#include <WiFi.h>
#include <WebServer.h>
#else
#warning "Unsupported board type"
#endif
#include <DNSServer.h>
#include "configuration.h"
class accesspoint {
class HanConfigAp {
public:
void setup(int accessPointButtonPin, Stream* debugger);
bool loop();
@ -37,7 +45,11 @@ private:
// Web server
static void handleRoot();
static void handleSave();
#if defined(ESP8266)
static ESP8266WebServer server;
#elif defined(ESP32) // ARDUINO_ARCH_ESP32
static WebServer server;
#endif
static Stream* debugger;
};

View File

@ -1,9 +1,9 @@
name=HANtoJson
name=HanToJson
version=1.0.0
author=roarfred
maintainer=roarfred <not@important.com>
sentence=HAN support
paragraph=HAN support
sentence=HAN reader data to Json
paragraph=HAN reader data to Json
category=Sensors
url=https://github.com/roarfred/AmsToMqttBridge
architectures=*