Skip to content

Commit

Permalink
Remove WiFiManager as a workaround for the incompatibility with the d…
Browse files Browse the repository at this point in the history
…isplay library
  • Loading branch information
Andreas Tacke authored and LoQue90 committed Dec 5, 2023
1 parent 988c822 commit 9e027c9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 80 deletions.
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ lib_deps =
bblanchon/ArduinoJson @ 6.19.4
tobiasschuerg/ESP8266 Influxdb @ 3.9.0
git+https://github.com/me-no-dev/ESPAsyncWebServer#f71e3d4
git+https://github.com/tzapu/WiFiManager#71937d1

[env:nodemcuv2_usb]
platform = espressif8266 @^2.6.3
Expand Down
7 changes: 1 addition & 6 deletions src/RancilioServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* @brief Embedded webserver
*/

#ifndef rancilioserver_h
#define rancilioserver_h

#include <Arduino.h>

#ifdef ESP32
Expand All @@ -16,8 +13,8 @@
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#define WEBSERVER_H
#endif

#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>

Expand Down Expand Up @@ -581,5 +578,3 @@ void sendTempEvent(double currentTemp, double targetTemp, double heaterPower) {
events.send("ping", NULL, millis());
events.send(getTempString().c_str(), "new_temps", millis());
}

#endif
52 changes: 8 additions & 44 deletions src/debugSerial.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
#include "debugSerial.h"

//server for monitor connections
WiFiServer SerialServer(23);
WiFiClient RemoteSerial;

void startRemoteSerialServer() {
SerialServer.begin();
}

void checkForRemoteSerialClients() {
if (SerialServer.hasClient()) {
// If we are already connected to another client,
// then reject the new connection. Otherwise accept
// the connection.
if (RemoteSerial.connected()) {
debugPrintln("Serial Server Connection rejected");
SerialServer.available().stop();
}
else {
debugPrintln("Serial Server Connection accepted");
RemoteSerial = SerialServer.available();
}
}
}

void getCurrentTimeString(char *output) {
time_t rawtime;
Expand All @@ -36,25 +13,17 @@ void getCurrentTimeString(char *output) {
void debugPrintln(const char *message) {
char time[12];
getCurrentTimeString(time);
if (RemoteSerial.connected()) {
RemoteSerial.print(time);
RemoteSerial.println(message);
} else {
Serial.print(time);
Serial.println(message);
}

Serial.print(time);
Serial.println(message);
}

void debugPrint(const char *message) {
char time[12];
getCurrentTimeString(time);
if (RemoteSerial.connected()) {
RemoteSerial.print(time);
RemoteSerial.print(message);
} else {
Serial.print(time);
Serial.print(message);
}

Serial.print(time);
Serial.print(message);
}

size_t debugPrintf(const char *format, ...) {
Expand Down Expand Up @@ -82,13 +51,8 @@ size_t debugPrintf(const char *format, ...) {
char time[12];
getCurrentTimeString(time);

if (RemoteSerial.connected()) {
len = RemoteSerial.print(time);
len += RemoteSerial.print(buffer);
} else {
len = Serial.print(time);
len += Serial.print(buffer);
}
len = Serial.print(time);
len += Serial.print(buffer);

if (buffer != temp) {
delete[] buffer;
Expand Down
7 changes: 2 additions & 5 deletions src/debugSerial.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/**
* @file debugSerial.h
*
* @brief Logging methods using either serial or network port
* @brief Debug logging
*/

#ifndef debugserial_h
#define debugserial_h

#include <ctime>
#include <cstdio>
#include <Arduino.h>

#include <WiFiManager.h>

void startRemoteSerialServer();
void checkForRemoteSerialClients();
void debugPrint(const char *message);
void debugPrintln(const char *message);
size_t debugPrintf(const char *format, ...);
Expand Down
60 changes: 37 additions & 23 deletions src/rancilio-pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#if TEMPSENSOR == 1
#include <DallasTemperature.h> // Library for dallas temp sensor
#endif
#include <WiFiManager.h>

#include <InfluxDbClient.h>
#include <PubSubClient.h>
#include <U8g2lib.h> // i2c display
Expand Down Expand Up @@ -121,11 +121,11 @@ double percentage;
#endif

// WiFi
WiFiManager wm;
const unsigned long wifiConnectionDelay = WIFICONNECTIONDELAY;
const unsigned int maxWifiReconnects = MAXWIFIRECONNECTS;
const char *hostname = HOSTNAME;
const char *pass = PASS;
const char *ssid = WIFI_SSID;
const char *pass = WIFI_PASS;
unsigned long lastWifiConnectionAttempt = millis();
unsigned int wifiReconnects = 0; // actual number of reconnects

Expand Down Expand Up @@ -715,8 +715,8 @@ void checkWifi() {
#endif
}

wm.disconnect();
wm.autoConnect();
WiFi.disconnect();
WiFi.begin(ssid, pass);

int count = 1;

Expand Down Expand Up @@ -1588,15 +1588,32 @@ void tempLed() {
* @brief Set up internal WiFi hardware
*/
void wiFiSetup() {
wm.setCleanConnect(true);
wm.setConfigPortalTimeout(60); // sec Timeout for Portal
wm.setConnectTimeout(10); // Try 10 sec to connect to WLAN, 5 sec too short!
wm.setBreakAfterConfig(true);
wm.setConnectRetries(3);
//wm.setWiFiAutoReconnect(true);
wm.setHostname(hostname);

if (wm.autoConnect(hostname, pass)) {
unsigned long started = millis();

#if defined(ESP8266)
WiFi.hostname(hostname);
#endif

/* Explicitly set the ESP8266 to be a WiFi client, otherwise it would
* try to act as both a client and an access-point by default and could
* cause network-issues with the other devices on your WiFi network
*/
WiFi.mode(WIFI_STA);
WiFi.persistent(false);
WiFi.begin(ssid, pass);

#if defined(ESP32)
WiFi.setHostname(hostname);
#endif

// Wait up to 20 seconds for connection:
while ((WiFi.status() != WL_CONNECTED) && (millis() - started < 20000)) {
yield(); // Prevent Watchdog trigger
}

checkWifi();

if (WiFi.status() == WL_CONNECTED) {
debugPrintf("WiFi connected - IP = %i.%i.%i.%i\n", WiFi.localIP()[0],
WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);

Expand All @@ -1618,17 +1635,15 @@ void wiFiSetup() {
displayLogo(langstring_nowifi[0], langstring_nowifi[1]);
#endif

wm.disconnect();
WiFi.disconnect();
delay(1000);

offlineMode = 1;
}

#if OLED_DISPLAY != 0
displayLogo(langstring_connectwifi1, wm.getWiFiSSID(true));
displayLogo(langstring_connectwifi1, WiFi.SSID());
#endif

startRemoteSerialServer();
}


Expand Down Expand Up @@ -1871,10 +1886,10 @@ void setup() {
}
} else if (connectmode == 0)
{
wm.disconnect(); // no wm
readSysParamsFromStorage(); // get values from stroage
offlineMode = 1 ; //offline mode
pidON = 1 ; //pid on
WiFi.disconnect();
readSysParamsFromStorage();
offlineMode = 1;
pidON = 1;
}

// Initialize PID controller
Expand Down Expand Up @@ -1945,7 +1960,6 @@ void loop() {
looppid();
#endif

checkForRemoteSerialClients();
}

#if TOF == 1
Expand Down
3 changes: 2 additions & 1 deletion src/userConfig_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ enum MACHINE {
// Connectivity
#define CONNECTMODE 1 // 0 = offline 1 = WIFI-MODE
#define HOSTNAME "silvia"
#define PASS "CleverCoffee" // default password for WiFiManager
#define WIFI_SSID "yourSSID" // SSID of your WiFi network
#define WIFI_PASS "yourWiFiPass" // WPA key to your WiFi network
#define MAXWIFIRECONNECTS 5 // maximum number of reconnection attempts, use -1 to deactivate
#define WIFICONNECTIONDELAY 10000 // delay between reconnects in ms

Expand Down

0 comments on commit 9e027c9

Please sign in to comment.