Added Build-Define for WiFi-Client
This commit is contained in:
parent
08c00efbdf
commit
aefbdc43bc
@ -26,6 +26,7 @@ upload_speed = 921600
|
||||
|
||||
build_flags =
|
||||
!python git_rev_macro.py
|
||||
-DWIFI_NOCLIENT
|
||||
-DWIFI_SSID=${wifi_cred.wifi_ssid}
|
||||
-DWIFI_PASSWORD=${wifi_cred.wifi_password}
|
||||
-DADMIN_PASSWORD=${wifi_cred.admin_password}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <Wire.h>
|
||||
#include <U8g2lib.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <RemoteDebug.h>
|
||||
@ -16,11 +15,17 @@
|
||||
#include "config.h"
|
||||
#include "globals.h"
|
||||
|
||||
#ifdef WIFI_CLIENT
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
|
||||
const char *ssid = QUOTE(WIFI_SSID);
|
||||
const char *password = QUOTE(WIFI_PASSWORD);
|
||||
|
||||
const uint32_t connectTimeoutMs = 5000;
|
||||
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
const bool debug_flag = true;
|
||||
#else
|
||||
@ -36,7 +41,6 @@ volatile uint32_t wheel_pulse = 0;
|
||||
|
||||
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
|
||||
RemoteDebug Debug;
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
CRGB leds[1];
|
||||
|
||||
// Function-Prototypes
|
||||
@ -44,7 +48,6 @@ String IpAddress2String(const IPAddress &ipAddress);
|
||||
void processCmdRemoteDebug();
|
||||
void RemotDebug_printSystemInfo();
|
||||
void RemoteDebug_printWifiInfo();
|
||||
void wifiMaintainConnectionTicker_callback();
|
||||
void updateWebUITicker_callback();
|
||||
void IRAM_ATTR trigger_ISR();
|
||||
void LED_Process(uint8_t override = false, CRGB setColor = CRGB::White);
|
||||
@ -52,7 +55,10 @@ void Display_Process();
|
||||
void Button_Process();
|
||||
void startWiFiAP();
|
||||
|
||||
#ifdef WIFI_CLIENT
|
||||
void wifiMaintainConnectionTicker_callback();
|
||||
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
|
||||
#endif
|
||||
Ticker UpdateWebUITicker(updateWebUITicker_callback, 5000, 0, MILLIS);
|
||||
|
||||
void setup()
|
||||
@ -61,9 +67,17 @@ void setup()
|
||||
|
||||
snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
|
||||
|
||||
WiFi.mode(WIFI_OFF);
|
||||
WiFi.persistent(false);
|
||||
|
||||
#ifdef WIFI_CLIENT
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setHostname(DeviceName);
|
||||
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
||||
WiFiMaintainConnectionTicker.start();
|
||||
#else
|
||||
WiFi.mode(WIFI_OFF);
|
||||
#endif
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
|
||||
@ -83,12 +97,6 @@ void setup()
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(GPIO_TRIGGER), trigger_ISR, FALLING);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setHostname(DeviceName);
|
||||
wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD));
|
||||
|
||||
WiFiMaintainConnectionTicker.start();
|
||||
|
||||
if (MDNS.begin(DeviceName))
|
||||
MDNS.addService("telnet", "tcp", 23);
|
||||
|
||||
@ -145,8 +153,6 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
RunLubeApp(&wheel_pulse);
|
||||
|
||||
WiFiMaintainConnectionTicker.update();
|
||||
UpdateWebUITicker.update();
|
||||
|
||||
Display_Process();
|
||||
@ -155,6 +161,9 @@ void loop()
|
||||
|
||||
ArduinoOTA.handle();
|
||||
Debug.handle();
|
||||
#ifdef WIFI_CLIENT
|
||||
WiFiMaintainConnectionTicker.update();
|
||||
#endif
|
||||
yield();
|
||||
}
|
||||
|
||||
@ -201,6 +210,7 @@ void RemoteDebug_printWifiInfo()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef WIFI_CLIENT
|
||||
void wifiMaintainConnectionTicker_callback()
|
||||
{
|
||||
static uint32_t WiFiFailCount = 0;
|
||||
@ -218,11 +228,12 @@ void wifiMaintainConnectionTicker_callback()
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("WiFi not connected! - Start AP");
|
||||
debugV("WiFi not connected! - Start AP");
|
||||
startWiFiAP();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void updateWebUITicker_callback()
|
||||
{
|
||||
@ -264,7 +275,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
|
||||
if (LED_Status != LED_Override)
|
||||
{
|
||||
LED_ResumeOverrideStatus = LED_Status;
|
||||
debugA("Override LED_Status");
|
||||
debugV("Override LED_Status");
|
||||
}
|
||||
LED_Status = LED_Override;
|
||||
LED_override_color = SetColor;
|
||||
@ -275,7 +286,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
|
||||
if (LED_Status == LED_Override)
|
||||
{
|
||||
LED_Status = LED_ResumeOverrideStatus;
|
||||
debugA("Resume LED_Status");
|
||||
debugV("Resume LED_Status");
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,25 +296,25 @@ void LED_Process(uint8_t override, CRGB SetColor)
|
||||
{
|
||||
case sysStat_Startup:
|
||||
LED_Status = LED_Startup;
|
||||
debugA("sysStat: Startup");
|
||||
debugV("sysStat: Startup");
|
||||
break;
|
||||
case sysStat_Normal:
|
||||
timestamp = timer + 3500;
|
||||
LED_Status = LED_Confirm_Normal;
|
||||
debugA("sysStat: Normal");
|
||||
debugV("sysStat: Normal");
|
||||
break;
|
||||
case sysStat_Rain:
|
||||
timestamp = timer + 3500;
|
||||
LED_Status = LED_Confirm_Rain;
|
||||
debugA("sysStat: Rain");
|
||||
debugV("sysStat: Rain");
|
||||
break;
|
||||
case sysStat_Purge:
|
||||
LED_Status = LED_Purge;
|
||||
debugA("sysStat: Purge");
|
||||
debugV("sysStat: Purge");
|
||||
break;
|
||||
case sysStat_Error:
|
||||
LED_Status = LED_Error;
|
||||
debugA("sysStat: Error");
|
||||
debugV("sysStat: Error");
|
||||
break;
|
||||
case sysStat_NOP:
|
||||
default:
|
||||
@ -332,7 +343,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
|
||||
{
|
||||
LED_Status = LED_Normal;
|
||||
FastLED.setBrightness(64);
|
||||
debugA("LED_Status: Confirm -> Normal");
|
||||
debugV("LED_Status: Confirm -> Normal");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -347,7 +358,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
|
||||
{
|
||||
LED_Status = LED_Rain;
|
||||
FastLED.setBrightness(64);
|
||||
debugA("LED_Status: Confirm -> Rain");
|
||||
debugV("LED_Status: Confirm -> Rain");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -446,13 +457,13 @@ void Button_Process()
|
||||
{
|
||||
case BTN_TOGGLEWIFI:
|
||||
startWiFiAP();
|
||||
debugA("Starting WiFi AP");
|
||||
debugV("Starting WiFi AP");
|
||||
break;
|
||||
|
||||
case BTN_STARTPURGE:
|
||||
globals.systemStatus = sysStat_Purge;
|
||||
globals.purgePulses = LubeConfig.BleedingPulses;
|
||||
debugA("Starting Purge");
|
||||
debugV("Starting Purge");
|
||||
break;
|
||||
|
||||
case BTN_TOGGLEMODE:
|
||||
@ -470,12 +481,12 @@ void Button_Process()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
debugA("Toggling Mode");
|
||||
debugV("Toggling Mode");
|
||||
break;
|
||||
|
||||
case BTN_NOTHING:
|
||||
default:
|
||||
debugA("Nothing or invalid");
|
||||
debugV("Nothing or invalid");
|
||||
break;
|
||||
}
|
||||
LED_Process(2);
|
||||
@ -487,10 +498,21 @@ void Button_Process()
|
||||
|
||||
void startWiFiAP()
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
|
||||
WiFi.softAP(DeviceName, QUOTE(WIFI_AP_PASSWORD));
|
||||
WiFiMaintainConnectionTicker.stop();
|
||||
Serial.println("WiFi AP started, stopped Maintain-Timer");
|
||||
if (WiFi.getMode() != WIFI_OFF)
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
debugV("WiFi turned off");
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
|
||||
WiFi.softAP(DeviceName, QUOTE(WIFI_AP_PASSWORD));
|
||||
#ifdef WIFI_CLIENT
|
||||
WiFiMaintainConnectionTicker.stop();
|
||||
debugV("WiFi AP started, stopped Maintain-Timer");
|
||||
#else
|
||||
debugV("WiFi AP started");
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user