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