mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-19 01:11:31 +10:00
Renamed example folders
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
bool _enteredConfigMode = false;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
WiFiManager wifiManager;
|
||||
|
||||
// wifiManager.setAPCallback([this](WiFiManager* wifiManager) {
|
||||
wifiManager.setAPCallback([&](WiFiManager* wifiManager) {
|
||||
Serial.printf("Entered config mode:ip=%s, ssid='%s'\n",
|
||||
WiFi.softAPIP().toString().c_str(),
|
||||
wifiManager->getConfigPortalSSID().c_str());
|
||||
_enteredConfigMode = true;
|
||||
});
|
||||
wifiManager.resetSettings();
|
||||
if (!wifiManager.autoConnect()) {
|
||||
Serial.printf("*** Failed to connect and hit timeout\n");
|
||||
ESP.restart();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#include <WiFiManager.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
char mqtt_server[40];
|
||||
void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
||||
// message received
|
||||
}
|
||||
|
||||
void mqttReconnect() {
|
||||
// reconnect code from PubSubClient example
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.setTimeout(180);
|
||||
|
||||
if(!wifiManager.autoConnect("AutoConnectAP")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
// id/name, placeholder/prompt, default, length
|
||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
|
||||
const char* mqtt_server = custom_mqtt_server.getValue();
|
||||
|
||||
Serial.println("connected...yeey :)");
|
||||
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(mqttCallback);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!client.connected()) {
|
||||
mqttReconnect();
|
||||
}
|
||||
client.loop();
|
||||
yield();
|
||||
}
|
||||
Reference in New Issue
Block a user