Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom AP wifi name #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 44 additions & 30 deletions src/WiFiMQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,13 @@
#include "WiFiMQTTManager.h"

WiFiManager *wm;

WiFiMQTTManager::WiFiMQTTManager(int resetPin, char* APpassword) {
wm = new WiFiManager;

lastMsg = 0;
formatFS = false;
_APpassword = APpassword;
strcpy(_mqtt_server, "YOURMQTTADDRESS");
strcpy(_mqtt_port, "1883");
_LED_BUILTIN = 2;
_lastMsg = 0;
_value = 0;
_shouldSaveConfig = false;
//byte* message;

Serial.begin(115200);
void _placeholderSubscibeTo();
subscribeTo = _placeholderSubscibeTo;
void _subscriptionCallback(char* topicIn, byte* message, unsigned int length);
subscriptionCallback = _subscriptionCallback;
wm->setDebugOutput(false);
pinMode(resetPin, INPUT);
_resetPin = resetPin;
#ifdef ESP32
strcpy(deviceType, "ESP32");
#elif defined(ESP8266)
strcpy(deviceType, "ESP8266");
#else
strcpy(deviceType, "UNKNOWN");
#endif
_init(resetPin, APpassword);
}

WiFiMQTTManager::WiFiMQTTManager(int resetPin, char* APpassword, char* apWifiName) {
_init(resetPin, APpassword);
_APwifiName = apWifiName;
}

void WiFiMQTTManager::loop() {
Expand Down Expand Up @@ -96,7 +72,13 @@ void WiFiMQTTManager::setup(String sketchName) {
});

Serial.println("WMM: lets try to connect to WiFi...");
if (!wm->autoConnect(clientId, _APpassword)) {
char *apWifiName;
if (_APwifiName == NULL) {
apWifiName = clientId;
} else {
apWifiName = _APwifiName;
}
if (!wm->autoConnect(apWifiName, _APpassword)) {
Serial.println("WMM: failed to connect and hit timeout...");
delay(3000);
ESP.restart();
Expand Down Expand Up @@ -166,6 +148,38 @@ void WiFiMQTTManager::setup(String sketchName) {
_registerDevice();
}

void WiFiMQTTManager::_init(int resetPin, char* APpassword) {
wm = new WiFiManager;
lastMsg = 0;
formatFS = false;
_APpassword = APpassword;
strcpy(_mqtt_server, "82.165.202.174");
strcpy(_mqtt_port, "1883");
strcpy(_mqtt_username, "twigger");
strcpy(_mqtt_password, "tart1fl3tt3");
_LED_BUILTIN = 2;
_lastMsg = 0;
_value = 0;
_shouldSaveConfig = false;
//byte* message;

Serial.begin(115200);
void _placeholderSubscibeTo();
subscribeTo = _placeholderSubscibeTo;
void _subscriptionCallback(char* topicIn, byte* message, unsigned int length);
subscriptionCallback = _subscriptionCallback;
wm->setDebugOutput(false);
pinMode(resetPin, INPUT);
_resetPin = resetPin;
#ifdef ESP32
strcpy(deviceType, "ESP32");
#elif defined(ESP8266)
strcpy(deviceType, "ESP8266");
#else
strcpy(deviceType, "UNKNOWN");
#endif
}

void WiFiMQTTManager::_setupSpiffs(){
if (formatFS == true) {
Serial.print("WMM: formatting FS...please wait..... ");
Expand Down
3 changes: 3 additions & 0 deletions src/WiFiMQTTManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void _settingsAP();
class WiFiMQTTManager {
public:
WiFiMQTTManager(int resetPin, char* APpassword);
WiFiMQTTManager(int resetPin, char* APpassword, char* apWifiName);
//WiFiManager wm;
void setup(String sketchName);
void loop();
Expand All @@ -39,6 +40,7 @@ class WiFiMQTTManager {
long lastMsg;
char deviceType[40];
private:
void _init(int resetPin, char* APpassword);
void _setupSpiffs();
void _checkButton();
void _registerDevice();
Expand All @@ -52,6 +54,7 @@ class WiFiMQTTManager {
char _mqtt_port[6];
String _sketchName;
char* _APpassword;
char* _APwifiName;
//char _mqtt_username[40] = "YOURMQTTUSERNAME";
//char _mqtt_password[40] = "YOURMQTTPASSWORD";
int _LED_BUILTIN;
Expand Down