mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Changes to haspDevice class
This commit is contained in:
parent
b7366336cc
commit
7857ea03ed
@ -8,6 +8,11 @@
|
||||
#include "Arduino.h"
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
#include <cstdint>
|
||||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
namespace dev {
|
||||
|
||||
class BaseDevice {
|
||||
@ -17,6 +22,19 @@ class BaseDevice {
|
||||
|
||||
virtual void reboot()
|
||||
{}
|
||||
virtual const char* get_hostname()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual const char* get_core_version()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
virtual const char* get_display_driver()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
virtual void init()
|
||||
{}
|
||||
virtual void post_setup()
|
||||
@ -60,10 +78,13 @@ class BaseDevice {
|
||||
#elif defined(STM32F4)
|
||||
#warning Building for STM32F4xx Devices
|
||||
#include "stm32f4/stm32f4.h"
|
||||
#elif defined(WINDOWS)
|
||||
#warning Building for Win32 Devices
|
||||
#include "win32/hasp_win32.h"
|
||||
#else
|
||||
#warning Building for Generic Devices
|
||||
using dev::BaseDevice;
|
||||
|
||||
extern dev::BaseDevice haspDevice;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "hasp_conf.h"
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp/hasp_utilities.h"
|
||||
|
||||
#define BACKLIGHT_CHANNEL 0
|
||||
|
||||
@ -22,17 +23,31 @@ void Esp32Device::reboot()
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
const char* Esp32Device::get_hostname()
|
||||
{
|
||||
return hostname.c_str();
|
||||
}
|
||||
const char* Esp32Device::get_core_version()
|
||||
{
|
||||
return ESP.getSdkVersion();
|
||||
}
|
||||
const char* Esp32Device::get_display_driver()
|
||||
{
|
||||
return Utilities::tft_driver_name().c_str();
|
||||
}
|
||||
|
||||
void Esp32Device::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
Esp32Device::backlight_pin = pin;
|
||||
/* Setup Backlight Control Pin */
|
||||
if(pin >= 0) {
|
||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
||||
|
||||
/* Setup Backlight Control Pin */
|
||||
if(pin != (uint8_t)-1) {
|
||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
||||
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
||||
ledcAttachPin(pin, BACKLIGHT_CHANNEL);
|
||||
|
||||
update_backlight();
|
||||
} else {
|
||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin not set"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,11 +77,10 @@ bool Esp32Device::get_backlight_power()
|
||||
|
||||
void Esp32Device::update_backlight()
|
||||
{
|
||||
if(backlight_pin == -1) return;
|
||||
if(backlight_pin == (uint8_t)-1) return;
|
||||
|
||||
if(backlight_power) { // The backlight is ON
|
||||
ledcWrite(BACKLIGHT_CHANNEL, map(backlight_level, 0, 100, 0, 4095)); // ledChannel and value
|
||||
}
|
||||
uint32_t duty = backlight_power ? map(backlight_level, 0, 100, 0, 4095) : 0;
|
||||
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
|
||||
}
|
||||
|
||||
size_t Esp32Device::get_free_max_block()
|
||||
|
@ -15,25 +15,24 @@ class Esp32Device : public BaseDevice {
|
||||
public:
|
||||
void reboot() override;
|
||||
|
||||
const char* get_hostname();
|
||||
const char* get_core_version();
|
||||
const char* get_display_driver();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
|
||||
uint8_t get_backlight_level() override;
|
||||
|
||||
void set_backlight_power(bool power) override;
|
||||
|
||||
bool get_backlight_power() override;
|
||||
|
||||
size_t get_free_max_block() override;
|
||||
|
||||
size_t get_free_heap() override;
|
||||
|
||||
uint8_t get_heap_fragmentation() override;
|
||||
|
||||
uint16_t get_cpu_frequency() override;
|
||||
|
||||
private:
|
||||
std::string hostname;
|
||||
|
||||
uint8_t backlight_pin;
|
||||
uint8_t backlight_level;
|
||||
uint8_t backlight_power;
|
||||
@ -43,8 +42,6 @@ class Esp32Device : public BaseDevice {
|
||||
|
||||
} // namespace dev
|
||||
|
||||
using dev::Esp32Device;
|
||||
|
||||
#if defined(LANBONL8)
|
||||
#warning Building for Lanbon L8
|
||||
#include "lanbonl8.h"
|
||||
@ -52,6 +49,7 @@ using dev::Esp32Device;
|
||||
#warning Building for M5Stack core2
|
||||
#include "m5stackcore2.h"
|
||||
#else
|
||||
using dev::Esp32Device;
|
||||
extern dev::Esp32Device haspDevice;
|
||||
#endif
|
||||
#endif // ESP32
|
||||
|
@ -64,4 +64,5 @@ void LanbonL8::init()
|
||||
} // namespace dev
|
||||
|
||||
dev::LanbonL8 haspDevice;
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@ class LanbonL8 : public Esp32Device {
|
||||
|
||||
} // namespace dev
|
||||
|
||||
using dev::LanbonL8;
|
||||
extern dev::LanbonL8 haspDevice;
|
||||
|
||||
#endif
|
||||
|
@ -43,4 +43,5 @@ void M5StackCore2::init(void)
|
||||
} // namespace dev
|
||||
|
||||
dev::M5StackCore2 haspDevice;
|
||||
|
||||
#endif
|
||||
|
@ -45,7 +45,6 @@ class Esp8266Device : public BaseDevice {
|
||||
} // namespace dev
|
||||
|
||||
using dev::Esp8266Device;
|
||||
|
||||
extern dev::Esp8266Device haspDevice;
|
||||
|
||||
#endif // ESP8266
|
||||
|
86
src/dev/win32/hasp_win32.cpp
Normal file
86
src/dev/win32/hasp_win32.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#if defined(WINDOWS)
|
||||
|
||||
#include <cstdint>
|
||||
#include "Windows.h"
|
||||
|
||||
#include "hasp_win32.h"
|
||||
|
||||
#include "hasp_conf.h"
|
||||
#include "hasp_debug.h"
|
||||
|
||||
namespace dev {
|
||||
|
||||
void Win32Device::reboot()
|
||||
{}
|
||||
|
||||
const char* Win32Device::get_hostname()
|
||||
{
|
||||
return "winhasp";
|
||||
}
|
||||
const char* Win32Device::get_core_version()
|
||||
{
|
||||
return "win32";
|
||||
}
|
||||
const char* Win32Device::get_display_driver()
|
||||
{
|
||||
return "test";
|
||||
}
|
||||
|
||||
void Win32Device::set_backlight_pin(uint8_t pin)
|
||||
{
|
||||
Win32Device::backlight_pin = pin;
|
||||
}
|
||||
|
||||
void Win32Device::set_backlight_level(uint8_t level)
|
||||
{
|
||||
backlight_level = level >= 0 ? level : 0;
|
||||
backlight_level = backlight_level <= 100 ? backlight_level : 100;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
uint8_t Win32Device::get_backlight_level()
|
||||
{
|
||||
return backlight_level;
|
||||
}
|
||||
|
||||
void Win32Device::set_backlight_power(bool power)
|
||||
{
|
||||
backlight_power = power;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool Win32Device::get_backlight_power()
|
||||
{
|
||||
return backlight_power != 0;
|
||||
}
|
||||
|
||||
void Win32Device::update_backlight()
|
||||
{
|
||||
if(backlight_pin == -1) return;
|
||||
}
|
||||
|
||||
size_t Win32Device::get_free_max_block()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t Win32Device::get_free_heap(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t Win32Device::get_heap_fragmentation()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t Win32Device::get_cpu_frequency()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dev
|
||||
|
||||
dev::Win32Device haspDevice;
|
||||
|
||||
#endif // WINDOWS
|
52
src/dev/win32/hasp_win32.h
Normal file
52
src/dev/win32/hasp_win32.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#ifndef HASP_DEVICE_WINDOWS_H
|
||||
#define HASP_DEVICE_WINDOWS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "Windows.h"
|
||||
|
||||
#include "hasp_conf.h"
|
||||
#include "../device.h"
|
||||
|
||||
#if defined(WINDOWS)
|
||||
|
||||
namespace dev {
|
||||
|
||||
class Win32Device : public BaseDevice {
|
||||
|
||||
public:
|
||||
void reboot() override;
|
||||
|
||||
const char* get_hostname() override;
|
||||
const char* get_core_version() override;
|
||||
const char* get_display_driver() override;
|
||||
|
||||
void set_backlight_pin(uint8_t pin);
|
||||
void set_backlight_level(uint8_t val);
|
||||
uint8_t get_backlight_level();
|
||||
void set_backlight_power(bool power);
|
||||
bool get_backlight_power();
|
||||
|
||||
size_t get_free_max_block();
|
||||
size_t get_free_heap();
|
||||
uint8_t get_heap_fragmentation();
|
||||
uint16_t get_cpu_frequency();
|
||||
|
||||
private:
|
||||
uint8_t backlight_pin;
|
||||
uint8_t backlight_level;
|
||||
uint8_t backlight_power;
|
||||
|
||||
void update_backlight();
|
||||
};
|
||||
|
||||
} // namespace dev
|
||||
|
||||
using dev::Win32Device;
|
||||
extern dev::Win32Device haspDevice;
|
||||
|
||||
#endif // WINDOWS
|
||||
|
||||
#endif // HASP_DEVICE_WINDOWS_H
|
@ -8,13 +8,14 @@
|
||||
#include "ArduinoJson.h"
|
||||
#include "hasp_conf.h"
|
||||
|
||||
#include "dev/device.h"
|
||||
|
||||
#if HASP_USE_EEPROM > 0
|
||||
#include "StreamUtils.h" // For EEPromStream
|
||||
#endif
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "lv_conf.h"
|
||||
#include "hasp_conf.h"
|
||||
|
||||
#if HASP_USE_DEBUG > 0
|
||||
#include "../hasp_debug.h"
|
||||
@ -32,7 +33,6 @@
|
||||
|
||||
#include "hasp_attribute.h"
|
||||
#include "hasp.h"
|
||||
#include "dev/device.h"
|
||||
#include "lv_theme_hasp.h"
|
||||
|
||||
#if HASP_USE_EEPROM > 0
|
||||
@ -163,10 +163,11 @@ void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time)
|
||||
/**
|
||||
* Checks if we went to sleep, wake up is handled in the event handlers
|
||||
*/
|
||||
// void haspEverySecond()
|
||||
// {
|
||||
// hasp_update_sleep_state();
|
||||
// }
|
||||
void haspEverySecond()
|
||||
{
|
||||
hasp_update_sleep_state();
|
||||
dispatchEverySecond();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#if HASP_USE_DEBUG > 0
|
||||
#include "../hasp_debug.h"
|
||||
#include "dev/device.h"
|
||||
#endif
|
||||
|
||||
#define NORMALIZE(a, b, c) map(a, b, c, 0, 0xFFFFU)
|
||||
@ -50,7 +51,7 @@ extern "C" {
|
||||
*/
|
||||
void haspSetup(void);
|
||||
void haspLoop(void);
|
||||
// void haspEverySecond(void); // See MACROS
|
||||
void haspEverySecond(void);
|
||||
|
||||
void haspReconnect(void);
|
||||
void haspDisconnect(void);
|
||||
@ -84,7 +85,6 @@ void hasp_enable_wakeup_touch();
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
#define haspEverySecond hasp_update_sleep_state
|
||||
|
||||
#endif /*HASP_USE_APP*/
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
dispatch_conf_t dispatch_setings = {.teleperiod = 300};
|
||||
dispatch_conf_t dispatch_setings = {.teleperiod = 10};
|
||||
|
||||
uint32_t dispatchLastMillis;
|
||||
uint8_t nCommands = 0;
|
||||
@ -897,18 +897,32 @@ void dispatch_output_statusupdate(const char*, const char*)
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
printf("%s %d\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
snprintf_P(data, sizeof(data),
|
||||
PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
mqttGetNodename().c_str(), buffer, long(millis() / 1000));
|
||||
haspDevice.get_hostname(), buffer, long(millis() / 1000));
|
||||
|
||||
printf("%s %d\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
|
||||
#if HASP_USE_WIFI > 0
|
||||
network_get_statusupdate(buffer, sizeof(buffer));
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
|
||||
printf("%s %d\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
|
||||
haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), halGetCoreVersion().c_str());
|
||||
haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), haspDevice.get_core_version());
|
||||
strcat(data, buffer);
|
||||
|
||||
printf("%s %d\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
|
||||
haspGetPage(), (HASP_NUM_PAGES));
|
||||
strcat(data, buffer);
|
||||
@ -918,8 +932,11 @@ void dispatch_output_statusupdate(const char*, const char*)
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
|
||||
printf("%s %d\n", __FILE__, __LINE__);
|
||||
fflush(stdout);
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
|
||||
halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
haspDevice.get_display_driver(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
strcat(data, buffer);
|
||||
}
|
||||
mqtt_send_state(F("statusupdate"), data);
|
||||
@ -1006,7 +1023,7 @@ void dispatchLoop()
|
||||
}
|
||||
|
||||
#if 1 || ARDUINO
|
||||
void everySecond()
|
||||
void dispatchEverySecond()
|
||||
{
|
||||
if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) {
|
||||
dispatchLastMillis = millis();
|
||||
|
@ -7,7 +7,8 @@
|
||||
#include "ArduinoJson.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
struct dispatch_conf_t {
|
||||
struct dispatch_conf_t
|
||||
{
|
||||
uint16_t teleperiod;
|
||||
};
|
||||
|
||||
|
@ -608,7 +608,7 @@ int hasp_parse_json_attributes(lv_obj_t * obj, const JsonObject & doc)
|
||||
std::string v;
|
||||
|
||||
for(JsonPair keyValue : doc) {
|
||||
LOG_VERBOSE(TAG_HASP, F(" * %s => %s"), keyValue.key().c_str(), keyValue.value().as<std::string>().c_str());
|
||||
LOG_VERBOSE(TAG_HASP, F(D_BULLET "%s=%s"), keyValue.key().c_str(), keyValue.value().as<std::string>().c_str());
|
||||
v = keyValue.value().as<std::string>();
|
||||
hasp_process_obj_attribute(obj, keyValue.key().c_str(), keyValue.value().as<std::string>().c_str(), true);
|
||||
i++;
|
||||
@ -618,7 +618,7 @@ int hasp_parse_json_attributes(lv_obj_t * obj, const JsonObject & doc)
|
||||
v.reserve(64);
|
||||
|
||||
for(JsonPair keyValue : doc) {
|
||||
LOG_VERBOSE(TAG_HASP, F(" * %s => %s"), keyValue.key().c_str(), keyValue.value().as<String>().c_str());
|
||||
LOG_DEBUG(TAG_HASP, F(D_BULLET "%s=%s"), keyValue.key().c_str(), keyValue.value().as<String>().c_str());
|
||||
v = keyValue.value().as<String>();
|
||||
hasp_process_obj_attribute(obj, keyValue.key().c_str(), keyValue.value().as<String>().c_str(), true);
|
||||
i++;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
#ifdef ARDUINO
|
||||
#include "Arduino.h"
|
||||
@ -54,8 +55,44 @@ int Utilities::format_bytes(size_t filesize, char * buf, size_t len)
|
||||
return snprintf_P(buf, len, PSTR("%d.%d %ciB"), filesize / 10, filesize % 10, labels[unit]);
|
||||
}
|
||||
|
||||
std::string Utilities::tft_driver_name()
|
||||
{
|
||||
#if defined(ILI9341_DRIVER)
|
||||
return "ILI9341";
|
||||
#elif defined(ST7735_DRIVER)
|
||||
return "ST7735";
|
||||
#elif defined(ILI9163_DRIVER)
|
||||
return "ILI9163";
|
||||
#elif defined(S6D02A1_DRIVER)
|
||||
return "S6D02A1";
|
||||
#elif defined(ST7796_DRIVER)
|
||||
return "ST7796";
|
||||
#elif defined(ILI9486_DRIVER)
|
||||
return "ILI9486";
|
||||
#elif defined(ILI9481_DRIVER)
|
||||
return "ILI9481";
|
||||
#elif defined(ILI9488_DRIVER)
|
||||
return "ILI9488";
|
||||
#elif defined(HX8357D_DRIVER)
|
||||
return "HX8357D";
|
||||
#elif defined(EPD_DRIVER)
|
||||
return "EPD";
|
||||
#elif defined(ST7789_DRIVER)
|
||||
return "ST7789";
|
||||
#elif defined(R61581_DRIVER)
|
||||
return "R61581";
|
||||
#elif defined(ST7789_2_DRIVER)
|
||||
return "ST7789_2";
|
||||
#elif defined(RM68140_DRIVER)
|
||||
return "RM68140";
|
||||
#else
|
||||
return "Other";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef ARDUINO
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
#endif
|
@ -4,6 +4,8 @@
|
||||
#ifndef HASP_UTILITIES_H
|
||||
#define HASP_UTILITIES_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Utilities {
|
||||
|
||||
public:
|
||||
@ -11,6 +13,7 @@ class Utilities {
|
||||
static bool is_true(const char* s);
|
||||
static bool is_only_digits(const char* s);
|
||||
static int format_bytes(size_t filesize, char* buf, size_t len);
|
||||
static std::string tft_driver_name();
|
||||
};
|
||||
|
||||
#ifndef ARDUINO
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "lv_fs_if.h"
|
||||
|
||||
// Device Drivers
|
||||
#include "dev/device.h"
|
||||
#include "drv/hasp_drv_display.h"
|
||||
#include "drv/hasp_drv_touch.h"
|
||||
|
||||
@ -203,16 +204,17 @@ void guiSetup(void)
|
||||
#endif
|
||||
|
||||
/* Setup Backlight Control Pin */
|
||||
if(gui_settings.backlight_pin >= 0) {
|
||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin);
|
||||
haspDevice.set_backlight_pin(gui_settings.backlight_pin);
|
||||
// if(gui_settings.backlight_pin >= 0) {
|
||||
// LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
||||
ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL);
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
pinMode(gui_settings.backlight_pin, OUTPUT);
|
||||
#endif
|
||||
}
|
||||
// #if defined(ARDUINO_ARCH_ESP32)
|
||||
// ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
||||
// ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL);
|
||||
// #elif defined(ARDUINO_ARCH_ESP8266)
|
||||
// pinMode(gui_settings.backlight_pin, OUTPUT);
|
||||
// #endif
|
||||
// }
|
||||
LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), gui_settings.rotation);
|
||||
|
||||
LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH,
|
||||
|
@ -28,8 +28,8 @@ bool mqttGetConfig(const JsonObject & settings);
|
||||
bool mqttSetConfig(const JsonObject& settings);
|
||||
#endif
|
||||
|
||||
#ifndef WINDOWS
|
||||
String mqttGetNodename(void);
|
||||
#endif
|
||||
// #ifndef WINDOWS
|
||||
// String mqttGetNodename(void);
|
||||
// #endif
|
||||
|
||||
#endif
|
@ -93,7 +93,7 @@ bool mqttHAautodiscover = true;
|
||||
char mqttServer[16] = MQTT_HOST;
|
||||
char mqttUser[23] = MQTT_USER;
|
||||
char mqttPassword[32] = MQTT_PASSW;
|
||||
char mqttNodeName[16] = MQTT_NODENAME;
|
||||
// char mqttNodeName[16] = MQTT_NODENAME;
|
||||
char mqttGroupName[16] = MQTT_GROUPNAME;
|
||||
uint16_t mqttPort = MQTT_PORT;
|
||||
|
||||
@ -419,7 +419,5 @@ void mqttLoop(){};
|
||||
|
||||
void mqttEvery5Seconds(bool wifiIsConnected){};
|
||||
|
||||
// String mqttGetNodename(void){return "palte35"};
|
||||
|
||||
#endif // USE_PAHO
|
||||
#endif // USE_MQTT
|
@ -348,10 +348,10 @@ void mqttEvery5Seconds(bool networkIsConnected)
|
||||
}
|
||||
}
|
||||
|
||||
String mqttGetNodename()
|
||||
{
|
||||
return mqttNodeName;
|
||||
}
|
||||
// String mqttGetNodename()
|
||||
// {
|
||||
// return mqttNodeName;
|
||||
// }
|
||||
|
||||
void mqttStop()
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
|
||||
#include "hasp_conf.h"
|
||||
#include "hal/hasp_hal.h"
|
||||
#include "hasp_debug.h"
|
||||
@ -17,7 +16,7 @@ void EthernetEvent(WiFiEvent_t event)
|
||||
case SYSTEM_EVENT_ETH_START:
|
||||
LOG_TRACE(TAG_ETH, F(D_SERVICE_STARTED));
|
||||
// set eth hostname here
|
||||
ETH.setHostname(mqttGetNodename().c_str());
|
||||
ETH.setHostname(haspDevice.get_hostname());
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
LOG_TRACE(TAG_ETH, F(D_SERVICE_CONNECTED));
|
||||
@ -65,8 +64,8 @@ bool ethernetEvery5Seconds()
|
||||
|
||||
void ethernet_get_statusupdate(char* buffer, size_t len)
|
||||
{
|
||||
snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":\"%d Mbps\",\"ip\":\"%s\","), eth_connected ? F("ON") : F("OFF"), ETH.linkSpeed(),
|
||||
ETH.localIP().toString().c_str());
|
||||
snprintf_P(buffer, len, PSTR("\"eth\":\"%s\",\"link\":\"%d Mbps\",\"ip\":\"%s\","),
|
||||
eth_connected ? F("ON") : F("OFF"), ETH.linkSpeed(), ETH.localIP().toString().c_str());
|
||||
}
|
||||
|
||||
#endif
|
@ -65,7 +65,8 @@ static void wifiConnected(IPAddress ipaddress)
|
||||
LOG_TRACE(TAG_WIFI, F(D_NETWORK_IP_ADDRESS_RECEIVED), ipaddress.toString().c_str());
|
||||
#endif
|
||||
|
||||
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"), WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE));
|
||||
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"),
|
||||
WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE));
|
||||
networkStart();
|
||||
}
|
||||
|
||||
@ -353,10 +354,10 @@ static void wifiReconnect(void)
|
||||
{
|
||||
WiFi.disconnect(true);
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
WiFi.hostname(mqttGetNodename().c_str());
|
||||
WiFi.hostname(haspDevice.get_hostname());
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||
WiFi.setHostname(mqttGetNodename().c_str());
|
||||
WiFi.setHostname(haspDevice.get_hostname());
|
||||
#endif
|
||||
WiFi.begin(wifiSsid, wifiPassword);
|
||||
}
|
||||
|
@ -33,12 +33,6 @@ void mdnsStart()
|
||||
|
||||
LOG_TRACE(TAG_MDNS, F(D_SERVICE_STARTING));
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
String hasp2Node = mqttGetNodename();
|
||||
#else
|
||||
String hasp2Node = "unknown";
|
||||
#endif
|
||||
|
||||
// Setup mDNS service discovery if enabled
|
||||
|
||||
/* uint8_t attempt = 0;
|
||||
@ -55,7 +49,7 @@ void mdnsStart()
|
||||
LOG_VERBOSE(TAG_MDNS, F("Trying hostname %s"), hasp2Node.c_str());
|
||||
};*/
|
||||
|
||||
if(MDNS.begin(hasp2Node.c_str())) {
|
||||
if(MDNS.begin(haspDevice.get_hostname())) {
|
||||
char value[32];
|
||||
char service[12];
|
||||
char key[12];
|
||||
|
@ -141,12 +141,8 @@ void otaSetup(void)
|
||||
// delay(5000);
|
||||
});
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
ArduinoOTA.setHostname(String(mqttGetNodename()).c_str());
|
||||
#else
|
||||
ArduinoOTA.setHostname(String(mqttGetNodename()).c_str());
|
||||
#endif
|
||||
// ArduinoOTA.setPassword(configPassword);
|
||||
ArduinoOTA.setHostname(haspDevice.get_hostname());
|
||||
// ArduinoOTA.setPassword(configPassword); // See OTA_PASSWORD
|
||||
ArduinoOTA.setPort(otaPort);
|
||||
|
||||
#if ESP32
|
||||
@ -160,7 +156,7 @@ void otaSetup(void)
|
||||
ArduinoOTA.setRebootOnSuccess(false); // We do that ourselves
|
||||
|
||||
#ifdef OTA_PASSWORD
|
||||
ArduinoOTA.setPassword(OTA_PASSWORD);
|
||||
ArduinoOTA.setPassword(OTA_PASSWORD); // TODO
|
||||
#endif
|
||||
|
||||
ArduinoOTA.begin();
|
||||
|
@ -76,7 +76,11 @@ lib_deps =
|
||||
https://github.com/eclipse/paho.mqtt.c.git
|
||||
bblanchon/ArduinoJson@^6.17.2 ; Json(l) parser
|
||||
|
||||
lib_ignore = paho
|
||||
lib_ignore =
|
||||
paho
|
||||
AXP192
|
||||
ArduinoLog
|
||||
lv_fs_if
|
||||
|
||||
src_filter =
|
||||
+<*>
|
||||
@ -89,14 +93,12 @@ src_filter =
|
||||
-<MQTTClient.c>
|
||||
-<MQTTVersion.c>
|
||||
-<SSLSocket.c>
|
||||
-<../.pio/libdeps/emulator_64bits/lv_fs_if/lv_fs_pc.c>
|
||||
-<../.pio/libdeps/emulator_64bits/ArduinoLog/ArduinoLog.cpp>
|
||||
-<sys/>
|
||||
-<hal/>
|
||||
-<drv/>
|
||||
-<drv/touch>
|
||||
-<drv/tft>
|
||||
-<dev/>
|
||||
+<dev/>
|
||||
-<hal/>
|
||||
-<svc/>
|
||||
-<hasp_filesystem.cpp>
|
||||
@ -105,11 +107,4 @@ src_filter =
|
||||
+<lang/>
|
||||
-<log/>
|
||||
+<mqtt/>
|
||||
-<lib/ArduinoLog>
|
||||
-<lib/lv_fs_if>
|
||||
-<../lib/lv_fs_if/>
|
||||
-<../lib/lv_fs_if/lv_fs_if.cpp>
|
||||
-<../lib/lv_fs_if/lv_fs_if.h>
|
||||
-<../lib/lv_fs_if/lv_fs_spiffs.cpp>
|
||||
-<../lib/lv_fs_if/lv_fs_spiffs.h>
|
||||
+<../.pio/libdeps/emulator_64bits/ArduinoJson/src/ArduinoJson.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user