Skip to content

Commit

Permalink
Home Accessory Architect v3.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenSystem committed Oct 10, 2020
1 parent cc210cb commit 96e5da8
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 190 deletions.
6 changes: 3 additions & 3 deletions devices/HAA/Makefile
Expand Up @@ -17,8 +17,8 @@ EXTRA_COMPONENTS = \
$(abspath ../../libs/adv_hlw) \
$(abspath ../../libs/new_dht) \
$(abspath ../../libs/ping) \
$(abspath ../../libs/adv_logger)

$(abspath ../../libs/adv_logger) \
$(abspath ../../libs/timers_helper)

FLASH_SIZE = 8
FLASH_MODE = dout
Expand All @@ -45,7 +45,7 @@ EXTRA_CFLAGS += -DDEFAULT_RAW_RECVMBOX_SIZE=5
EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0

EXTRA_CFLAGS += -DconfigMINIMAL_STACK_SIZE=256
EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=4
EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(configMAX_PRIORITIES-1\)
EXTRA_CFLAGS += -DconfigTIMER_QUEUE_LENGTH=10
EXTRA_CFLAGS += -DconfigTIMER_TASK_STACK_DEPTH=640

Expand Down
13 changes: 6 additions & 7 deletions devices/HAA/header.h
Expand Up @@ -9,7 +9,7 @@
#define __HAA_HEADER_H__

// Version
#define FIRMWARE_VERSION "3.5.7"
#define FIRMWARE_VERSION "3.5.8"

// Sysparam
#define SYSPARAMSECTOR (0xF3000)
Expand Down Expand Up @@ -430,14 +430,13 @@
#define SAVE_STATES_TIMER ch_group_find_by_acc(ACC_TYPE_ROOT_DEVICE)->timer
#define WIFI_WATCHDOG_TIMER ch_group_find_by_acc(ACC_TYPE_ROOT_DEVICE)->timer2
#define WIFI_STATUS_DISCONNECTED (0)
#define WIFI_STATUS_CONNECTING_1 (1)
#define WIFI_STATUS_CONNECTING_2 (2)
#define WIFI_STATUS_PRECONNECTED (3)
#define WIFI_STATUS_CONNECTED (4)
#define WIFI_STATUS_CONNECTING (1)
#define WIFI_STATUS_PRECONNECTED (2)
#define WIFI_STATUS_CONNECTED (3)
#define WIFI_WATCHDOG_POLL_PERIOD_MS (1000)
#define WIFI_RECONNECTION_POLL_PERIOD_MS (7500)
#define WIFI_RECONNECTION_POLL_PERIOD_MS (5000)
#define WIFI_PING_ERRORS "w"
#define WIFI_ERROR_COUNT_REBOOT (20)
#define WIFI_ERROR_COUNT_REBOOT (60)

#define SAVE_STATES_DELAY_MS (5000)

Expand Down
172 changes: 86 additions & 86 deletions devices/HAA/main.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion devices/HAA/setup_mode/content/index.html
Expand Up @@ -22,7 +22,7 @@
.nonetworks{text-align:center;margin:1em 0;}
.field{margin-bottom:0.5em;}
.field.required label::before{content:"*";color:red;}
</style></head><body><div class="container"><h1>Home Accessory Architect v3.5.7</h1>
</style></head><body><div class="container"><h1>Home Accessory Architect v3.5.8</h1>
<form action="/settings" method="post">
<div class="field required conf">
<label for="conf">JSON Config:</label>
Expand Down
71 changes: 26 additions & 45 deletions devices/HAA/setup_mode/src/wifi_config.c
Expand Up @@ -12,10 +12,8 @@

#include <stdio.h>
#include <string.h>
//#include <stdint.h>
#include <sysparam.h>
#include <FreeRTOS.h>
#include <timers.h>
#include <esplibs/libmain.h>
#include <espressif/esp_common.h>
#include <lwip/sockets.h>
Expand All @@ -32,6 +30,8 @@
#include <rboot-api.h>
#include <homekit/homekit.h>

#include <timers_helper.h>

#define CUSTOM_REPO_SYSPARAM "ota_sever"
#define PORT_NUMBER_SYSPARAM "ota_port"
#define PORT_SECURE_SYSPARAM "ota_sec"
Expand All @@ -57,8 +57,6 @@

#define MAX_BODY_LEN (16000)

#define XTIMER_BLOCK_TIME (50)

#define INFO(message, ...) printf(message "\n", ##__VA_ARGS__);
#define ERROR(message, ...) printf("! " message "\n", ##__VA_ARGS__);

Expand Down Expand Up @@ -89,13 +87,12 @@ typedef struct {

TaskHandle_t http_task_handle;
TaskHandle_t dns_task_handle;
TaskHandle_t wifi_scan_task_handle;
TaskHandle_t sta_connect_timeout;

wifi_network_info_t* wifi_networks;
SemaphoreHandle_t wifi_networks_mutex;

uint8_t check_counter: 7;
uint8_t check_counter: 6;
bool hostname_ready: 1;
} wifi_config_context_t;

Expand Down Expand Up @@ -162,12 +159,6 @@ static void client_send_redirect(client_t *client, int code, const char *redirec
client_send(client, buffer, len);
}

static void stop_reboot_timer() {
if (context->auto_reboot_timer) {
xTimerDelete(context->auto_reboot_timer, XTIMER_BLOCK_TIME);
}
}

uint8_t wifi_config_connect();
void wifi_config_reset() {
struct sdk_station_config sta_config;
Expand All @@ -176,15 +167,14 @@ void wifi_config_reset() {
strncpy((char *)sta_config.ssid, "none", sizeof(sta_config.ssid));
sta_config.ssid[sizeof(sta_config.ssid) - 1] = 0;
sdk_wifi_station_set_config(&sta_config);
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_connect();
sdk_wifi_station_set_auto_connect(false);
}

static void wifi_networks_free() {
wifi_network_info_t* wifi_network = context->wifi_networks;
while (wifi_network) {
wifi_network_info_t *next = wifi_network->next;
wifi_network_info_t* next = wifi_network->next;
free(wifi_network);
wifi_network = next;
}
Expand All @@ -193,12 +183,17 @@ static void wifi_networks_free() {

static void wifi_scan_done_cb(void *arg, sdk_scan_status_t status) {
if (status != SCAN_OK || !context) {
ERROR("WiFi scan failed");
ERROR("Wifi scan failed");
return;
}

xSemaphoreTake(context->wifi_networks_mutex, portMAX_DELAY);

if (!context) {
ERROR("No context");
return;
}

wifi_networks_free();

struct sdk_bss_info *bss = (struct sdk_bss_info *)arg;
Expand Down Expand Up @@ -236,18 +231,17 @@ static void wifi_scan_done_cb(void *arg, sdk_scan_status_t status) {
}

static void wifi_scan_task(void *arg) {
INFO("Start WiFi scan");

for (;;) {
sdk_wifi_station_scan(NULL, wifi_scan_done_cb);
vTaskDelay(pdMS_TO_TICKS(10000));
}
INFO("Start Wifi scan");
sdk_wifi_station_scan(NULL, wifi_scan_done_cb);
vTaskDelete(NULL);
}

#include "index.html.h"

static void wifi_config_server_on_settings(client_t *client) {
stop_reboot_timer();
esp_timer_delete(context->auto_reboot_timer);

xTaskCreate(wifi_scan_task, "wifi_scan", 384, NULL, (tskIDLE_PRIORITY + 0), NULL);

static const char http_prologue[] =
"HTTP/1.1 200 \r\n"
Expand All @@ -268,7 +262,6 @@ static void wifi_config_server_on_settings(client_t *client) {
free(text);
text = NULL;
}

client_send_chunk(client, html_settings_middle);

status = sysparam_get_string(OTA_VERSION_SYSPARAM, &text);
Expand All @@ -277,15 +270,13 @@ static void wifi_config_server_on_settings(client_t *client) {
free(text);
text = NULL;
}

client_send_chunk(client, html_settings_otaversion);

bool auto_ota = false;
status = sysparam_get_bool(AUTO_OTA_SYSPARAM, &auto_ota);
if (status == SYSPARAM_OK && auto_ota) {
client_send_chunk(client, "checked");
}

client_send_chunk(client, html_settings_autoota);

int8_t int8_value = 0;
Expand All @@ -300,7 +291,7 @@ static void wifi_config_server_on_settings(client_t *client) {
}
client_send_chunk(client, html_wifi_mode_1);

// WiFi Networks
// Wifi Networks
char buffer[120];
char bssid[13];
if (xSemaphoreTake(context->wifi_networks_mutex, pdMS_TO_TICKS(5000))) {
Expand Down Expand Up @@ -568,12 +559,8 @@ static int wifi_config_server_on_message_complete(http_parser *parser) {
break;
}
case ENDPOINT_SETTINGS_UPDATE: {
stop_reboot_timer();
esp_timer_delete(context->auto_reboot_timer);
vTaskDelete(context->sta_connect_timeout);

if (context->wifi_scan_task_handle) {
vTaskDelete(context->wifi_scan_task_handle);
}
wifi_config_context_free(context);
xTaskCreate(wifi_config_server_on_settings_update_task, "settings_update", 512, client, (tskIDLE_PRIORITY + 0), NULL);
return 0;
Expand Down Expand Up @@ -816,8 +803,6 @@ static void wifi_config_softap_start() {
context->wifi_networks_mutex = xSemaphoreCreateBinary();
xSemaphoreGive(context->wifi_networks_mutex);

xTaskCreate(wifi_scan_task, "wifi_scan_task", 384, NULL, (tskIDLE_PRIORITY + 0), &context->wifi_scan_task_handle);

INFO("Start DHCP server");
dhcpserver_start(&first_client_ip, 4);
dhcpserver_set_router(&ap_ip.ip);
Expand Down Expand Up @@ -855,13 +840,9 @@ static void wifi_config_sta_connect_timeout_task() {

if (context->on_wifi_ready) {
http_stop();
if (context->wifi_scan_task_handle) {
vTaskDelete(context->wifi_scan_task_handle);
}
context->on_wifi_ready();

wifi_config_context_free(context);
context = NULL;
break;
}
} else if (context->on_wifi_ready) {
Expand All @@ -870,7 +851,7 @@ static void wifi_config_sta_connect_timeout_task() {
wifi_config_connect();
vTaskDelay(pdMS_TO_TICKS(6000));

} else if (context->check_counter == 60) {
} else if (context->check_counter == 55) {
context->check_counter = 0;
wifi_config_reset();
vTaskDelay(pdMS_TO_TICKS(6000));
Expand Down Expand Up @@ -928,12 +909,12 @@ uint8_t wifi_config_connect() {
if (wifi_mode == 1 && wifi_bssid) {
sta_config.bssid_set = 1;
memcpy(sta_config.bssid, wifi_bssid, 6);
INFO("WiFi Mode: Forced BSSID");
INFO("Wifi Mode: Forced BSSID");

//INFO("WiFi Mode: Forced BSSID %02x%02x%02x%02x%02x%02x", sta_config.bssid[0], sta_config.bssid[1], sta_config.bssid[2], sta_config.bssid[3], sta_config.bssid[4], sta_config.bssid[5]);
//INFO("Wifi Mode: Forced BSSID %02x%02x%02x%02x%02x%02x", sta_config.bssid[0], sta_config.bssid[1], sta_config.bssid[2], sta_config.bssid[3], sta_config.bssid[4], sta_config.bssid[5]);

} else {
INFO("WiFi Mode: Normal");
INFO("Wifi Mode: Normal");
sta_config.bssid_set = 0;
}

Expand All @@ -955,7 +936,7 @@ uint8_t wifi_config_connect() {
return 1;

} else {
INFO("No WiFi config found");
INFO("No Wifi config found");
}

return 0;
Expand All @@ -975,8 +956,8 @@ static void wifi_config_station_connect() {

if (setup_mode == 1) {
INFO("Enabling auto reboot");
context->auto_reboot_timer = xTimerCreate(0, pdMS_TO_TICKS(AUTO_REBOOT_TIMEOUT), pdFALSE, NULL, auto_reboot_run);
xTimerStart(context->auto_reboot_timer, XTIMER_BLOCK_TIME);
context->auto_reboot_timer = esp_timer_create(AUTO_REBOOT_TIMEOUT, false, NULL, auto_reboot_run);
esp_timer_start(context->auto_reboot_timer);
}

wifi_config_softap_start();
Expand All @@ -988,7 +969,7 @@ static void wifi_config_station_connect() {
}

void wifi_config_init(const char* ssid_prefix, const char* password, void (*on_wifi_ready)(), const char* custom_hostname) {
INFO("WiFi config init");
INFO("Wifi config init");
if (password && strlen(password) < 8) {
ERROR("Password must be at least 8 characters");
return;
Expand Down
6 changes: 3 additions & 3 deletions devices/HAA/types.h
Expand Up @@ -217,9 +217,10 @@ typedef struct _str_ch_value {
} str_ch_value_t;

typedef struct _main_config {
uint8_t wifi_status: 3;
uint8_t wifi_status: 2;
uint8_t wifi_channel: 4;
bool enable_homekit_server: 1;
bool setpwm_bool_semaphore: 1;
int8_t setup_mode_toggle_counter;
int8_t setup_mode_toggle_counter_max;
uint8_t ir_tx_freq;
Expand All @@ -229,14 +230,13 @@ typedef struct _main_config {
uint8_t ir_tx_gpio: 5;
bool ir_tx_inv: 1;
bool setpwm_is_running: 1;
bool setpwm_bool_semaphore: 1;
uint8_t led_gpio: 5;
bool wifi_ping_is_running: 1;
bool ping_is_running: 1;
bool used_gpio_0: 1;
bool used_gpio_1: 1;

uint16_t setup_mode_time;
bool used_gpio_1: 1;
bool used_gpio_2: 1;
bool used_gpio_3: 1;
bool used_gpio_4: 1;
Expand Down
7 changes: 3 additions & 4 deletions external_libs/homekit/src/mdnsresponder.c
Expand Up @@ -429,7 +429,7 @@ static void mdns_announce_netif(struct netif *netif, const ip_addr_t *addr);
static TimerHandle_t mdns_announce_timer = NULL;

void mdns_clear() {
xTimerStop(mdns_announce_timer, 100);
xTimerStop(mdns_announce_timer, 0);

if (!xSemaphoreTake(gDictMutex, portMAX_DELAY))
return;
Expand Down Expand Up @@ -619,13 +619,12 @@ void mdns_add_facility_work(const char* instanceName, // Friendly name, need n
free(fullName);
free(devName);

xTimerStop(mdns_announce_timer, 100);
xTimerStop(mdns_announce_timer, 0);

mdns_announce();

// if (ttl > 0) {
xTimerChangePeriod(mdns_announce_timer, pdMS_TO_TICKS(ttl * TTL_MULTIPLIER_MS), 100);
xTimerStart(mdns_announce_timer, 100);
xTimerChangePeriod(mdns_announce_timer, pdMS_TO_TICKS(ttl * TTL_MULTIPLIER_MS), 0);
// }
}

Expand Down

0 comments on commit 96e5da8

Please sign in to comment.