a basic web server

This commit is contained in:
2019-07-31 19:42:53 +03:00
parent de36bbbd4b
commit 62e86aa4c2
7 changed files with 62 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ constexpr int i2cTimeout{10}, i2cTimeoutTries{10};
constexpr int lastStsTTL{10};
constexpr unsigned long powerTimeout{20000}, powerStartupDelay{100};
constexpr const char *defSSID{"eggbot"}, *defPass{"eggbotwi"};
constexpr const char *defSSID{"eggbot"}, *defPass{"eggbotwi"},
*defName{"eggbot"};
#endif // CONFIG_H

View File

@@ -2,5 +2,12 @@
#define GLOBALS_H
#include <Arduino.h>
#include <queue>
#include "LocalCommand.h"
#include "common/Commands.h"
extern std::queue<Command> commandQueue;
extern std::queue<LCommand> lCommandQueue;
#endif // GLOBALS_H

View File

@@ -0,0 +1,19 @@
#ifndef WEB_API_H
#define WEB_API_H
#include <Arduino.h>
#include <ESP8266WebServer.h>
class WebAPI {
private:
void handleNotFound();
public:
WebAPI();
void init();
void loopRoutine();
};
extern WebAPI webApi;
#endif // WEB_API_H

View File

@@ -4,7 +4,8 @@
#include "ConfigManager.h"
const std::unordered_map<std::string, std::string> defaults{
{{"wifiMode", "ap"},
{{"name", defName},
{"wifiMode", "ap"},
{"wifiSSID", defSSID},
{"wifiPass", defPass},
{"defRpm", "2"}}};

View File

@@ -1 +1,4 @@
#include "Globals.h"
std::queue<Command> commandQueue;
std::queue<LCommand> lCommandQueue;

View File

@@ -0,0 +1,18 @@
#include "WebAPI.h"
ESP8266WebServer server(80);
WebAPI::WebAPI() {}
void WebAPI::handleNotFound() {
server.send(404, "text/plain", "File Not Found\n\n");
}
void WebAPI::init() {
server.onNotFound(std::bind(&WebAPI::handleNotFound, this));
server.begin();
}
void WebAPI::loopRoutine() { server.handleClient(); }
WebAPI webApi;

View File

@@ -4,6 +4,9 @@
#include <Wire.h>
#include <queue>
#include <string>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include "ConfigManager.h"
#include "Executor.h"
#include "GCodeParser.h"
@@ -11,10 +14,9 @@
#include "LocalExecutor.h"
#include "Power.h"
#include "WiFiManager.h"
#include "WebAPI.h"
#include "common/Commands.h"
std::queue<Command> commandQueue;
std::queue<LCommand> lCommandQueue;
bool shouldPrintSts;
void setup() {
@@ -23,6 +25,9 @@ void setup() {
power.enable12v();
configManager.load();
wifiManager.init();
MDNS.begin(configManager.get("name").c_str());
webApi.init();
}
void printSts(Status status) {
@@ -89,4 +94,7 @@ void commandsLoop() {
void loop() {
serialLoop();
commandsLoop();
MDNS.update();
webApi.loopRoutine();
}