Initial WifiManager addition.
This commit is contained in:
parent
169b53aaa5
commit
f3d6d8d6d2
51
Arduino/SenderTrial2/BTCWifi.cpp
Normal file
51
Arduino/SenderTrial2/BTCWifi.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "BTCWifi.h"
|
||||
|
||||
// select which pin will trigger the configuration portal when set to LOW
|
||||
|
||||
WiFiManager wm;
|
||||
|
||||
unsigned int timeout = 120; // seconds to run for
|
||||
unsigned int startTime = millis();
|
||||
bool portalRunning = false;
|
||||
bool startCP = false; // start AP and webserver if true, else start only webserver
|
||||
int TRIG_PIN;
|
||||
|
||||
void initWifi(int initpin)
|
||||
{
|
||||
TRIG_PIN = initpin;
|
||||
pinMode(initpin, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void doWiFiManager(){
|
||||
// is auto timeout portal running
|
||||
if(portalRunning){
|
||||
wm.process();
|
||||
if((millis()-startTime) > (timeout*1000)){
|
||||
Serial.println("portaltimeout");
|
||||
portalRunning = false;
|
||||
if(startCP){
|
||||
wm.stopConfigPortal();
|
||||
}
|
||||
else{
|
||||
wm.stopWebPortal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// is configuration portal requested?
|
||||
if(digitalRead(TRIG_PIN) == LOW && (!portalRunning)) {
|
||||
if(startCP){
|
||||
Serial.println("Button Pressed, Starting Config Portal");
|
||||
wm.setConfigPortalBlocking(false);
|
||||
wm.startConfigPortal();
|
||||
}
|
||||
else{
|
||||
Serial.println("Button Pressed, Starting Web Portal");
|
||||
wm.startWebPortal();
|
||||
}
|
||||
portalRunning = true;
|
||||
startTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
|
8
Arduino/SenderTrial2/BTCWifi.h
Normal file
8
Arduino/SenderTrial2/BTCWifi.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <Arduino.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
|
||||
void doWiFiManager();
|
||||
void initWifi(int initpin);
|
||||
|
||||
|
|
@ -67,9 +67,11 @@
|
|||
#include "pins.h"
|
||||
#include "NVStorage.h"
|
||||
#include "debugport.h"
|
||||
#include "BTCWifi.h"
|
||||
|
||||
#define DEBUG_BTRX
|
||||
|
||||
#define TRIGGER_PIN 12
|
||||
|
||||
#define DEBUG_BTRX
|
||||
#include "Bluetooth.h"
|
||||
|
||||
#if defined(__arm__)
|
||||
|
@ -152,6 +154,7 @@ void PrepareTxFrame(const CProtocol& basisFrame, CProtocol& TxFrame, bool isBTCm
|
|||
|
||||
void setup()
|
||||
{
|
||||
initWifi(TRIGGER_PIN);
|
||||
// initialize serial port to interact with the "blue wire"
|
||||
// 25000 baud, Tx and Rx channels of Chinese heater comms interface:
|
||||
// Tx/Rx data to/from heater,
|
||||
|
@ -208,7 +211,7 @@ void setup()
|
|||
void loop()
|
||||
{
|
||||
unsigned long timenow = millis();
|
||||
|
||||
doWiFiManager();
|
||||
// check for test commands received from PC Over USB
|
||||
if(DebugPort.available()) {
|
||||
char rxval = DebugPort.read();
|
||||
|
|
Loading…
Reference in a new issue