mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
basic wifi thingy
This commit is contained in:
@@ -6,4 +6,6 @@ constexpr int i2cTimeout{10}, i2cTimeoutTries{10};
|
||||
constexpr int lastStsTTL{1};
|
||||
constexpr unsigned long powerTimeout{20000}, powerStartupDelay{100};
|
||||
|
||||
constexpr const char *defSSID{"eggbot"}, *defPass{"eggbotwi"};
|
||||
|
||||
#endif // CONFIG_H
|
||||
@@ -14,8 +14,8 @@ class ConfigManager {
|
||||
public:
|
||||
std::unordered_map<std::string, std::string> map;
|
||||
ConfigManager();
|
||||
std::string get(std::string &prop);
|
||||
void update(std::string &prop, std::string &val);
|
||||
std::string get(std::string prop);
|
||||
void update(std::string prop, std::string val);
|
||||
void load();
|
||||
void write();
|
||||
void reset();
|
||||
|
||||
19
Firmware/EggbotWireless/include/WiFiManager.h
Normal file
19
Firmware/EggbotWireless/include/WiFiManager.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef WIFI_MANAGER_H
|
||||
#define WIFI_MANAGER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
#include "ConfigManager.h"
|
||||
|
||||
class WiFiManager
|
||||
{
|
||||
private:
|
||||
public:
|
||||
WiFiManager();
|
||||
void init();
|
||||
};
|
||||
|
||||
extern WiFiManager wifiManager;
|
||||
|
||||
#endif // WIFI_MANAGER_H
|
||||
@@ -1,14 +1,10 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
#include "Config.h"
|
||||
#include "ConfigManager.h"
|
||||
|
||||
const std::unordered_map<std::string, std::string> defaults{
|
||||
{{"wifiClient", "off"},
|
||||
{"wifiClientSSID", ""},
|
||||
{"wifiClientPass", ""},
|
||||
{"wifiAP", "on"},
|
||||
{"wifiAPSSID", "eggbot"},
|
||||
{"wifiAPPASS", "eggbot"}}};
|
||||
{{"wifiMode", "ap"}, {"wifiSSID", defSSID}, {"wifiPass", defPass}}};
|
||||
|
||||
/*
|
||||
Max string length is 25
|
||||
@@ -19,7 +15,7 @@ const std::unordered_map<std::string, std::string> defaults{
|
||||
|
||||
ConfigManager::ConfigManager() { map.reserve(20); }
|
||||
|
||||
void ConfigManager::update(std::string &prop, std::string &val) {
|
||||
void ConfigManager::update(std::string prop, std::string val) {
|
||||
if (prop == "good" || prop == "reset" || prop == "end") {
|
||||
return;
|
||||
}
|
||||
@@ -33,7 +29,7 @@ void ConfigManager::update(std::string &prop, std::string &val) {
|
||||
saved = false;
|
||||
}
|
||||
|
||||
std::string ConfigManager::get(std::string &prop) {
|
||||
std::string ConfigManager::get(std::string prop) {
|
||||
auto valp = map.find(prop);
|
||||
if (valp != map.end()) {
|
||||
return valp->second;
|
||||
|
||||
33
Firmware/EggbotWireless/src/WiFiManager.cpp
Normal file
33
Firmware/EggbotWireless/src/WiFiManager.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "WiFiManager.h"
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
WiFiManager::WiFiManager(){};
|
||||
|
||||
void WiFiManager::init() {
|
||||
if (configManager.get("wifiMode") == "client") {
|
||||
WiFi.begin(configManager.get("wifiSSID").c_str(),
|
||||
configManager.get("wifiPass").c_str());
|
||||
int status = WiFi.status();
|
||||
while (status != WL_CONNECTED && status != WL_NO_SSID_AVAIL &&
|
||||
status != WL_CONNECT_FAILED) {
|
||||
delay(500);
|
||||
status = WiFi.status();
|
||||
}
|
||||
if (status == WL_NO_SSID_AVAIL || status == WL_CONNECT_FAILED) {
|
||||
Serial.println("WiFi connection failed");
|
||||
configManager.update("wifiMode", "ap");
|
||||
configManager.update("wifiSSID", defSSID);
|
||||
configManager.update("wifiPass", defPass);
|
||||
}
|
||||
}
|
||||
|
||||
if (configManager.get("wifiMode") == "ap") {
|
||||
WiFi.reconnect();
|
||||
Serial.println("Starting WiFi AP");
|
||||
WiFi.softAP(configManager.get("wifiSSID").c_str(),
|
||||
configManager.get("wifiPass").c_str());
|
||||
}
|
||||
}
|
||||
|
||||
WiFiManager wifiManager;
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "GCodeParser.h"
|
||||
#include "Globals.h"
|
||||
#include "LocalExecutor.h"
|
||||
#include "WiFiManager.h"
|
||||
#include "Power.h"
|
||||
#include "common/Commands.h"
|
||||
|
||||
@@ -21,6 +22,7 @@ void setup() {
|
||||
Wire.begin(12, 13);
|
||||
power.enable12v();
|
||||
configManager.load();
|
||||
wifiManager.init();
|
||||
}
|
||||
|
||||
void printSts(I2CStatusMsg status) {
|
||||
|
||||
Reference in New Issue
Block a user