mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 05:06:39 +01:00
* Fix filesystem mutex handling This fixes the re-initialization of the filesystem mutex when the dyn storage module is reinitialized. Using xSemaphoreCreateMutex would cause a memory leak when the begin function is called multiple times and a semaphore leakage could be caused by the re-initialization of the global fsMutex variable while the semaphore is taken. The fsMutex should not be taken while the logLine function is called as this would cause a nested take of the fsMutex, which causes a deadlock. Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Fix hard coded littlefs in json upload Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Add new AP hardware support OpenEPaperLink_ESP32-PoE-ISO_AP This is based on Olimex ESP32-PoE-ISO https://www.olimex.com/Products/IoT/ESP32/ESP32-POE-ISO/open-source-hardware It has a SD Card slot that is used to store all filesystem data on SD. Use the prepare_sdcard.sh script to copy all needed data to an empty SD card that is formatted with FAT filesystem. The AP firmware will format the SD if an unformatted or from formatted card is used. This can be used to intially prepare an empty SD card for usage. For tag communication a ESP32-C6-WROOM-1(U) is used with the following connection scheme: ESP32-PoE-ISO | ESP32-C6-WROOM-1 ---------------+------------------ GPIO5 | EN GPIO13 | GPIO9 GPIO36 | GPIO3 GPIO4 | GPIO2 GPIO33 | GPIO24 GPIO32 | GPIO25 | GPIO8 pullup 5.1k Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Avoid error message log print when parsers.json is missing Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Workaround for IEEE802.15.4 modem stuck issue The ESP32-C6 esp-idf based modem firmware can run into a case where it does not receive data anymore from the tags. This can be detected when it starts to print "receive buffer full, drop the current frame" and does not recover from that. In such a case a modem reset is triggered. Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Add OpenEPaperLink_ESP32-PoE-ISO_AP to release build Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Add OpenEPaperLink_ESP32-PoE-ISO_AP to condidional build Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> * Add Ethernet support The ethernet support allows to make the network/internet connection via LAN cable instead of WiFi. LAN is preferred, if a LAN cable is connected and a valid IP configuration via DHCP can be obtained, WiFi is switched off. If the LAN cable is disconnected, a fall back to WiFi is done. Use those defines in platform.ini for PHY settings: ETHERNET_PHY_POWER: IO pin where the PHY can be switched of/on, can be -1 if not used. ETHERNET_CLK_MODE: PHY clock mode, see eth_clock_mode_t in ETH.h ETHERNET_PHY_MDC: PHY MDC pin ETHERNET_PHY_MDIO: PHY MDIO pin ETHERNET_PHY_TYPE: PHY type, see eth_phy_type_t in ETH.h Limitations: - only DHCP is supported, no static IP configuration for LAN so far. - If GPIO0 is used for one of the ETHERNET_CLK_MODE modes, then GPIO0 cannot be used to clear the WiFi configuration. Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> --------- Signed-off-by: Frank Kunz <mailinglists@kunz-im-inter.net> Co-authored-by: Frank Kunz <mailinglists@kunz-im-inter.net>
134 lines
3.2 KiB
C++
134 lines
3.2 KiB
C++
#pragma once
|
|
#include <Arduino.h>
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifndef WIFI_MANAGER_H
|
|
#define WIFI_MANAGER_H
|
|
|
|
#include <WiFi.h>
|
|
|
|
enum WifiStatus {
|
|
NOINIT,
|
|
WAIT_CONNECTING,
|
|
CONNECTED,
|
|
WAIT_RECONNECT,
|
|
AP,
|
|
ETHERNET
|
|
};
|
|
|
|
class WifiManager {
|
|
private:
|
|
bool _connected;
|
|
bool _savewhensuccessfull;
|
|
int _reconnectIntervalCheck;
|
|
int _retryIntervalCheck;
|
|
int _connectionTimeout;
|
|
String _ssid;
|
|
String _pass;
|
|
unsigned long _nextReconnectCheck;
|
|
bool _APstarted;
|
|
|
|
const int SERIAL_BUFFER_SIZE = 64;
|
|
char serialBuffer[64];
|
|
int serialIndex = 0;
|
|
|
|
String WiFi_SSID();
|
|
String WiFi_psk();
|
|
|
|
bool waitForConnection();
|
|
void pollSerial();
|
|
static void terminalLog(String text);
|
|
static String buildHostname(esp_mac_type_t mac_type);
|
|
|
|
public:
|
|
WifiManager();
|
|
|
|
WifiStatus wifiStatus;
|
|
static uint8_t apClients;
|
|
bool connectToWifi();
|
|
bool connectToWifi(String ssid, String pass, bool savewhensuccessfull);
|
|
|
|
void startManagementServer();
|
|
void poll();
|
|
static void WiFiEvent(WiFiEvent_t event);
|
|
void initEth();
|
|
IPAddress localIP();
|
|
};
|
|
|
|
#endif
|
|
|
|
extern WifiManager wm;
|
|
|
|
// **** Improv Wi-Fi ****
|
|
// https://www.improv-wifi.com/
|
|
// https://github.com/jnthas/improv-wifi-demo
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
namespace improv {
|
|
|
|
enum Error : uint8_t {
|
|
ERROR_NONE = 0x00,
|
|
ERROR_INVALID_RPC = 0x01,
|
|
ERROR_UNKNOWN_RPC = 0x02,
|
|
ERROR_UNABLE_TO_CONNECT = 0x03,
|
|
ERROR_NOT_AUTHORIZED = 0x04,
|
|
ERROR_UNKNOWN = 0xFF,
|
|
};
|
|
|
|
enum State : uint8_t {
|
|
STATE_STOPPED = 0x00,
|
|
STATE_AWAITING_AUTHORIZATION = 0x01,
|
|
STATE_AUTHORIZED = 0x02,
|
|
STATE_PROVISIONING = 0x03,
|
|
STATE_PROVISIONED = 0x04,
|
|
};
|
|
|
|
enum Command : uint8_t {
|
|
UNKNOWN = 0x00,
|
|
WIFI_SETTINGS = 0x01,
|
|
IDENTIFY = 0x02,
|
|
GET_CURRENT_STATE = 0x02,
|
|
GET_DEVICE_INFO = 0x03,
|
|
GET_WIFI_NETWORKS = 0x04,
|
|
BAD_CHECKSUM = 0xFF,
|
|
};
|
|
|
|
static const uint8_t CAPABILITY_IDENTIFY = 0x01;
|
|
static const uint8_t IMPROV_SERIAL_VERSION = 1;
|
|
|
|
enum ImprovSerialType : uint8_t {
|
|
TYPE_CURRENT_STATE = 0x01,
|
|
TYPE_ERROR_STATE = 0x02,
|
|
TYPE_RPC = 0x03,
|
|
TYPE_RPC_RESPONSE = 0x04
|
|
};
|
|
|
|
struct ImprovCommand {
|
|
Command command;
|
|
std::string ssid;
|
|
std::string password;
|
|
};
|
|
|
|
ImprovCommand parse_improv_data(const std::vector<uint8_t> &data, bool check_checksum = true);
|
|
ImprovCommand parse_improv_data(const uint8_t *data, size_t length, bool check_checksum = true);
|
|
|
|
bool parse_improv_serial_byte(size_t position, uint8_t byte, const uint8_t *buffer,
|
|
std::function<bool(ImprovCommand)> &&callback, std::function<void(Error)> &&on_error);
|
|
|
|
std::vector<uint8_t> build_rpc_response(Command command, const std::vector<std::string> &datum,
|
|
bool add_checksum = true);
|
|
std::vector<uint8_t> build_rpc_response(Command command, const std::vector<String> &datum, bool add_checksum = true);
|
|
|
|
} // namespace improv
|
|
|
|
void set_state(improv::State state);
|
|
void send_response(std::vector<uint8_t> &response);
|
|
void set_error(improv::Error error);
|
|
void getAvailableWifiNetworks();
|
|
bool onCommandCallback(improv::ImprovCommand cmd);
|
|
void onErrorCallback(improv::Error err);
|