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 int lastStsTTL{1};
|
||||||
constexpr unsigned long powerTimeout{20000}, powerStartupDelay{100};
|
constexpr unsigned long powerTimeout{20000}, powerStartupDelay{100};
|
||||||
|
|
||||||
|
constexpr const char *defSSID{"eggbot"}, *defPass{"eggbotwi"};
|
||||||
|
|
||||||
#endif // CONFIG_H
|
#endif // CONFIG_H
|
||||||
@@ -14,8 +14,8 @@ class ConfigManager {
|
|||||||
public:
|
public:
|
||||||
std::unordered_map<std::string, std::string> map;
|
std::unordered_map<std::string, std::string> map;
|
||||||
ConfigManager();
|
ConfigManager();
|
||||||
std::string get(std::string &prop);
|
std::string get(std::string prop);
|
||||||
void update(std::string &prop, std::string &val);
|
void update(std::string prop, std::string val);
|
||||||
void load();
|
void load();
|
||||||
void write();
|
void write();
|
||||||
void reset();
|
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 "EEPROM.h"
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
|
|
||||||
const std::unordered_map<std::string, std::string> defaults{
|
const std::unordered_map<std::string, std::string> defaults{
|
||||||
{{"wifiClient", "off"},
|
{{"wifiMode", "ap"}, {"wifiSSID", defSSID}, {"wifiPass", defPass}}};
|
||||||
{"wifiClientSSID", ""},
|
|
||||||
{"wifiClientPass", ""},
|
|
||||||
{"wifiAP", "on"},
|
|
||||||
{"wifiAPSSID", "eggbot"},
|
|
||||||
{"wifiAPPASS", "eggbot"}}};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Max string length is 25
|
Max string length is 25
|
||||||
@@ -19,7 +15,7 @@ const std::unordered_map<std::string, std::string> defaults{
|
|||||||
|
|
||||||
ConfigManager::ConfigManager() { map.reserve(20); }
|
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") {
|
if (prop == "good" || prop == "reset" || prop == "end") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -33,7 +29,7 @@ void ConfigManager::update(std::string &prop, std::string &val) {
|
|||||||
saved = false;
|
saved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ConfigManager::get(std::string &prop) {
|
std::string ConfigManager::get(std::string prop) {
|
||||||
auto valp = map.find(prop);
|
auto valp = map.find(prop);
|
||||||
if (valp != map.end()) {
|
if (valp != map.end()) {
|
||||||
return valp->second;
|
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 "GCodeParser.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "LocalExecutor.h"
|
#include "LocalExecutor.h"
|
||||||
|
#include "WiFiManager.h"
|
||||||
#include "Power.h"
|
#include "Power.h"
|
||||||
#include "common/Commands.h"
|
#include "common/Commands.h"
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ void setup() {
|
|||||||
Wire.begin(12, 13);
|
Wire.begin(12, 13);
|
||||||
power.enable12v();
|
power.enable12v();
|
||||||
configManager.load();
|
configManager.load();
|
||||||
|
wifiManager.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printSts(I2CStatusMsg status) {
|
void printSts(I2CStatusMsg status) {
|
||||||
|
|||||||
Reference in New Issue
Block a user