Skip to content

Commit

Permalink
Home Accessory Architect v12.8.0 Merlin
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenSystem committed Sep 14, 2023
1 parent 340806e commit b83ea70
Show file tree
Hide file tree
Showing 40 changed files with 1,055 additions and 680 deletions.
6 changes: 6 additions & 0 deletions HAA/HAA_Installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if(HAA_SINGLE_CORE)
)
endif()

if(HAA_XTAL26)
list(APPEND EXTRA_COMPILE_OPTIONS
-DHAA_XTAL26
)
endif()

if(HAABOOT)
list(APPEND EXTRA_COMPILE_OPTIONS
-DHAABOOT
Expand Down
3 changes: 2 additions & 1 deletion HAA/HAA_Installer/main/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "../../common/common_headers.h"

#define INSTALLER_VERSION "7.5.3"
#define INSTALLER_BETA_REVISION ""
#define INSTALLER_VERSION "7.6.0"INSTALLER_BETA_REVISION

#endif // __HAA_OTA_HEADER_H__
17 changes: 16 additions & 1 deletion HAA/HAA_Installer/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void init_task() {
ota_reboot(0);
}
#else
if (running_partition->subtype != ESP_PARTITION_SUBTYPE_APP_OTA_1 && running_partition->subtype != ESP_PARTITION_SUBTYPE_APP_FACTORY) {
if (running_partition->subtype != ESP_PARTITION_SUBTYPE_APP_OTA_1 &&
running_partition->subtype != ESP_PARTITION_SUBTYPE_APP_FACTORY) {
ota_reboot(1);
}
#endif // HAABOOT
Expand Down Expand Up @@ -169,6 +170,20 @@ void ota_task(void *arg) {
INFO(" installed");
#endif // HAABOOT

/*
#ifdef ESP_PLATFORM
// Show ESP-IDF Partitions
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
for (; it != NULL; it = esp_partition_next(it)) {
const esp_partition_t *part = esp_partition_get(it);
INFO("Partition '%s' at 0x%02X, Size 0x%02X, Type 0x%02X, Sub 0x%02X", part->label, part->address, part->size, part->type, part->subtype);
}
esp_partition_iterator_release(it);
#endif
*/

ota_init(user_repo, is_ssl);

vTaskDelay(MS_TO_TICKS(2000));
Expand Down
22 changes: 11 additions & 11 deletions HAA/HAA_Installer/main/ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void set_partitions() {
}
}

esp_partition_t* get_partition(const int sector) {
esp_partition_t* get_partition(const unsigned int sector) {
if (sector == BOOT0SECTOR) {
return partition_boot0;
}
Expand All @@ -116,10 +116,10 @@ esp_partition_t* get_partition(const int sector) {
#endif

static char *strstr_lc(char *full_string, const char *search) {
const size_t search_len = strlen(search);
for (size_t i = 0; i <= strlen(full_string) - search_len; i++) {
const unsigned int search_len = strlen(search);
for (unsigned int i = 0; i <= strlen(full_string) - search_len; i++) {
if (tolower((unsigned char) full_string[i]) == tolower((unsigned char) search[0])) {
for (size_t j = 0; j < search_len; j++) {
for (unsigned int j = 0; j < search_len; j++) {
if (tolower((unsigned char) full_string[i + j]) != tolower((unsigned char) search[j])) {
break;
}
Expand Down Expand Up @@ -314,7 +314,7 @@ static int ota_get_final_location(char* repo, char* file, uint16_t port, const b
WOLFSSL* ssl;
int socket;

size_t buffer_len = 0;
uint32_t buffer_len = 0;
char* buffer = NULL;
char* recv_buf = NULL;
char* location = NULL;
Expand Down Expand Up @@ -351,7 +351,7 @@ static int ota_get_final_location(char* repo, char* file, uint16_t port, const b
CRLFCRLF);

if (ota_conn_result == 0) {
const int send_bytes = strlen(recv_buf);
const unsigned int send_bytes = strlen(recv_buf);

if (is_ssl) {
ret = wolfSSL_write(ssl, recv_buf, send_bytes);
Expand All @@ -364,7 +364,7 @@ static int ota_get_final_location(char* repo, char* file, uint16_t port, const b
INFO("OK");

//wolfSSL_shutdown(ssl); //by shutting down the connection before even reading, we reduce the payload to the minimum
int all_ok = false;
unsigned int all_ok = false;

do {
memset(recv_buf, 0, RECV_BUF_LEN);
Expand Down Expand Up @@ -509,7 +509,7 @@ static int ota_get_file_ex(char* repo, char* file, int sector, uint8_t* buffer,
return -5; // Needs to be either a sector or a signature/version file
}

int connection_tries = 0;
unsigned int connection_tries = 0;
while ((ota_conn_result = ota_get_final_location(repo, file, port, is_ssl)) <= 0 && connection_tries < 3) {
connection_tries++;
ERROR("Tries %i", connection_tries);
Expand All @@ -524,7 +524,7 @@ static int ota_get_file_ex(char* repo, char* file, int sector, uint8_t* buffer,
INFO("*** FINAL %s:%i/%s\n", last_host, port, last_location);

int new_connection() {
int tries = 0;
unsigned int tries = 0;
int result;
while ((result = ota_connect(last_host, port, &socket, &ssl, is_ssl)) < 0 && tries < 3) {
tries++;
Expand Down Expand Up @@ -566,7 +566,7 @@ static int ota_get_file_ex(char* repo, char* file, int sector, uint8_t* buffer,

snprintf(recv_buf, RECV_BUF_LEN - 1, REQUESTHEAD"%s"REQUESTTAIL"%s"RANGE"%d-%d%s", last_location, last_host, collected, collected + 4095, CRLFCRLF);

const int send_bytes = strlen(recv_buf);
const unsigned int send_bytes = strlen(recv_buf);

if (is_ssl) {
ret = wolfSSL_write(ssl, recv_buf, send_bytes);
Expand Down Expand Up @@ -870,7 +870,7 @@ int ota_verify_sign(int start_sector, int filesize, uint8_t* signature) {
wc_Sha384Final(&sha, hash);

int verify = 0;
int ret = wc_ecc_verify_hash(signature, SIGNSIZE, hash, HASHSIZE, &verify, &public_key);
wc_ecc_verify_hash(signature, SIGNSIZE, hash, HASHSIZE, &verify, &public_key);

INFO(">>> Result %s", verify == 1 ? "OK" : "ERROR");

Expand Down
2 changes: 1 addition & 1 deletion HAA/HAA_Installer/main/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define OTAREPO "github.com/RavenSystem/haa/releases/latest/download"

#ifdef ESP_PLATFORM
#define HAA_FINAL_NAME "_"HAA_CHIP_NAME""HAA_SINGLE_CORE_SUFIX
#define HAA_FINAL_NAME "_"HAA_CHIP_NAME""HAA_SINGLE_CORE_SUFIX""HAA_XTAL26_SUFIX
#else
#define HAA_FINAL_NAME ""
#endif
Expand Down
29 changes: 16 additions & 13 deletions HAA/HAA_Installer/main/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#define ENDPOINT_SETTINGS_UPDATE (3)

#ifdef ESP_PLATFORM
int got_ip = false;
bool got_ip = false;
esp_netif_t* setup_esp_netif = NULL;

void setup_set_esp_netif(esp_netif_t* esp_netif) {
Expand All @@ -98,7 +98,7 @@ typedef struct _wifi_network_info {

typedef struct {
char* ssid_prefix;
size_t max_body_size;
uint32_t max_body_size;

TimerHandle_t auto_reboot_timer;

Expand All @@ -122,7 +122,7 @@ typedef struct _client {
http_parser parser;
uint8_t endpoint;
uint8_t *body;
size_t body_length;
uint32_t body_length;
} client_t;


Expand Down Expand Up @@ -158,14 +158,14 @@ static void client_free(client_t *client) {
free(client);
}

static void client_send(client_t *client, const char *payload, size_t payload_size) {
static void client_send(client_t *client, const char *payload, unsigned int payload_size) {
lwip_write(client->fd, payload, payload_size);
}

static void client_send_chunk(client_t *client, const char *payload) {
size_t len = strlen(payload);
unsigned int len = strlen(payload);
char buffer[10];
size_t buffer_len = snprintf(buffer, sizeof(buffer), "%x\r\n", len);
unsigned int buffer_len = snprintf(buffer, sizeof(buffer), "%x\r\n", len);
client_send(client, buffer, buffer_len);
client_send(client, payload, len);
client_send(client, "\r\n", 2);
Expand All @@ -174,7 +174,7 @@ static void client_send_chunk(client_t *client, const char *payload) {
static void client_send_redirect(client_t *client, int code, const char *redirect_url) {
INFO("Redirect %s", redirect_url);
char buffer[128];
size_t len = snprintf(buffer, sizeof(buffer), "HTTP/1.1 %d \r\nLocation: %s\r\nContent-Length: 0\r\nConnection: close\r\n\r\n", code, redirect_url);
unsigned int len = snprintf(buffer, sizeof(buffer), "HTTP/1.1 %d \r\nLocation: %s\r\nContent-Length: 0\r\nConnection: close\r\n\r\n", code, redirect_url);
client_send(client, buffer, len);
}

Expand Down Expand Up @@ -300,15 +300,15 @@ static void wifi_scan_sc_done() {

int8_t best_rssi = INT8_MIN;
uint8_t* best_bssid = malloc(6);
int found = false;
unsigned int found = false;

uint16_t ap_count = 0;
esp_wifi_scan_get_ap_num(&ap_count);

wifi_ap_record_t* ap_records = (wifi_ap_record_t*) malloc(ap_count * sizeof(wifi_ap_record_t));
esp_wifi_scan_get_ap_records(&ap_count, ap_records);

for (int i = 0; i < ap_count; i++) {
for (unsigned int i = 0; i < ap_count; i++) {
if (strcmp(wifi_ssid, (char*) ap_records[i].ssid) == 0) {
INFO("RSSI %i, Ch %i - %02x%02x%02x%02x%02x%02x", ap_records[i].rssi, ap_records[i].primary, ap_records[i].bssid[0], ap_records[i].bssid[1], ap_records[i].bssid[2], ap_records[i].bssid[3], ap_records[i].bssid[4], ap_records[i].bssid[5]);

Expand Down Expand Up @@ -345,7 +345,7 @@ static void wifi_scan_sc_done(void* arg, sdk_scan_status_t status) {

int8_t best_rssi = INT8_MIN;
uint8_t* best_bssid = malloc(6);
int found = false;
unsigned int found = false;
while (bss) {
if (strcmp(wifi_ssid, (char*) bss->ssid) == 0) {
INFO("RSSI %i, Ch %i - %02x%02x%02x%02x%02x%02x", bss->rssi, bss->channel, bss->bssid[0], bss->bssid[1], bss->bssid[2], bss->bssid[3], bss->bssid[4], bss->bssid[5]);
Expand Down Expand Up @@ -431,6 +431,7 @@ static uint8_t wifi_config_connect(const uint8_t phy);
static void wifi_config_reset() {
INFO("Wifi clean");
sdk_wifi_station_disconnect();
vTaskDelay(1);

struct sdk_station_config sta_config;
memset(&sta_config, 0, sizeof(sta_config));
Expand Down Expand Up @@ -467,7 +468,7 @@ static void wifi_scan_done_cb() {
wifi_ap_record_t* ap_records = (wifi_ap_record_t*) malloc(ap_count * sizeof(wifi_ap_record_t));
esp_wifi_scan_get_ap_records(&ap_count, ap_records);

for (int i = 0; i < ap_count; i++) {
for (unsigned int i = 0; i < ap_count; i++) {
//INFO("%s (%i) Ch %i - %02x%02x%02x%02x%02x%02x", ap_records[i].bssid, ap_records[i].rssi, ap_records[i].primary, ap_records[i].bssid[0], ap_records[i].bssid[1], ap_records[i].bssid[2], ap_records[i].bssid[3], ap_records[i].bssid[4], ap_records[i].bssid[5]);

wifi_network_info_t* net = context->wifi_networks;
Expand Down Expand Up @@ -546,6 +547,7 @@ static void wifi_scan_task(void *arg) {
#ifdef ESP_PLATFORM
if (!wifi_config_got_ip()) {
sdk_wifi_station_disconnect();
vTaskDelay(1);
}

if (esp_wifi_scan_start(NULL, true) == ESP_OK) {
Expand Down Expand Up @@ -959,7 +961,7 @@ static void wifi_config_server_on_settings_update_task(void* args) {
sdk_system_restart();
}

static int wifi_config_server_on_url(http_parser *parser, const char *data, size_t length) {
static int wifi_config_server_on_url(http_parser *parser, const char *data, unsigned int length) {
client_t *client = (client_t*) parser->data;

client->endpoint = ENDPOINT_UNKNOWN;
Expand All @@ -984,7 +986,7 @@ static int wifi_config_server_on_url(http_parser *parser, const char *data, size
return 0;
}

static int wifi_config_server_on_body(http_parser *parser, const char *data, size_t length) {
static int wifi_config_server_on_body(http_parser *parser, const char *data, unsigned int length) {
client_t *client = parser->data;

//client->body = realloc(client->body, client->body_length + length + 1);
Expand Down Expand Up @@ -1303,6 +1305,7 @@ static uint8_t wifi_config_connect(const uint8_t phy) {
#endif

sdk_wifi_station_disconnect();
vTaskDelay(1);

char* wifi_password = NULL;
sysparam_get_string(WIFI_STA_PASSWORD_SYSPARAM, &wifi_password);
Expand Down
2 changes: 1 addition & 1 deletion HAA/HAA_Installer/main/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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<br>Installer v@@@INSTALLER_VERSION@@@ @@@HAA_CHIP_NAME@@@@@@HAA_SINGLE_CORE_SUFIX@@@</h1>
</style></head><body><div class="container"><h1>Home Accessory Architect<br>Installer v@@@INSTALLER_VERSION@@@ @@@HAA_CHIP_NAME@@@@@@HAA_SINGLE_CORE_SUFIX@@@@@@HAA_XTAL26_SUFIX@@@</h1>
<h2>Please, support this project by <a href="https://paypal.me/ravensystem">donating here</a></h2>
<form action="/sn" method="post">
<div class="field required">
Expand Down
6 changes: 6 additions & 0 deletions HAA/HAA_Main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ if(HAA_SINGLE_CORE)
)
endif()

if(HAA_XTAL26)
list(APPEND EXTRA_COMPILE_OPTIONS
-DHAA_XTAL26
)
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(HAA_Main)

Expand Down
16 changes: 12 additions & 4 deletions HAA/HAA_Main/main/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "../../common/common_headers.h"

// Version
#define HAA_FIRMWARE_VERSION "12.7.3"
#define HAA_FIRMWARE_VERSION "12.8.0"
#define HAA_FIRMWARE_BETA_REVISION ""
#define HAA_FIRMWARE_CODENAME "Merlin"

Expand Down Expand Up @@ -85,20 +85,22 @@
#define INIT_STATE_INV_LAST (6)
#define INIT_STATE_LAST_STR "{\"s\":5}"

// JSON
// MEPLHAA Script
#define GENERAL_CONFIG "c"
#define MDNS_TTL "ttl"
#define MDNS_TTL_DEFAULT (4500)
#define MDNS_TTL_PERIOD_DEFAULT (2250)
#define CUSTOM_HOSTNAME "n"
#define CUSTOM_NTP_HOST "ntp"
#define NTP_DISABLE_STRING "0"
#define TIMEZONE "tz"
#define LOG_OUTPUT "o"
#define LOG_OUTPUT_TARGET "ot"
#define ALLOWED_SETUP_MODE_TIME "m"
#define STATUS_LED_GPIO "l"
#define INVERTED "i"
#define BUTTON_FILTER "f"
#define FLEX_FILTER_ARRAY "fl"
#define BUTTON_CONTINUOS_MODE "c"
#define PWMS_FREQ "q"
#define PWMH_FREQ_ARRAY "y"
Expand Down Expand Up @@ -416,6 +418,7 @@
#define WINDOW_COVER_STOP_FROM_CLOSING (5)
#define WINDOW_COVER_STOP_FROM_OPENING (6)
#define WINDOW_COVER_OBSTRUCTION (7)
#define WINDOW_COVER_SINGLE_INPUT (100)
#define WINDOW_COVER_TYPE_SET "w"
#define WINDOW_COVER_TYPE_DEFAULT (0)
#define WINDOW_COVER_TIME_OPEN_SET "o"
Expand Down Expand Up @@ -506,6 +509,7 @@
#define FM_SENSOR_TYPE_UART_PATTERN_TEXT (25)
#define FM_SENSOR_TYPE_DEFAULT FM_SENSOR_TYPE_FREE
#define FM_SENSOR_TYPE ch_group->num_i[0]
#define FM_SENSOR_TYPE_B ch_group_b->num_i[0]
#define FM_SENSOR_GPIO_ARRAY_SET "g"
#define FM_SENSOR_GPIO ch_group->num_i[1]
#define FM_SENSOR_GPIO_INT_TYPE ch_group->num_i[2]
Expand Down Expand Up @@ -544,6 +548,8 @@
#define FM_MATHS_GET_TIME_YEAR (-8)
#define FM_MATHS_GET_TIME_IS_SAVING (-9)
#define FM_MATHS_GEN_RANDOM_NUMBER (-10)
#define FM_MATHS_GET_UPTIME (-11)
#define FM_MATHS_GET_WIFI_RSSI (-12)
#define FM_MATHS_OPERATIONS ch_group->num_i[1]
#define FM_MATHS_FIRST_OPERATION (2)
#define FM_MATHS_INT ch_group->num_i
Expand All @@ -568,7 +574,9 @@
#define FM_I2C_VAL_OFFSET_SET "io"
#define FM_I2C_VAL_OFFSET_DEFAULT (0)
#define FM_I2C_BUS ch_group->num_i[3]
#define FM_I2C_BUS_B ch_group_b->num_i[3]
#define FM_I2C_ADDR ch_group->num_i[4]
#define FM_I2C_ADDR_B ch_group_b->num_i[4]
#define FM_I2C_REG_LEN ch_group->num_i[5]
#define FM_I2C_VAL_OFFSET ch_group->num_i[6]
#define FM_I2C_REG_FIRST (7)
Expand Down Expand Up @@ -749,15 +757,15 @@
#define SETUP_MODE_ACTIVATE_COUNT "z"
#define SETUP_MODE_DEFAULT_ACTIVATE_COUNT (8)
#define SETUP_MODE_TOGGLE_TIME_MS (1050)
#define CUSTOM_HAA_COMMAND "zc"
#define CUSTOM_HAA_COMMAND "ic"
#define HAA_SETUP_ACCESSORY_SET "s"

#define IRRF_CAPTURE_BUFFER_SIZE (2048)

#define ACTION_TASK_TYPE_UART (0)
#define ACTION_TASK_TYPE_NETWORK (1)
#define ACTION_TASK_TYPE_IRRF (2)
#define ACTION_TASK_MAX_ERRORS (6)
#define ACTION_TASK_MAX_ERRORS (10)

#define SAVE_STATES_TIMER ch_group_find_by_serv(SERV_TYPE_ROOT_DEVICE)->timer
#define WIFI_WATCHDOG_TIMER ch_group_find_by_serv(SERV_TYPE_ROOT_DEVICE)->timer2
Expand Down
Loading

0 comments on commit b83ea70

Please sign in to comment.