Compare commits
5 Commits
60f8299f59
...
0687a6a981
| Author | SHA1 | Date | |
|---|---|---|---|
| 0687a6a981 | |||
| 94af947d1f | |||
| e8e8876686 | |||
| 2547be508c | |||
| ca082595d9 |
|
|
@ -240,6 +240,7 @@ typedef struct
|
||||||
|
|
||||||
|
|
||||||
cron_timer_t Timers[CONFIG_WEBGUIAPP_CRON_NUMBER];
|
cron_timer_t Timers[CONFIG_WEBGUIAPP_CRON_NUMBER];
|
||||||
|
bool bIsCRONEnabled;
|
||||||
|
|
||||||
} SYS_CONFIG;
|
} SYS_CONFIG;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ typedef struct
|
||||||
time_t time;
|
time_t time;
|
||||||
int msgType;
|
int msgType;
|
||||||
int payloadType;
|
int payloadType;
|
||||||
|
char payloadName[32];
|
||||||
void *payload;
|
void *payload;
|
||||||
unsigned char sha256[32];
|
unsigned char sha256[32];
|
||||||
} parsedData;
|
} parsedData;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ const char *exec_errors[] = {
|
||||||
"param COMMAND not found",
|
"param COMMAND not found",
|
||||||
"object not exists",
|
"object not exists",
|
||||||
"command not exists",
|
"command not exists",
|
||||||
"handler not set"
|
"handler not set",
|
||||||
|
"param ARGUMENT not found",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -158,6 +159,8 @@ static int ExecCommandParse(char *cmd)
|
||||||
return 2; //ERROR_OBJECT_NOT_PARSED
|
return 2; //ERROR_OBJECT_NOT_PARSED
|
||||||
if (!com)
|
if (!com)
|
||||||
return 3; //ERROR_ACTION_NOT_PARSED
|
return 3; //ERROR_ACTION_NOT_PARSED
|
||||||
|
if (!arg)
|
||||||
|
return 7; //ERROR_ACTION_NOT_PARSED
|
||||||
|
|
||||||
for (int idx = 0; idx < CONFIG_WEBGUIAPP_MAX_OBJECTS_NUM; idx++)
|
for (int idx = 0; idx < CONFIG_WEBGUIAPP_MAX_OBJECTS_NUM; idx++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <CronTimers.h>
|
#include <CronTimers.h>
|
||||||
|
#include "SysConfiguration.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "webguiapp.h"
|
#include "webguiapp.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
@ -42,6 +43,7 @@ char* GetCronError()
|
||||||
|
|
||||||
void custom_cron_job_callback(cron_job *job)
|
void custom_cron_job_callback(cron_job *job)
|
||||||
{
|
{
|
||||||
|
if (GetSysConf()->bIsCRONEnabled)
|
||||||
ExecCommand(((cron_timer_t*) job->data)->exec);
|
ExecCommand(((cron_timer_t*) job->data)->exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,6 +98,7 @@ static void ExecuteLastAction(obj_struct_t *objarr)
|
||||||
if (minimal != -1)
|
if (minimal != -1)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Run previous CRON \"%s\" with delta %d", GetSysConf()->Timers[minimal].exec, (int )delta);
|
ESP_LOGI(TAG, "Run previous CRON \"%s\" with delta %d", GetSysConf()->Timers[minimal].exec, (int )delta);
|
||||||
|
if (GetSysConf()->bIsCRONEnabled)
|
||||||
ExecCommand(GetSysConf()->Timers[minimal].exec);
|
ExecCommand(GetSysConf()->Timers[minimal].exec);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
src/MQTT.c
34
src/MQTT.c
|
|
@ -161,42 +161,12 @@ esp_err_t ExternalServiceMQTTSend(char *servname, char *data, int len, int idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_ERROR_JSON 256
|
#define MAX_ERROR_JSON 256
|
||||||
/*
|
static char resp[256];
|
||||||
|
static char JSONMess[1024];
|
||||||
mqtt_app_err_t PublicTestMQTT(int idx)
|
mqtt_app_err_t PublicTestMQTT(int idx)
|
||||||
{
|
{
|
||||||
char tmp[10];
|
char tmp[10];
|
||||||
char resp[256];
|
|
||||||
char JSONMess[512];
|
|
||||||
struct jWriteControl jwc;
|
|
||||||
jwOpen(&jwc, JSONMess, MAX_ERROR_JSON, JW_OBJECT, JW_PRETTY);
|
|
||||||
time_t now;
|
|
||||||
time(&now);
|
|
||||||
jwObj_int(&jwc, "time", (unsigned int) now);
|
|
||||||
jwObj_string(&jwc, "event", "MQTT_TEST_MESSAGE)");
|
|
||||||
strcpy(resp, "mqtt://");
|
|
||||||
strcat(resp, GetSysConf()->mqttStation[idx].ServerAddr);
|
|
||||||
itoa(GetSysConf()->mqttStation[idx].ServerPort, tmp, 10);
|
|
||||||
strcat(resp, ":");
|
|
||||||
strcat(resp, tmp);
|
|
||||||
jwObj_string(&jwc, "url", resp);
|
|
||||||
ComposeTopic(resp, idx, SERVICE_NAME, UPLINK_SUBTOPIC);
|
|
||||||
jwObj_string(&jwc, "tx_topic", resp);
|
|
||||||
ComposeTopic(resp, idx, SERVICE_NAME, DOWNLINK_SUBTOPIC);
|
|
||||||
jwObj_string(&jwc, "rx_topic", resp);
|
|
||||||
jwEnd(&jwc);
|
|
||||||
jwClose(&jwc);
|
|
||||||
mqtt_app_err_t merr = API_OK;
|
|
||||||
if (SysServiceMQTTSend(JSONMess, strlen(JSONMess), idx) != ESP_OK)
|
|
||||||
merr = API_INTERNAL_ERR;
|
|
||||||
return merr;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
mqtt_app_err_t PublicTestMQTT(int idx)
|
|
||||||
{
|
|
||||||
char tmp[10];
|
|
||||||
char resp[256];
|
|
||||||
char JSONMess[1024];
|
|
||||||
struct jWriteControl jwc;
|
struct jWriteControl jwc;
|
||||||
jwOpen(&jwc, JSONMess, 1024 - 64, JW_OBJECT, JW_COMPACT);
|
jwOpen(&jwc, JSONMess, 1024 - 64, JW_OBJECT, JW_COMPACT);
|
||||||
jwObj_object(&jwc, "data");
|
jwObj_object(&jwc, "data");
|
||||||
|
|
|
||||||
|
|
@ -450,6 +450,8 @@ const rest_var_t SystemVariables[] =
|
||||||
{ 0, "lat", &funct_lat, VAR_FUNCT, RW, 0, 0 },
|
{ 0, "lat", &funct_lat, VAR_FUNCT, RW, 0, 0 },
|
||||||
{ 0, "lon", &funct_lon, VAR_FUNCT, RW, 0, 0 },
|
{ 0, "lon", &funct_lon, VAR_FUNCT, RW, 0, 0 },
|
||||||
|
|
||||||
|
{ 0, "cronrecs_enab", &SysConfig.bIsCRONEnabled, VAR_BOOL, RW, 0, 1 },
|
||||||
|
|
||||||
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
|
||||||
{ 0, "mqtt_1_enab", &SysConfig.mqttStation[0].Flags1.bIsGlobalEnabled, VAR_BOOL, RW, 0, 1 },
|
{ 0, "mqtt_1_enab", &SysConfig.mqttStation[0].Flags1.bIsGlobalEnabled, VAR_BOOL, RW, 0, 1 },
|
||||||
{ 0, "mqtt_1_serv", &SysConfig.mqttStation[0].ServerAddr, VAR_STRING, RW, 3, 63 },
|
{ 0, "mqtt_1_serv", &SysConfig.mqttStation[0].ServerAddr, VAR_STRING, RW, 3, 63 },
|
||||||
|
|
@ -550,7 +552,7 @@ const rest_var_t SystemVariables[] =
|
||||||
{ 0, "serial_enab", &SysConfig.serialSettings.Flags.IsSerialEnabled, VAR_BOOL, RW, 0, 1 },
|
{ 0, "serial_enab", &SysConfig.serialSettings.Flags.IsSerialEnabled, VAR_BOOL, RW, 0, 1 },
|
||||||
{ 0, "serial_bridge", &SysConfig.serialSettings.Flags.IsBridgeEnabled, VAR_BOOL, RW, 0, 1 },
|
{ 0, "serial_bridge", &SysConfig.serialSettings.Flags.IsBridgeEnabled, VAR_BOOL, RW, 0, 1 },
|
||||||
{ 0, "serial_mode", &funct_serial_mode, VAR_FUNCT, R, 1, 2 },
|
{ 0, "serial_mode", &funct_serial_mode, VAR_FUNCT, R, 1, 2 },
|
||||||
{ 0, "serial_baud", &SysConfig.serialSettings.BaudRate, VAR_INT, RW, 1200, 4096000 },
|
{ 0, "serial_baud", &SysConfig.serialSettings.BaudRate, VAR_INT, RW, 1200, 8192000 },
|
||||||
|
|
||||||
{ 0, "serial_bits", &SysConfig.serialSettings.DataBits, VAR_INT, RW, 0, 3 },
|
{ 0, "serial_bits", &SysConfig.serialSettings.DataBits, VAR_INT, RW, 0, 3 },
|
||||||
{ 0, "serial_parity", &SysConfig.serialSettings.Parity, VAR_INT, RW, 0, 3 },
|
{ 0, "serial_parity", &SysConfig.serialSettings.Parity, VAR_INT, RW, 0, 3 },
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
#define TAG "serial_port"
|
#define TAG "serial_port"
|
||||||
#define UART_READ_TOUT (100) // 3.5T * 8 = 28 ticks, TOUT=3 -> ~24..33 ticks
|
#define UART_READ_TOUT (80) // 3.5T * 8 = 28 ticks, TOUT=3 -> ~24..33 ticks
|
||||||
#define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
|
#define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
|
||||||
|
|
||||||
#define UART_TX_QUEUE_SIZE (5)
|
#define UART_TX_QUEUE_SIZE (5)
|
||||||
|
|
@ -119,7 +119,6 @@ void serial_RX_task(void *arg)
|
||||||
case UART_DATA:
|
case UART_DATA:
|
||||||
if (event.timeout_flag)
|
if (event.timeout_flag)
|
||||||
{
|
{
|
||||||
|
|
||||||
bzero(rxbuf, CONFIG_WEBGUIAPP_UART_BUF_SIZE);
|
bzero(rxbuf, CONFIG_WEBGUIAPP_UART_BUF_SIZE);
|
||||||
uart_get_buffered_data_len(CONFIG_WEBGUIAPP_UART_PORT_NUM, (size_t *)&buffered_size);
|
uart_get_buffered_data_len(CONFIG_WEBGUIAPP_UART_PORT_NUM, (size_t *)&buffered_size);
|
||||||
if (buffered_size)
|
if (buffered_size)
|
||||||
|
|
@ -136,7 +135,6 @@ void serial_RX_task(void *arg)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ReceiveHandlerAPI();
|
ReceiveHandlerAPI();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -218,8 +216,7 @@ void static serial_TX_task(void *arg)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
xQueueReceive(UARTtxQueueHandle, &DSS, portMAX_DELAY);
|
xQueueReceive(UARTtxQueueHandle, &DSS, portMAX_DELAY);
|
||||||
if (uart_write_bytes(CONFIG_WEBGUIAPP_UART_PORT_NUM, DSS.raw_data_ptr, DSS.data_length)
|
if (uart_write_bytes(CONFIG_WEBGUIAPP_UART_PORT_NUM, DSS.raw_data_ptr, DSS.data_length) != DSS.data_length)
|
||||||
!= DSS.data_length)
|
|
||||||
ESP_LOGE(TAG, "RS485 write data failure");
|
ESP_LOGE(TAG, "RS485 write data failure");
|
||||||
free(DSS.raw_data_ptr);
|
free(DSS.raw_data_ptr);
|
||||||
if (uart_wait_tx_done(CONFIG_WEBGUIAPP_UART_PORT_NUM, pdMS_TO_TICKS(1000)) != ESP_OK)
|
if (uart_wait_tx_done(CONFIG_WEBGUIAPP_UART_PORT_NUM, pdMS_TO_TICKS(1000)) != ESP_OK)
|
||||||
|
|
@ -231,50 +228,85 @@ void InitSerialPort(void)
|
||||||
{
|
{
|
||||||
uart_config_t uart_config = {
|
uart_config_t uart_config = {
|
||||||
.baud_rate = GetSysConf()->serialSettings.BaudRate,
|
.baud_rate = GetSysConf()->serialSettings.BaudRate,
|
||||||
.data_bits = UART_DATA_7_BITS,
|
.data_bits = UART_DATA_8_BITS,
|
||||||
.parity = UART_PARITY_EVEN,
|
.parity = UART_PARITY_DISABLE,
|
||||||
.stop_bits = UART_STOP_BITS_1,
|
.stop_bits = UART_STOP_BITS_1,
|
||||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||||
.source_clk = UART_SCLK_APB,
|
.source_clk = UART_SCLK_APB,
|
||||||
};
|
};
|
||||||
|
|
||||||
//uart_config.data_bits = (uint8_t)GetSysConf()->serialSettings.DataBits;
|
//uart_config.data_bits = (uint8_t)GetSysConf()->serialSettings.DataBits;
|
||||||
//uart_config.parity = (uint8_t) GetSysConf()->serialSettings.Parity;
|
|
||||||
|
switch (GetSysConf()->serialSettings.DataBits)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
uart_config.data_bits = UART_DATA_5_BITS;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
uart_config.data_bits = UART_DATA_6_BITS;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
uart_config.data_bits = UART_DATA_7_BITS;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
uart_config.data_bits = UART_DATA_8_BITS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch (GetSysConf()->serialSettings.Parity)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
uart_config.parity = UART_PARITY_DISABLE;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
uart_config.parity = UART_PARITY_EVEN;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
uart_config.parity = UART_PARITY_ODD;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch (GetSysConf()->serialSettings.StopBits)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
uart_config.stop_bits = UART_STOP_BITS_1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
uart_config.stop_bits = UART_STOP_BITS_1_5;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
uart_config.stop_bits = UART_STOP_BITS_2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// uart_config.stop_bits = (uint8_t) GetSysConf()->serialSettings.StopBits;
|
// uart_config.stop_bits = (uint8_t) GetSysConf()->serialSettings.StopBits;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "UART data_bits:%d parity:%d stop_bits:%d",
|
ESP_LOGI(TAG, "UART data_bits:%d parity:%d stop_bits:%d", GetSysConf()->serialSettings.DataBits, GetSysConf()->serialSettings.Parity, GetSysConf()->serialSettings.StopBits);
|
||||||
GetSysConf()->serialSettings.DataBits,
|
|
||||||
GetSysConf()->serialSettings.Parity,
|
|
||||||
GetSysConf()->serialSettings.StopBits);
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_driver_install(CONFIG_WEBGUIAPP_UART_PORT_NUM, CONFIG_WEBGUIAPP_UART_BUF_SIZE * 2, 0, 20, &uart_event_queue, 0));
|
||||||
uart_driver_install(CONFIG_WEBGUIAPP_UART_PORT_NUM, CONFIG_WEBGUIAPP_UART_BUF_SIZE * 2, 0, 20, &uart_event_queue, 0));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_param_config(CONFIG_WEBGUIAPP_UART_PORT_NUM, &uart_config));
|
||||||
ESP_ERROR_CHECK(uart_param_config(CONFIG_WEBGUIAPP_UART_PORT_NUM, &uart_config));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_set_pin(CONFIG_WEBGUIAPP_UART_PORT_NUM, CONFIG_WEBGUIAPP_UART_TXD, CONFIG_WEBGUIAPP_UART_RXD, CONFIG_WEBGUIAPP_UART_RTS, -1));
|
||||||
ESP_ERROR_CHECK(uart_set_pin(CONFIG_WEBGUIAPP_UART_PORT_NUM,
|
|
||||||
CONFIG_WEBGUIAPP_UART_TXD, CONFIG_WEBGUIAPP_UART_RXD, CONFIG_WEBGUIAPP_UART_RTS, -1));
|
|
||||||
|
|
||||||
#ifdef CONFIG_WEBGUIAPP_UART_MODE_UART
|
#ifdef CONFIG_WEBGUIAPP_UART_MODE_UART
|
||||||
ESP_ERROR_CHECK(uart_set_mode(CONFIG_WEBGUIAPP_UART_PORT_NUM, UART_MODE_UART));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_set_mode(CONFIG_WEBGUIAPP_UART_PORT_NUM, UART_MODE_UART));
|
||||||
#elif CONFIG_WEBGUIAPP_UART_MODE_RS485
|
#elif CONFIG_WEBGUIAPP_UART_MODE_RS485
|
||||||
ESP_ERROR_CHECK(uart_set_mode(CONFIG_WEBGUIAPP_UART_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_set_mode(CONFIG_WEBGUIAPP_UART_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESP_ERROR_CHECK(uart_enable_rx_intr(CONFIG_WEBGUIAPP_UART_PORT_NUM));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_enable_rx_intr(CONFIG_WEBGUIAPP_UART_PORT_NUM));
|
||||||
ESP_ERROR_CHECK(uart_set_rx_timeout(CONFIG_WEBGUIAPP_UART_PORT_NUM, UART_READ_TOUT));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(uart_set_rx_timeout(CONFIG_WEBGUIAPP_UART_PORT_NUM, UART_READ_TOUT));
|
||||||
//ESP_ERROR_CHECK(uart_enable_pattern_det_baud_intr(CONFIG_UART_PORT_NUM, '+', PATTERN_CHR_NUM, 9, 0, 0));
|
// ESP_ERROR_CHECK_WITHOUT_ABORT(uart_enable_pattern_det_baud_intr(CONFIG_UART_PORT_NUM, '+', PATTERN_CHR_NUM, 9, 0, 0));
|
||||||
uart_pattern_queue_reset(CONFIG_WEBGUIAPP_UART_PORT_NUM, 20);
|
uart_pattern_queue_reset(CONFIG_WEBGUIAPP_UART_PORT_NUM, 20);
|
||||||
|
|
||||||
UARTtxQueueHandle = NULL;
|
UARTtxQueueHandle = NULL;
|
||||||
UARTtxQueueHandle = xQueueCreateStatic(UART_TX_QUEUE_SIZE,
|
UARTtxQueueHandle = xQueueCreateStatic(UART_TX_QUEUE_SIZE, sizeof(UART_DATA_SEND_STRUCT), UARTtxQueueStorageArea, &xStaticUARTtxQueue);
|
||||||
sizeof(UART_DATA_SEND_STRUCT),
|
|
||||||
UARTtxQueueStorageArea,
|
|
||||||
&xStaticUARTtxQueue);
|
|
||||||
|
|
||||||
xTaskCreate(serial_TX_task, "serial_tx", 1024 * 2, (void *)0, 7, NULL);
|
xTaskCreate(serial_TX_task, "serial_tx", 1024 * 2, (void *)0, 7, NULL);
|
||||||
xTaskCreate(serial_RX_task, "serial_rx", 1024 * 4, (void *)0, 12, NULL);
|
xTaskCreate(serial_RX_task, "serial_rx", 1024 * 4, (void *)0, 12, NULL);
|
||||||
ESP_LOGI(TAG, "Serial port initialized on UART%d with baudrate %d", CONFIG_WEBGUIAPP_UART_PORT_NUM,
|
ESP_LOGI(TAG, "Serial port initialized on UART%d with baudrate %d", CONFIG_WEBGUIAPP_UART_PORT_NUM, GetSysConf()->serialSettings.BaudRate);
|
||||||
GetSysConf()->serialSettings.BaudRate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "webguiapp.h"
|
#include "webguiapp.h"
|
||||||
#include "SystemApplication.h"
|
#include "SystemApplication.h"
|
||||||
#include "mbedtls/md.h"
|
#include "mbedtls/md.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define TAG "SysComm"
|
#define TAG "SysComm"
|
||||||
|
|
||||||
|
|
@ -59,6 +60,7 @@ static sys_error_code PayloadDefaultTypeHandler(data_message_t *MSG)
|
||||||
jwObj_string(&jwc, "time", time);
|
jwObj_string(&jwc, "time", time);
|
||||||
jwObj_int(&jwc, "msgtype", DATA_MESSAGE_TYPE_RESPONSE);
|
jwObj_int(&jwc, "msgtype", DATA_MESSAGE_TYPE_RESPONSE);
|
||||||
jwObj_int(&jwc, "payloadtype", MSG->parsedData.payloadType);
|
jwObj_int(&jwc, "payloadtype", MSG->parsedData.payloadType);
|
||||||
|
jwObj_string(&jwc, "payloadname", MSG->parsedData.payloadName);
|
||||||
jwObj_object(&jwc, "payload");
|
jwObj_object(&jwc, "payload");
|
||||||
jwObj_int(&jwc, "applytype", 0);
|
jwObj_int(&jwc, "applytype", 0);
|
||||||
jwObj_object(&jwc, "variables");
|
jwObj_object(&jwc, "variables");
|
||||||
|
|
@ -73,9 +75,7 @@ static sys_error_code PayloadDefaultTypeHandler(data_message_t *MSG)
|
||||||
|
|
||||||
for (int i = 0; i < result.elements; ++i)
|
for (int i = 0; i < result.elements; ++i)
|
||||||
{
|
{
|
||||||
jRead_string(MSG->inputDataBuffer, "{'data'{'payload'{'variables'{*", VarName,
|
jRead_string(MSG->inputDataBuffer, "{'data'{'payload'{'variables'{*", VarName, VAR_MAX_NAME_LENGTH, &i);
|
||||||
VAR_MAX_NAME_LENGTH,
|
|
||||||
&i);
|
|
||||||
const char parsevar[] = "{'data'{'payload'{'variables'{'";
|
const char parsevar[] = "{'data'{'payload'{'variables'{'";
|
||||||
char expr[sizeof(parsevar) + VAR_MAX_NAME_LENGTH];
|
char expr[sizeof(parsevar) + VAR_MAX_NAME_LENGTH];
|
||||||
strcpy(expr, parsevar);
|
strcpy(expr, parsevar);
|
||||||
|
|
@ -101,7 +101,6 @@ static sys_error_code PayloadDefaultTypeHandler(data_message_t *MSG)
|
||||||
tp = VAR_ERROR;
|
tp = VAR_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Read variables
|
{ // Read variables
|
||||||
|
|
@ -114,7 +113,6 @@ static sys_error_code PayloadDefaultTypeHandler(data_message_t *MSG)
|
||||||
jwObj_string(&jwc, VarName, VarValue);
|
jwObj_string(&jwc, VarName, VarValue);
|
||||||
else
|
else
|
||||||
jwObj_raw(&jwc, VarName, VarValue);
|
jwObj_raw(&jwc, VarName, VarValue);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(VarValue);
|
free(VarValue);
|
||||||
}
|
}
|
||||||
|
|
@ -132,8 +130,7 @@ static sys_error_code PayloadDefaultTypeHandler(data_message_t *MSG)
|
||||||
if (datap)
|
if (datap)
|
||||||
{
|
{
|
||||||
datap += sizeof("\"data\":") - 1;
|
datap += sizeof("\"data\":") - 1;
|
||||||
SHA256hmacHash((unsigned char*) datap, strlen(datap), (unsigned char*) "mykey", sizeof("mykey"),
|
SHA256hmacHash((unsigned char *)datap, strlen(datap), (unsigned char *)"mykey", sizeof("mykey"), MSG->parsedData.sha256);
|
||||||
MSG->parsedData.sha256);
|
|
||||||
unsigned char sha_print[32 * 2 + 1];
|
unsigned char sha_print[32 * 2 + 1];
|
||||||
BytesToStr(MSG->parsedData.sha256, sha_print, 32);
|
BytesToStr(MSG->parsedData.sha256, sha_print, 32);
|
||||||
sha_print[32 * 2] = 0x00;
|
sha_print[32 * 2] = 0x00;
|
||||||
|
|
@ -169,7 +166,6 @@ static sys_error_code PayloadDefaultTypeHandler(data_message_t *MSG)
|
||||||
default:
|
default:
|
||||||
return SYS_ERROR_PARSE_APPLYTYPE;
|
return SYS_ERROR_PARSE_APPLYTYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -194,8 +190,7 @@ static sys_error_code DataHeaderParser(data_message_t *MSG)
|
||||||
jRead_string(MSG->inputDataBuffer, "{'data'", hashbuf, MSG->inputDataLength, 0);
|
jRead_string(MSG->inputDataBuffer, "{'data'", hashbuf, MSG->inputDataLength, 0);
|
||||||
if (strlen(hashbuf) > 0)
|
if (strlen(hashbuf) > 0)
|
||||||
{
|
{
|
||||||
SHA256hmacHash((unsigned char*) hashbuf, strlen(hashbuf), (unsigned char*) "mykey", sizeof("mykey"),
|
SHA256hmacHash((unsigned char *)hashbuf, strlen(hashbuf), (unsigned char *)"mykey", sizeof("mykey"), MSG->parsedData.sha256);
|
||||||
MSG->parsedData.sha256);
|
|
||||||
unsigned char sha_print[32 * 2 + 1];
|
unsigned char sha_print[32 * 2 + 1];
|
||||||
BytesToStr(MSG->parsedData.sha256, sha_print, 32);
|
BytesToStr(MSG->parsedData.sha256, sha_print, 32);
|
||||||
sha_print[32 * 2] = 0x00;
|
sha_print[32 * 2] = 0x00;
|
||||||
|
|
@ -210,7 +205,6 @@ static sys_error_code DataHeaderParser(data_message_t *MSG)
|
||||||
return SYS_ERROR_PARSE_DATA;
|
return SYS_ERROR_PARSE_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
jRead(MSG->inputDataBuffer, "{'signature'", &result);
|
jRead(MSG->inputDataBuffer, "{'signature'", &result);
|
||||||
if (result.elements == 1)
|
if (result.elements == 1)
|
||||||
{
|
{
|
||||||
|
|
@ -223,8 +217,6 @@ static sys_error_code DataHeaderParser(data_message_t *MSG)
|
||||||
else
|
else
|
||||||
return SYS_ERROR_PARSE_SIGNATURE;
|
return SYS_ERROR_PARSE_SIGNATURE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Extract 'messidx' or throw exception
|
// Extract 'messidx' or throw exception
|
||||||
jRead(MSG->inputDataBuffer, "{'data'{'msgid'", &result);
|
jRead(MSG->inputDataBuffer, "{'data'{'msgid'", &result);
|
||||||
if (result.elements == 1)
|
if (result.elements == 1)
|
||||||
|
|
@ -274,6 +266,14 @@ static sys_error_code DataHeaderParser(data_message_t *MSG)
|
||||||
else
|
else
|
||||||
return SYS_ERROR_PARSE_PAYLOADTYPE;
|
return SYS_ERROR_PARSE_PAYLOADTYPE;
|
||||||
|
|
||||||
|
jRead(MSG->inputDataBuffer, "{'data'{'payloadname'", &result);
|
||||||
|
if (result.elements == 1)
|
||||||
|
{
|
||||||
|
jRead_string(MSG->inputDataBuffer, "{'data'{'payloadname'", MSG->parsedData.payloadName, 31, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
strcpy(MSG->parsedData.payloadName, "notset");
|
||||||
|
|
||||||
sys_error_code err = SYS_ERROR_HANDLER_NOT_SET;
|
sys_error_code err = SYS_ERROR_HANDLER_NOT_SET;
|
||||||
switch (MSG->parsedData.payloadType)
|
switch (MSG->parsedData.payloadType)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -452,6 +452,7 @@ esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_DNS3_ADDRESS_DEFAULT, (esp_ip4_addr_t*) &C
|
||||||
strcpy(Conf->Timers[i].exec, "OBJECT,ACTION,ARGUMENTS");
|
strcpy(Conf->Timers[i].exec, "OBJECT,ACTION,ARGUMENTS");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Conf->bIsCRONEnabled = true;
|
||||||
|
|
||||||
#ifdef CONFIG_WEBGUIAPP_ASTRO_ENABLE
|
#ifdef CONFIG_WEBGUIAPP_ASTRO_ENABLE
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,7 @@ void resonnectWithDelay(void *agr)
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_handler(void *arg, esp_event_base_t event_base,
|
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||||
int32_t event_id,
|
|
||||||
void *event_data)
|
|
||||||
{
|
{
|
||||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||||
{
|
{
|
||||||
|
|
@ -116,7 +114,6 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
||||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_BEACON_TIMEOUT)
|
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_BEACON_TIMEOUT)
|
||||||
{
|
{
|
||||||
ESP_LOGW(TAG, "STA beacon timeout");
|
ESP_LOGW(TAG, "STA beacon timeout");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||||
|
|
@ -165,17 +162,13 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
||||||
static void wifi_init_softap(void *pvParameter)
|
static void wifi_init_softap(void *pvParameter)
|
||||||
{
|
{
|
||||||
char if_key_str[24];
|
char if_key_str[24];
|
||||||
esp_netif_inherent_config_t esp_netif_conf = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP()
|
esp_netif_inherent_config_t esp_netif_conf = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
|
||||||
;
|
|
||||||
|
|
||||||
strcpy(if_key_str, "WIFI_AP_USER");
|
strcpy(if_key_str, "WIFI_AP_USER");
|
||||||
esp_netif_conf.if_key = if_key_str;
|
esp_netif_conf.if_key = if_key_str;
|
||||||
esp_netif_conf.route_prio = AP_PRIO;
|
esp_netif_conf.route_prio = AP_PRIO;
|
||||||
|
|
||||||
esp_netif_config_t cfg_netif = {
|
esp_netif_config_t cfg_netif = { .base = &esp_netif_conf, .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP };
|
||||||
.base = &esp_netif_conf,
|
|
||||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP
|
|
||||||
};
|
|
||||||
|
|
||||||
ap_netif = esp_netif_new(&cfg_netif);
|
ap_netif = esp_netif_new(&cfg_netif);
|
||||||
assert(ap_netif);
|
assert(ap_netif);
|
||||||
|
|
@ -196,15 +189,10 @@ static void wifi_init_softap(void *pvParameter)
|
||||||
esp_netif_attach_wifi_ap(ap_netif);
|
esp_netif_attach_wifi_ap(ap_netif);
|
||||||
esp_wifi_set_default_wifi_ap_handlers();
|
esp_wifi_set_default_wifi_ap_handlers();
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT()
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
;
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL));
|
||||||
ESP_EVENT_ANY_ID,
|
|
||||||
&event_handler,
|
|
||||||
NULL,
|
|
||||||
NULL));
|
|
||||||
|
|
||||||
wifi_config_t wifi_config = {
|
wifi_config_t wifi_config = {
|
||||||
.ap = {
|
.ap = {
|
||||||
|
|
@ -220,8 +208,7 @@ static void wifi_init_softap(void *pvParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(wifi_config.ap.ssid, GetSysConf()->wifiSettings.ApSSID, strlen(GetSysConf()->wifiSettings.ApSSID));
|
memcpy(wifi_config.ap.ssid, GetSysConf()->wifiSettings.ApSSID, strlen(GetSysConf()->wifiSettings.ApSSID));
|
||||||
memcpy(wifi_config.ap.password, GetSysConf()->wifiSettings.ApSecurityKey,
|
memcpy(wifi_config.ap.password, GetSysConf()->wifiSettings.ApSecurityKey, strlen(GetSysConf()->wifiSettings.ApSecurityKey));
|
||||||
strlen(GetSysConf()->wifiSettings.ApSecurityKey));
|
|
||||||
wifi_config.ap.ssid_len = strlen(GetSysConf()->wifiSettings.ApSSID);
|
wifi_config.ap.ssid_len = strlen(GetSysConf()->wifiSettings.ApSSID);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
||||||
|
|
@ -244,10 +231,7 @@ static void wifi_init_sta(void *pvParameter)
|
||||||
strcpy(if_key_str, "WIFI_STA_USER");
|
strcpy(if_key_str, "WIFI_STA_USER");
|
||||||
esp_netif_conf.if_key = if_key_str;
|
esp_netif_conf.if_key = if_key_str;
|
||||||
esp_netif_conf.route_prio = STA_PRIO;
|
esp_netif_conf.route_prio = STA_PRIO;
|
||||||
esp_netif_config_t cfg_netif = {
|
esp_netif_config_t cfg_netif = { .base = &esp_netif_conf, .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA };
|
||||||
.base = &esp_netif_conf,
|
|
||||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA
|
|
||||||
};
|
|
||||||
sta_netif = esp_netif_new(&cfg_netif);
|
sta_netif = esp_netif_new(&cfg_netif);
|
||||||
assert(sta_netif);
|
assert(sta_netif);
|
||||||
|
|
||||||
|
|
@ -273,22 +257,13 @@ static void wifi_init_sta(void *pvParameter)
|
||||||
esp_netif_attach_wifi_station(sta_netif);
|
esp_netif_attach_wifi_station(sta_netif);
|
||||||
esp_wifi_set_default_wifi_sta_handlers();
|
esp_wifi_set_default_wifi_sta_handlers();
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT()
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
;
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
|
||||||
esp_event_handler_instance_t instance_any_id;
|
esp_event_handler_instance_t instance_any_id;
|
||||||
esp_event_handler_instance_t instance_got_ip;
|
esp_event_handler_instance_t instance_got_ip;
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));
|
||||||
ESP_EVENT_ANY_ID,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip));
|
||||||
&event_handler,
|
|
||||||
NULL,
|
|
||||||
&instance_any_id));
|
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
|
||||||
IP_EVENT_STA_GOT_IP,
|
|
||||||
&event_handler,
|
|
||||||
NULL,
|
|
||||||
&instance_got_ip));
|
|
||||||
|
|
||||||
wifi_config_t wifi_config = {
|
wifi_config_t wifi_config = {
|
||||||
.sta = {
|
.sta = {
|
||||||
|
|
@ -304,8 +279,9 @@ static void wifi_init_sta(void *pvParameter)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
memcpy(wifi_config.sta.ssid, GetSysConf()->wifiSettings.InfSSID, strlen(GetSysConf()->wifiSettings.InfSSID));
|
memcpy(wifi_config.sta.ssid, GetSysConf()->wifiSettings.InfSSID, strlen(GetSysConf()->wifiSettings.InfSSID));
|
||||||
memcpy(wifi_config.sta.password, GetSysConf()->wifiSettings.InfSecurityKey,
|
memcpy(wifi_config.sta.password, GetSysConf()->wifiSettings.InfSecurityKey, strlen(GetSysConf()->wifiSettings.InfSecurityKey));
|
||||||
strlen(GetSysConf()->wifiSettings.InfSecurityKey));
|
|
||||||
|
esp_netif_set_hostname(sta_netif, GetSysConf()->NetBIOSName);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||||
|
|
@ -323,17 +299,13 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
{
|
{
|
||||||
// BEGIN AP MODE IF
|
// BEGIN AP MODE IF
|
||||||
char ap_if_key_str[24];
|
char ap_if_key_str[24];
|
||||||
esp_netif_inherent_config_t ap_esp_netif_conf = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP()
|
esp_netif_inherent_config_t ap_esp_netif_conf = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
|
||||||
;
|
|
||||||
|
|
||||||
strcpy(ap_if_key_str, "WIFI_AP_USER");
|
strcpy(ap_if_key_str, "WIFI_AP_USER");
|
||||||
ap_esp_netif_conf.if_key = ap_if_key_str;
|
ap_esp_netif_conf.if_key = ap_if_key_str;
|
||||||
ap_esp_netif_conf.route_prio = AP_PRIO;
|
ap_esp_netif_conf.route_prio = AP_PRIO;
|
||||||
|
|
||||||
esp_netif_config_t cfg_netif = {
|
esp_netif_config_t cfg_netif = { .base = &ap_esp_netif_conf, .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP };
|
||||||
.base = &ap_esp_netif_conf,
|
|
||||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP
|
|
||||||
};
|
|
||||||
|
|
||||||
ap_netif = esp_netif_new(&cfg_netif);
|
ap_netif = esp_netif_new(&cfg_netif);
|
||||||
assert(ap_netif);
|
assert(ap_netif);
|
||||||
|
|
@ -345,10 +317,7 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
strcpy(sta_if_key_str, "WIFI_STA_USER");
|
strcpy(sta_if_key_str, "WIFI_STA_USER");
|
||||||
staesp_netif_conf.if_key = sta_if_key_str;
|
staesp_netif_conf.if_key = sta_if_key_str;
|
||||||
staesp_netif_conf.route_prio = STA_PRIO;
|
staesp_netif_conf.route_prio = STA_PRIO;
|
||||||
esp_netif_config_t sta_cfg_netif = {
|
esp_netif_config_t sta_cfg_netif = { .base = &staesp_netif_conf, .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA };
|
||||||
.base = &staesp_netif_conf,
|
|
||||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA
|
|
||||||
};
|
|
||||||
sta_netif = esp_netif_new(&sta_cfg_netif);
|
sta_netif = esp_netif_new(&sta_cfg_netif);
|
||||||
assert(sta_netif);
|
assert(sta_netif);
|
||||||
// END STA MODE IF
|
// END STA MODE IF
|
||||||
|
|
@ -370,8 +339,7 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
esp_netif_attach_wifi_ap(ap_netif);
|
esp_netif_attach_wifi_ap(ap_netif);
|
||||||
esp_wifi_set_default_wifi_ap_handlers();
|
esp_wifi_set_default_wifi_ap_handlers();
|
||||||
|
|
||||||
wifi_init_config_t ap_cfg = WIFI_INIT_CONFIG_DEFAULT()
|
wifi_init_config_t ap_cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
;
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&ap_cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&ap_cfg));
|
||||||
wifi_config_t ap_wifi_config = {
|
wifi_config_t ap_wifi_config = {
|
||||||
|
|
@ -393,8 +361,7 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(ap_wifi_config.ap.ssid, GetSysConf()->wifiSettings.ApSSID, strlen(GetSysConf()->wifiSettings.ApSSID));
|
memcpy(ap_wifi_config.ap.ssid, GetSysConf()->wifiSettings.ApSSID, strlen(GetSysConf()->wifiSettings.ApSSID));
|
||||||
memcpy(ap_wifi_config.ap.password, GetSysConf()->wifiSettings.ApSecurityKey,
|
memcpy(ap_wifi_config.ap.password, GetSysConf()->wifiSettings.ApSecurityKey, strlen(GetSysConf()->wifiSettings.ApSecurityKey));
|
||||||
strlen(GetSysConf()->wifiSettings.ApSecurityKey));
|
|
||||||
ap_wifi_config.ap.ssid_len = strlen(GetSysConf()->wifiSettings.ApSSID);
|
ap_wifi_config.ap.ssid_len = strlen(GetSysConf()->wifiSettings.ApSSID);
|
||||||
// END AP MODE CONFIGURATION
|
// END AP MODE CONFIGURATION
|
||||||
|
|
||||||
|
|
@ -421,22 +388,13 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
esp_netif_attach_wifi_station(sta_netif);
|
esp_netif_attach_wifi_station(sta_netif);
|
||||||
esp_wifi_set_default_wifi_sta_handlers();
|
esp_wifi_set_default_wifi_sta_handlers();
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT()
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
;
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
|
||||||
esp_event_handler_instance_t instance_any_id;
|
esp_event_handler_instance_t instance_any_id;
|
||||||
esp_event_handler_instance_t instance_got_ip;
|
esp_event_handler_instance_t instance_got_ip;
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));
|
||||||
ESP_EVENT_ANY_ID,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip));
|
||||||
&event_handler,
|
|
||||||
NULL,
|
|
||||||
&instance_any_id));
|
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
|
||||||
IP_EVENT_STA_GOT_IP,
|
|
||||||
&event_handler,
|
|
||||||
NULL,
|
|
||||||
&instance_got_ip));
|
|
||||||
|
|
||||||
wifi_config_t sta_wifi_config = {
|
wifi_config_t sta_wifi_config = {
|
||||||
.sta = {
|
.sta = {
|
||||||
|
|
@ -454,10 +412,15 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
memcpy(sta_wifi_config.sta.ssid, GetSysConf()->wifiSettings.InfSSID, strlen(GetSysConf()->wifiSettings.InfSSID));
|
memcpy(sta_wifi_config.sta.ssid, GetSysConf()->wifiSettings.InfSSID, strlen(GetSysConf()->wifiSettings.InfSSID));
|
||||||
memcpy(sta_wifi_config.sta.password, GetSysConf()->wifiSettings.InfSecurityKey,
|
memcpy(sta_wifi_config.sta.password, GetSysConf()->wifiSettings.InfSecurityKey, strlen(GetSysConf()->wifiSettings.InfSecurityKey));
|
||||||
strlen(GetSysConf()->wifiSettings.InfSecurityKey));
|
|
||||||
// END STA MODE CONFIGURATION
|
// END STA MODE CONFIGURATION
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_netif_set_hostname(sta_netif, "test_TEST"));
|
||||||
|
ESP_ERROR_CHECK(esp_netif_set_hostname(ap_netif, GetSysConf()->NetBIOSName));
|
||||||
|
char name[32];
|
||||||
|
esp_netif_get_hostname(sta_netif, &name);
|
||||||
|
ESP_LOGW(TAG, "Net bios name set to %s", name);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_wifi_config));
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_wifi_config));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_wifi_config));
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_wifi_config));
|
||||||
|
|
@ -471,8 +434,7 @@ static void wifi_init_apsta(void *pvParameter)
|
||||||
|
|
||||||
wifi_country_t CC;
|
wifi_country_t CC;
|
||||||
esp_wifi_get_country(&CC);
|
esp_wifi_get_country(&CC);
|
||||||
ESP_LOGI(TAG, "Country code %.*s, start_ch=%d, total_ch=%d, max power %d", 3, CC.cc, CC.schan, CC.nchan,
|
ESP_LOGI(TAG, "Country code %.*s, start_ch=%d, total_ch=%d, max power %d", 3, CC.cc, CC.schan, CC.nchan, CC.max_tx_power);
|
||||||
CC.max_tx_power);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "wifi_init_softap_sta finished");
|
ESP_LOGI(TAG, "wifi_init_softap_sta finished");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
|
|
@ -488,16 +450,17 @@ void WiFiConnect(void)
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RECONNECT_INTERVAL_AP 60
|
#define RECONNECT_INTERVAL_AP 30
|
||||||
#define RECONNECT_INTERVAL_STA 30
|
#define RECONNECT_INTERVAL_STA 30
|
||||||
|
#define RECONNECT_FAST_ATTEMPTS 5
|
||||||
#define WAITIP_INTERVAL 10
|
#define WAITIP_INTERVAL 10
|
||||||
|
|
||||||
static void WiFiControlTask(void *arg)
|
static void WiFiControlTask(void *arg)
|
||||||
{
|
{
|
||||||
// WiFi init and start block
|
// WiFi init and start block
|
||||||
|
static int attempts = 0;
|
||||||
static int reconnect_counter;
|
static int reconnect_counter;
|
||||||
reconnect_counter =
|
reconnect_counter = 5;
|
||||||
(GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA) ? RECONNECT_INTERVAL_STA : RECONNECT_INTERVAL_AP;
|
|
||||||
static int waitip_counter = WAITIP_INTERVAL;
|
static int waitip_counter = WAITIP_INTERVAL;
|
||||||
// s_wifi_event_group = xEventGroupCreate();
|
// s_wifi_event_group = xEventGroupCreate();
|
||||||
switch (GetSysConf()->wifiSettings.WiFiMode)
|
switch (GetSysConf()->wifiSettings.WiFiMode)
|
||||||
|
|
@ -520,6 +483,7 @@ static void WiFiControlTask(void *arg)
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
if (isWiFiConnected)
|
if (isWiFiConnected)
|
||||||
{
|
{
|
||||||
|
attempts = 0;
|
||||||
reconnect_counter = RECONNECT_INTERVAL_STA;
|
reconnect_counter = RECONNECT_INTERVAL_STA;
|
||||||
if (!isWiFiGotIp)
|
if (!isWiFiGotIp)
|
||||||
{
|
{
|
||||||
|
|
@ -532,16 +496,19 @@ static void WiFiControlTask(void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isWiFiFail)
|
if (isWiFiFail)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (--reconnect_counter <= 0 && !isScanExecuting)
|
if (--reconnect_counter <= 0 && !isScanExecuting)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "WiFi STA started, reconnecting to AP...");
|
ESP_LOGI(TAG, "WiFi STA started, reconnecting to AP...");
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
reconnect_counter =
|
if (++attempts <= RECONNECT_FAST_ATTEMPTS)
|
||||||
(GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA) ?
|
reconnect_counter = 5;
|
||||||
RECONNECT_INTERVAL_STA : RECONNECT_INTERVAL_AP;
|
else
|
||||||
|
reconnect_counter = (GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA) ? RECONNECT_INTERVAL_STA : RECONNECT_INTERVAL_AP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TempAPCounter > 0)
|
if (TempAPCounter > 0)
|
||||||
{
|
{
|
||||||
if (--TempAPCounter <= 0)
|
if (--TempAPCounter <= 0)
|
||||||
|
|
@ -555,7 +522,6 @@ static void WiFiControlTask(void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWiFiConnected)
|
if (isWiFiConnected)
|
||||||
|
|
@ -639,4 +605,3 @@ int GetAPClientsNumber()
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user