mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
a basic web server
This commit is contained in:
@@ -6,6 +6,7 @@ constexpr int i2cTimeout{10}, i2cTimeoutTries{10};
|
|||||||
constexpr int lastStsTTL{10};
|
constexpr int lastStsTTL{10};
|
||||||
constexpr unsigned long powerTimeout{20000}, powerStartupDelay{100};
|
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
|
#endif // CONFIG_H
|
||||||
@@ -2,5 +2,12 @@
|
|||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
#endif // GLOBALS_H
|
#include "LocalCommand.h"
|
||||||
|
#include "common/Commands.h"
|
||||||
|
|
||||||
|
extern std::queue<Command> commandQueue;
|
||||||
|
extern std::queue<LCommand> lCommandQueue;
|
||||||
|
|
||||||
|
#endif // GLOBALS_H
|
||||||
19
Firmware/EggbotWireless/include/WebAPI.h
Normal file
19
Firmware/EggbotWireless/include/WebAPI.h
Normal 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
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
|
|
||||||
const std::unordered_map<std::string, std::string> defaults{
|
const std::unordered_map<std::string, std::string> defaults{
|
||||||
{{"wifiMode", "ap"},
|
{{"name", defName},
|
||||||
|
{"wifiMode", "ap"},
|
||||||
{"wifiSSID", defSSID},
|
{"wifiSSID", defSSID},
|
||||||
{"wifiPass", defPass},
|
{"wifiPass", defPass},
|
||||||
{"defRpm", "2"}}};
|
{"defRpm", "2"}}};
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
|
std::queue<Command> commandQueue;
|
||||||
|
std::queue<LCommand> lCommandQueue;
|
||||||
|
|||||||
18
Firmware/EggbotWireless/src/WebAPI.cpp
Normal file
18
Firmware/EggbotWireless/src/WebAPI.cpp
Normal 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;
|
||||||
@@ -4,6 +4,9 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
|
||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
#include "Executor.h"
|
#include "Executor.h"
|
||||||
#include "GCodeParser.h"
|
#include "GCodeParser.h"
|
||||||
@@ -11,10 +14,9 @@
|
|||||||
#include "LocalExecutor.h"
|
#include "LocalExecutor.h"
|
||||||
#include "Power.h"
|
#include "Power.h"
|
||||||
#include "WiFiManager.h"
|
#include "WiFiManager.h"
|
||||||
|
#include "WebAPI.h"
|
||||||
#include "common/Commands.h"
|
#include "common/Commands.h"
|
||||||
|
|
||||||
std::queue<Command> commandQueue;
|
|
||||||
std::queue<LCommand> lCommandQueue;
|
|
||||||
bool shouldPrintSts;
|
bool shouldPrintSts;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -23,6 +25,9 @@ void setup() {
|
|||||||
power.enable12v();
|
power.enable12v();
|
||||||
configManager.load();
|
configManager.load();
|
||||||
wifiManager.init();
|
wifiManager.init();
|
||||||
|
|
||||||
|
MDNS.begin(configManager.get("name").c_str());
|
||||||
|
webApi.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printSts(Status status) {
|
void printSts(Status status) {
|
||||||
@@ -89,4 +94,7 @@ void commandsLoop() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
serialLoop();
|
serialLoop();
|
||||||
commandsLoop();
|
commandsLoop();
|
||||||
|
|
||||||
|
MDNS.update();
|
||||||
|
webApi.loopRoutine();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user