8 Commits

Author SHA1 Message Date
Kuba Szczodrzyński
f7c28eeea4 [release] v1.0.2
Some checks failed
Lint check / Lint with clang-format (push) Has been cancelled
Lint check / Lint with black (push) Has been cancelled
PlatformIO Publish / publish (push) Has been cancelled
2023-05-11 16:20:26 +02:00
Albert Koczy
113b2fc31d [docs] Fix dead link to Boards & CPU list (#124) 2023-05-07 12:31:27 +02:00
Stroe Andrei Catalin
86924d8785 [beken-72xx] Fix delay, yet again (#116) 2023-05-01 23:28:01 +02:00
Stroe Andrei Catalin
219415174e [libs] Fix mDNS after a wifi disconnect / reconnect event (#112)
* [libs] Fix mDNS not responding when device disconnects / reconnects to wifi

* Minor bugfix

* Reworked mDNS fix

* Update LwIPmDNS.cpp
2023-05-01 21:44:03 +02:00
Stroe Andrei Catalin
8999cb9091 [beken-72xx] Fix delay macro (#114)
* [beken-72xx] Fix delay macro

* Better fix for delay
2023-05-01 21:08:01 +02:00
Kuba Szczodrzyński
8337ac121e [core] Fix reentrant malloc wrappers 2023-05-01 20:58:37 +02:00
Kuba Szczodrzyński
d332315e7a [beken-72xx] Fix WiFi compilation issue 2023-04-28 21:24:41 +02:00
Péter Sárközi
882f58bae4 [beken-72xx] Implement WiFi powersave (#111)
* Rebase

* Clang-format
2023-04-28 17:21:49 +02:00
9 changed files with 136 additions and 28 deletions

View File

@@ -528,7 +528,7 @@ queue.BuildLibraries()
# Rename Arduino's delay() to delayMilliseconds()
env.Append(
CPPDEFINES=[
("delay", "delayMilliseconds"),
("'delay(ms)'", "'delayMilliseconds(ms)'"),
],
)

View File

@@ -84,3 +84,20 @@ IPAddress WiFiClass::hostByName(const char *hostname) {
}
return IPAddress();
}
bool WiFiClass::setSleep(bool enable) {
LT_DM(WIFI, "WiFi sleep mode %u", enable);
if (enable) {
// Replicating OpenBeken PowerSave feature
// https://github.com/openshwprojects/OpenBK7231T_App/blob/567c5756b489f0670988fad1c2742a19f0f217ea/src/cmnds/cmd_main.c#L58
bk_wlan_power_save_set_level((BK_PS_LEVEL)(PS_RF_SLEEP_BIT | PS_MCU_SLEEP_BIT));
} else {
bk_wlan_power_save_set_level((BK_PS_LEVEL)0);
}
DATA->sleep = enable;
return true;
}
bool WiFiClass::getSleep() {
return DATA->sleep;
}

View File

@@ -31,6 +31,7 @@ extern "C" {
extern void func_init_extended();
extern void app_pre_start();
extern void bk_wlan_ap_init(network_InitTypeDef_st *inNetworkInitPara);
extern int bk_wlan_power_save_set_level(BK_PS_LEVEL level);
// func/hostapd-2.5/wpa_supplicant/main_supplicant.c
extern struct wpa_ssid_value *wpas_connect_ssid;
@@ -64,6 +65,7 @@ typedef struct {
rw_evt_type lastStaEvent;
rw_evt_type lastApEvent;
bool apEnabled;
bool sleep;
} WiFiData;
#define DATA ((WiFiData *)data)

View File

@@ -6,8 +6,9 @@
// mDNS support
#undef MEMP_NUM_UDP_PCB
#define LWIP_NUM_NETIF_CLIENT_DATA 2
#define MEMP_NUM_UDP_PCB (MAX_SOCKETS_UDP + 2 + 1)
#define LWIP_NUM_NETIF_CLIENT_DATA 2
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
#define MEMP_NUM_UDP_PCB (MAX_SOCKETS_UDP + 2 + 1)
#define ip_addr ip4_addr
#define ip_addr_t ip4_addr_t

View File

@@ -13,10 +13,17 @@ extern "C" {
#include <lwip/netif.h>
}
static std::vector<char *> services_name;
static std::vector<char *> services;
static std::vector<uint8_t> protos;
static std::vector<uint16_t> ports;
static std::vector<std::vector<char *>> records;
static const char *hostName;
#ifdef LWIP_NETIF_EXT_STATUS_CALLBACK
NETIF_DECLARE_EXT_CALLBACK(netif_callback)
#endif
mDNS::mDNS() {}
mDNS::~mDNS() {}
@@ -37,34 +44,84 @@ static void mdnsStatusCallback(struct netif *netif, uint8_t result) {
LT_DM(MDNS, "Status: netif %u, status %u", netif->num, result);
}
#ifdef LWIP_NETIF_EXT_STATUS_CALLBACK
static void addServices(struct netif *netif) {
for (uint8_t i = 0; i < services.size(); i++) {
LT_DM(
MDNS,
"Add service: netif %u / %s / %s / %u / %u",
netif->num,
services_name[i],
services[i],
protos[i],
ports[i]
);
mdns_resp_add_service(
netif,
services_name[i],
services[i],
(mdns_sd_proto)protos[i],
ports[i],
255,
mdnsTxtCallback,
reinterpret_cast<void *>(i) // index of newly added service
);
}
}
#endif
static bool enableMDNS(struct netif *netif) {
if (netif_is_up(netif)) {
LT_DM(MDNS, "Starting mDNS on netif %u", netif->num);
if ((netif->flags & NETIF_FLAG_IGMP) == 0) {
netif->flags |= NETIF_FLAG_IGMP;
igmp_start(netif);
LT_DM(MDNS, "Added IGMP to netif %u", netif->num);
}
err_t ret = mdns_resp_add_netif(netif, hostName, 255);
if (ret == ERR_OK) {
LT_DM(MDNS, "mDNS started on netif %u, announcing it to network", netif->num);
mdns_resp_announce(netif);
return true;
} else {
LT_DM(MDNS, "Cannot start mDNS on netif %u; ret=%d, errno=%d", netif->num, ret, errno);
}
}
return false;
}
#ifdef LWIP_NETIF_EXT_STATUS_CALLBACK
static void
mdns_netif_ext_status_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args) {
if (reason & LWIP_NSC_NETIF_REMOVED) {
LT_DM(MDNS, "Netif removed, stopping mDNS on netif %u", netif->num);
mdns_resp_remove_netif(netif);
} else if (reason & LWIP_NSC_STATUS_CHANGED) {
LT_DM(MDNS, "Netif changed, starting mDNS on netif %u", netif->num);
if (enableMDNS(netif) && services.size() > 0) {
LT_DM(MDNS, "Adding services to netif %u", netif->num);
addServices(netif);
}
}
}
#endif
bool mDNS::begin(const char *hostname) {
hostName = strdup(hostname);
setInstanceName(hostname);
#ifdef LWIP_NETIF_EXT_STATUS_CALLBACK
netif_add_ext_callback(&netif_callback, mdns_netif_ext_status_callback);
#endif
LT_DM(MDNS, "Starting (%s)", hostname);
#if LWIP_VERSION_MAJOR >= 2 && LWIP_VERSION_MINOR >= 1
mdns_resp_register_name_result_cb(mdnsStatusCallback);
#endif
mdns_resp_init();
uint8_t enabled = 0;
struct netif *netif;
for (netif = netif_list; netif != NULL; netif = netif->next) {
if (!netif_is_up(netif))
continue;
LT_DM(MDNS, "Adding netif %u", netif->num);
if ((netif->flags & NETIF_FLAG_IGMP) == 0) {
LT_DM(MDNS, "Enabling IGMP");
netif->flags |= NETIF_FLAG_IGMP;
igmp_start(netif);
}
err_t ret = mdns_resp_add_netif(netif, hostname, 255);
if (ret == ERR_OK)
enabled++;
else
LT_DM(MDNS, "Cannot add netif %u; ret=%d, errno=%d", netif->num, ret, errno);
enableMDNS(netif);
}
return enabled > 0;
return true;
}
void mDNS::end() {
@@ -103,8 +160,10 @@ bool mDNS::addServiceImpl(const char *name, const char *service, uint8_t proto,
return false;
// add the service to TXT record arrays
services_name.push_back(strdup(name));
services.push_back(strdup(service));
protos.push_back(proto);
ports.push_back(port);
records.emplace_back();
return true;

View File

@@ -44,10 +44,38 @@ void __wrap_free(void *ptr) {
vPortFree(ptr);
}
__attribute__((alias("__wrap_malloc"))) void *__wrap__malloc_r(void *reent, size_t size);
__attribute__((alias("__wrap_calloc"))) void *__wrap__calloc_r(void *reent, size_t num, size_t size);
__attribute__((alias("__wrap_realloc"))) void *__wrap__realloc_r(void *reent, void *ptr, size_t new_size);
__attribute__((alias("__wrap_free"))) void __wrap__free_r(void *reent, void *ptr);
// Mind the 'reent' parameter - do NOT define these as linker aliases!
void *__wrap__malloc_r(void *reent, size_t size) {
return pvPortMalloc(size);
}
void *__wrap__calloc_r(void *reent, size_t num, size_t size) {
void *ptr;
if (num == 0 || size == 0)
num = size = 1;
ptr = pvPortMalloc(num * size);
if (ptr)
memset(ptr, 0, num * size);
return ptr;
}
void *__wrap__realloc_r(void *reent, void *ptr, size_t new_size) {
#if LT_REMALLOC
void *nptr = pvPortMalloc(new_size);
if (nptr) {
memcpy(nptr, ptr, new_size);
vPortFree(ptr);
}
return nptr;
#else
return LT_REALLOC_FUNC(ptr, new_size);
#endif
}
void __wrap__free_r(void *reent, void *ptr) {
vPortFree(ptr);
}
#endif

View File

@@ -5,7 +5,8 @@
#include_next "lwipopts.h"
// - 2022-05-23 set LWIP_NUM_NETIF_CLIENT_DATA to 1
#define LWIP_NUM_NETIF_CLIENT_DATA 1
#define LWIP_NUM_NETIF_CLIENT_DATA 1
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
// - 2022-05-23 set MEMP_NUM_UDP_PCB to 7
#undef MEMP_NUM_UDP_PCB
#define MEMP_NUM_UDP_PCB 7

View File

@@ -12,7 +12,7 @@ There are two basic ways to install and use LibreTiny-ESPHome. You can choose th
## Find your device's board
Go to [Boards & CPU list](../status/supported/), find your board (chip model), click on it and remember the **`Board code`**. This will be used later, during config creation.
Go to [Boards & CPU list](../status/supported.md), find your board (chip model), click on it and remember the **`Board code`**. This will be used later, during config creation.
If your board isn't listed, use one of the **Generic** boards, depending on the chip type of your device.

View File

@@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/kuba2k2/platformio-libretiny"
},
"version": "1.0.1",
"version": "1.0.2",
"frameworks": {
"base": {
"title": "Base Framework (SDK only)",