ESP8266 compatibility

This commit is contained in:
Patrick Haßel 2024-04-11 14:01:43 +02:00
parent d29cb632ec
commit ca36d71288
6 changed files with 71 additions and 18 deletions

View File

@ -3,4 +3,14 @@
#include <Arduino.h> #include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#endif #endif

View File

@ -1,6 +1,10 @@
#include "config.h" #include "config.h"
#include "log.h" #include "log.h"
#ifdef ESP32
#include <nvs_flash.h> #include <nvs_flash.h>
#include <Preferences.h>
Preferences config; Preferences config;
@ -47,3 +51,31 @@ double configGetDouble(const char *name, double fallback) {
bool configPutDouble(const char *name, double fallback) { bool configPutDouble(const char *name, double fallback) {
return config.value(name, fallback) == 0; return config.value(name, fallback) == 0;
} }
#else
void configSetup() {
// ESP8266 FAKE
}
void configReset() {
// ESP8266 FAKE
}
String configGetString(const char *name, const char *fallback, bool allowEmpty) {
return fallback;
}
bool configPutString(const char *name, const char *value) {
return false;
}
double configGetDouble(const char *name, double fallback) {
return fallback;
}
bool configPutDouble(const char *name, double fallback) {
return false;
}
#endif

View File

@ -1,7 +1,7 @@
#ifndef SENSOR3_CONFIG_H #ifndef SENSOR3_CONFIG_H
#define SENSOR3_CONFIG_H #define SENSOR3_CONFIG_H
#include <Preferences.h> #include <WString.h>
void configSetup(); void configSetup();

View File

@ -1,8 +1,7 @@
#include <console.h> #include <console.h>
#include <HardwareSerial.h>
#include <log.h> #include <log.h>
#include <Esp.h> #include <Esp.h>
#include <WiFi.h> #include "base.h"
#include "mqtt.h" #include "mqtt.h"
#include "wifi.h" #include "wifi.h"
#include "config.h" #include "config.h"
@ -167,8 +166,10 @@ void _info() {
info(" sys: %s", datetime); info(" sys: %s", datetime);
info("Chip:"); info("Chip:");
#ifdef ESP32
info(" model: %s", ESP.getChipModel()); info(" model: %s", ESP.getChipModel());
info(" cores: %d", ESP.getChipCores()); info(" cores: %d", ESP.getChipCores());
#endif
info(" freq: %d", ESP.getCpuFreqMHz()); info(" freq: %d", ESP.getCpuFreqMHz());
info("Flash:"); info("Flash:");
@ -177,20 +178,24 @@ void _info() {
info(" speed: %d", ESP.getFlashChipSpeed()); info(" speed: %d", ESP.getFlashChipSpeed());
info("Heap:"); info("Heap:");
info(" size: %d", ESP.getHeapSize());
info(" free: %d", ESP.getFreeHeap()); info(" free: %d", ESP.getFreeHeap());
#ifdef ESP32
info(" size: %d", ESP.getHeapSize());
info(" minFree: %d", ESP.getMinFreeHeap()); info(" minFree: %d", ESP.getMinFreeHeap());
info(" maxAlloc: %d", ESP.getMaxAllocHeap()); info(" maxAlloc: %d", ESP.getMaxAllocHeap());
#endif
info("PS RAM:"); info("PS RAM:");
info(" size: %d", ESP.getPsramSize()); #ifdef ESP32
info(" free: %d", ESP.getFreePsram()); info(" free: %d", ESP.getFreePsram());
info(" size: %d", ESP.getPsramSize());
info(" minFree: %d", ESP.getMinFreePsram()); info(" minFree: %d", ESP.getMinFreePsram());
info(" maxAlloc: %d", ESP.getMaxAllocPsram()); info(" maxAlloc: %d", ESP.getMaxAllocPsram());
#endif
info("SDK:"); info("SDK:");
info(" size: %d", ESP.getSketchSize());
info(" free: %d", ESP.getFreeSketchSpace()); info(" free: %d", ESP.getFreeSketchSpace());
info(" size: %d", ESP.getSketchSize());
info(" MD5: %s", ESP.getSketchMD5().c_str()); info(" MD5: %s", ESP.getSketchMD5().c_str());
info("SDK:"); info("SDK:");
@ -207,10 +212,12 @@ const char *getFlashChipMode() {
return "DIO"; return "DIO";
case FM_DOUT: case FM_DOUT:
return "DOUT"; return "DOUT";
case FM_FAST_READ: #ifdef ESP32
return "FAST_READ"; case FM_FAST_READ:
case FM_SLOW_READ: return "FAST_READ";
return "SLOW_READ"; case FM_SLOW_READ:
return "SLOW_READ";
#endif
case FM_UNKNOWN: case FM_UNKNOWN:
return "UNKNOWN"; return "UNKNOWN";
default: default:

View File

@ -1,10 +1,10 @@
#include "wifi.h" #include "wifi.h"
#include "base.h"
#include "log.h" #include "log.h"
#include "mqtt.h" #include "mqtt.h"
#include "console.h" #include "console.h"
#include "config.h" #include "config.h"
#include <WiFi.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <lwip/apps/sntp.h> #include <lwip/apps/sntp.h>
@ -61,7 +61,11 @@ void wifiConnect() {
info("WIFI connecting: %s", ssid.c_str()); info("WIFI connecting: %s", ssid.c_str());
#ifdef ESP32
WiFiClass::hostname(HOSTNAME); WiFiClass::hostname(HOSTNAME);
#else
WiFi.hostname(HOSTNAME);
#endif
yield(); yield();
WiFi.begin(ssid, pkey); WiFi.begin(ssid, pkey);

View File

@ -32,13 +32,13 @@ lib_deps = ${COMMON.lib_deps}
build_flags = -D HOSTNAME=\"DEV\" -D WIFI_SSID=\"${COMMON.WIFI_SSID}\" -D WIFI_PKEY=\"${COMMON.WIFI_PKEY}\" -D OTA_PASSWORD=\"OtaAuthPatrixDEV\" -D BOOT_DELAY=false -D DEBUG_LOG=false build_flags = -D HOSTNAME=\"DEV\" -D WIFI_SSID=\"${COMMON.WIFI_SSID}\" -D WIFI_PKEY=\"${COMMON.WIFI_PKEY}\" -D OTA_PASSWORD=\"OtaAuthPatrixDEV\" -D BOOT_DELAY=false -D DEBUG_LOG=false
[env:Fermenter] [env:Fermenter]
upload_port = 10.0.0.138 ;upload_port = 10.0.0.138
upload_flags = --auth=OtaAuthPatrixFermenter ;upload_flags = --auth=OtaAuthPatrixFermenter
upload_protocol = ${COMMON.ota_protocol} ;upload_protocol = ${COMMON.ota_protocol}
;upload_port = ${COMMON.usb_port} upload_port = ${COMMON.usb_port}
;upload_speed = ${COMMON.usb_speed} upload_speed = ${COMMON.usb_speed}
platform = ${COMMON.platform} platform = espressif8266
board = ${COMMON.board} board = esp12e
framework = ${COMMON.framework} framework = ${COMMON.framework}
monitor_port = ${COMMON.monitor_port} monitor_port = ${COMMON.monitor_port}
monitor_speed = ${COMMON.monitor_speed} monitor_speed = ${COMMON.monitor_speed}