lora setting from web implemented

This commit is contained in:
Bogdan Pilyugin 2023-03-07 14:38:56 +02:00
parent 9d2f6dc3b4
commit 28cdda4bc7
2 changed files with 58 additions and 26 deletions

View File

@ -23,6 +23,7 @@
#include "HTTPServer.h"
#include "LoRaWAN.h"
#include "Helpers.h"
static const char *TAG = "HTTPServerPost";
@ -97,7 +98,7 @@ static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, c
static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
{
char tmp[32];
char tmp[33];
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
bool TempIsETHEnabled = false;
@ -218,6 +219,30 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
}
#endif
#if CONFIG_WEBGUIAPP_LORAWAN_ENABLE
bool TempIsLoRaEnabled = false;
if (httpd_query_key_value(PostData, "lren", tmp, sizeof(tmp)) == ESP_OK)
{
if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsLoRaEnabled = true;
}
if (httpd_query_key_value(PostData, "lrdvid", tmp, sizeof(tmp)) == ESP_OK)
{
if (strlen(tmp) == 16)
StrToBytesLen((unsigned char*) tmp, (unsigned char*) GetSysConf()->lorawanSettings.DevEui, 16);
}
if (httpd_query_key_value(PostData, "lrapid", tmp, sizeof(tmp)) == ESP_OK)
{
if (strlen(tmp) == 16)
StrToBytesLen((unsigned char*) tmp, (unsigned char*) GetSysConf()->lorawanSettings.AppEui, 16);
}
if (httpd_query_key_value(PostData, "lrapkey", tmp, sizeof(tmp)) == ESP_OK)
{
if (strlen(tmp) == 32)
StrToBytesLen((unsigned char*) tmp, (unsigned char*) GetSysConf()->lorawanSettings.AppKey, 32);
}
#endif
if (httpd_query_key_value(PostData, "wifisc", tmp, 4) == ESP_OK)
{
if (!strcmp(tmp, (const char*) "prs"))
@ -259,6 +284,13 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled = TempIsGSMEnabled;
#endif
}
else if (!strcmp(tmp, (const char*) "lora"))
{
#if CONFIG_WEBGUIAPP_LORAWAN_ENABLE
GetSysConf()->lorawanSettings.Flags1.bIsLoRaWANEnabled = TempIsLoRaEnabled;
#endif
}
if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
{

View File

@ -62,6 +62,8 @@ void regLoRaUserReceiveHandler(
esp_err_t LORASendData(LORA_DATA_SEND_STRUCT *pdss)
{
if (LORAMessagesQueueHandle == NULL)
return ESP_ERR_INVALID_ARG;
char *ptr = (char*) malloc(MESSAGE_LENGTH);
if (ptr)
{
@ -93,8 +95,8 @@ void messageReceived(const uint8_t *message, size_t length, ttn_port_t port)
ESP_LOGI(TAG, "Received=%s", P);
}
#endif
if(LoRaUserReceiveHandler != NULL)
LoRaUserReceiveHandler((char*)message, length, (int)port);
if (LoRaUserReceiveHandler != NULL)
LoRaUserReceiveHandler((char*) message, length, (int) port);
}
@ -128,7 +130,6 @@ void LoRaWANTransportTask(void *pvParameter)
}
}
void LoRaWANRejoin(void)
{
ttn_rejoin();
@ -174,7 +175,6 @@ void LoRaWANInitJoinTask(void *pvParameter)
}
#endif
void LoRaWANStart(void)
{
#ifdef CONFIG_WEBGUIAPP_LORAWAN_ENABLE