added custom HTTP REST API interface
This commit is contained in:
parent
5aff687cec
commit
979a68e475
|
|
@ -1 +1 @@
|
|||
Subproject commit 164580725651933150afb09431b262f05f50f14d
|
||||
Subproject commit d307a365a95771ed45edd945697cada343d639d6
|
||||
|
|
@ -3,7 +3,7 @@ dependencies:
|
|||
component_hash: null
|
||||
source:
|
||||
type: idf
|
||||
version: 4.4.4
|
||||
manifest_hash: 31dd4ec84ade1450fc168388f4adce2efacd1516170670735140bc772e9d72bd
|
||||
version: 4.4.5
|
||||
manifest_hash: cc4f7a08a6eeed39d05fbfb84ff3df9215bdf0009945794b887b5e99cbaee95b
|
||||
target: esp32
|
||||
version: 1.0.0
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
# See the build system documentation in IDF programming guide
|
||||
# for more information about component CMakeLists.txt files.
|
||||
|
||||
set(srcs main.c
|
||||
src/HTTPPrintCustom.c
|
||||
src/HTTPPostCustom.c
|
||||
src/MQTTCustom.c
|
||||
src/AppConfiguration.c
|
||||
src/CronTimers.c
|
||||
)
|
||||
set(include "include")
|
||||
|
||||
idf_component_register(
|
||||
SRCS "${srcs}"
|
||||
INCLUDE_DIRS ${include}
|
||||
SRC_DIRS "."
|
||||
"src"
|
||||
INCLUDE_DIRS "include"
|
||||
)
|
||||
30
main/include/Application.h
Normal file
30
main/include/Application.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* Copyright 2023 Bogdan Pilyugin
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* File name: Application.h
|
||||
* Project: webguiapp_ref_implement
|
||||
* Created on: 2023-06-10
|
||||
* Author: bogdan
|
||||
* Description:
|
||||
*/
|
||||
|
||||
#ifndef MAIN_INCLUDE_APPLICATION_H_
|
||||
#define MAIN_INCLUDE_APPLICATION_H_
|
||||
|
||||
#include "webguiapp.h"
|
||||
|
||||
HTTP_IO_RESULT HTTPPostCustomAPI(httpd_req_t *req, char *PostData);
|
||||
|
||||
|
||||
#endif /* MAIN_INCLUDE_APPLICATION_H_ */
|
||||
57
main/src/HTTPAPICustom.c
Normal file
57
main/src/HTTPAPICustom.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* Copyright 2023 Bogdan Pilyugin
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* File name: HTTPAPICustom.c
|
||||
* Project: webguiapp_ref_implement
|
||||
* Created on: 2023-06-10
|
||||
* Author: bogdan
|
||||
* Description:
|
||||
*/
|
||||
|
||||
#include "webguiapp.h"
|
||||
#include "jRead.h"
|
||||
#include "jWrite.h"
|
||||
#include "AppConfiguration.h"
|
||||
|
||||
#define USER_API_VER "1.00"
|
||||
|
||||
HTTP_IO_RESULT HTTPPostCustomAPI(httpd_req_t *req, char *PostData)
|
||||
{
|
||||
char data[1024];
|
||||
httpd_req_get_hdr_value_str(req, "Content-Type", (char*) data, 31);
|
||||
if (!memcmp(data, "application/json", sizeof("application/json")))
|
||||
{
|
||||
char key[32] = {0};
|
||||
struct jReadElement result;
|
||||
jRead(PostData, "", &result);
|
||||
if (result.dataType == JREAD_OBJECT)
|
||||
{
|
||||
jRead_string(PostData, "{'key'", key, sizeof(key), NULL);
|
||||
}
|
||||
|
||||
//ESP_LOGI(TAG, "JSON data:%s", PostData);
|
||||
jwOpen(data, sizeof(data), JW_OBJECT, JW_COMPACT);
|
||||
jwObj_string("apiver", USER_API_VER);
|
||||
jwObj_string("apitype", "userapi");
|
||||
jwObj_string("key", key);;
|
||||
jwObj_raw("result", "OK");
|
||||
jwEnd();
|
||||
jwClose();
|
||||
httpd_resp_sendstr(req, data);
|
||||
return HTTP_IO_DONE_API;
|
||||
}
|
||||
|
||||
httpd_resp_set_status(req, HTTPD_400);
|
||||
return HTTP_IO_DONE_API;
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
#include "webguiapp.h"
|
||||
#include "jRead.h"
|
||||
#include "AppConfiguration.h"
|
||||
#include "Application.h"
|
||||
#include "CronTimers.h"
|
||||
|
||||
const char pg_40[] = "index40.html";
|
||||
|
|
@ -30,6 +31,7 @@ const char pg_42[] = "index42.html";
|
|||
const char pg_43[] = "index43.html";
|
||||
const char pg_44[] = "index44.html";
|
||||
const char url_application[] = "application.html";
|
||||
const char url_userapi[] = "userapi";
|
||||
|
||||
static HTTP_IO_RESULT HTTPPostIndex40(httpd_req_t *req, char *PostData);
|
||||
static HTTP_IO_RESULT HTTPPostIndex42(httpd_req_t *req, char *PostData);
|
||||
|
|
@ -39,7 +41,8 @@ static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData);
|
|||
|
||||
HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData)
|
||||
{
|
||||
|
||||
if (!memcmp(filename, url_userapi, sizeof(url_userapi)))
|
||||
return HTTPPostCustomAPI(req, PostData);
|
||||
if (!memcmp(filename, pg_40, sizeof(pg_40)))
|
||||
return HTTPPostIndex40(req, PostData);
|
||||
if (!memcmp(filename, pg_42, sizeof(pg_42)))
|
||||
|
|
@ -54,6 +57,7 @@ HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, ch
|
|||
return HTTP_IO_DONE;
|
||||
}
|
||||
|
||||
|
||||
static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData)
|
||||
{
|
||||
char tmp[512];
|
||||
|
|
|
|||
26
sdkconfig
26
sdkconfig
|
|
@ -225,6 +225,7 @@ CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
|
|||
# CONFIG_TWAI_ERRATA_FIX_TX_INTR_LOST is not set
|
||||
# CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID is not set
|
||||
# CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT is not set
|
||||
# CONFIG_TWAI_ERRATA_FIX_LISTEN_ONLY_DOM is not set
|
||||
# end of TWAI configuration
|
||||
|
||||
#
|
||||
|
|
@ -280,9 +281,16 @@ CONFIG_ESP_TLS_USING_MBEDTLS=y
|
|||
#
|
||||
CONFIG_ESP32_REV_MIN_0=y
|
||||
# CONFIG_ESP32_REV_MIN_1 is not set
|
||||
# CONFIG_ESP32_REV_MIN_1_1 is not set
|
||||
# CONFIG_ESP32_REV_MIN_2 is not set
|
||||
# CONFIG_ESP32_REV_MIN_3 is not set
|
||||
# CONFIG_ESP32_REV_MIN_3_1 is not set
|
||||
CONFIG_ESP32_REV_MIN=0
|
||||
CONFIG_ESP32_REV_MIN_FULL=0
|
||||
CONFIG_ESP_REV_MIN_FULL=0
|
||||
CONFIG_ESP32_REV_MAX_FULL_STR_OPT=y
|
||||
CONFIG_ESP32_REV_MAX_FULL=399
|
||||
CONFIG_ESP_REV_MAX_FULL=399
|
||||
CONFIG_ESP32_DPORT_WORKAROUND=y
|
||||
# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
|
||||
|
|
@ -417,6 +425,7 @@ CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y
|
|||
# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
|
||||
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
|
||||
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
|
||||
# CONFIG_ESP_MAC_IGNORE_MAC_CRC_ERROR is not set
|
||||
# end of MAC Config
|
||||
|
||||
#
|
||||
|
|
@ -470,7 +479,10 @@ CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y
|
|||
# CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set
|
||||
CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20
|
||||
CONFIG_ESP_PHY_MAX_TX_POWER=20
|
||||
CONFIG_ESP_PHY_REDUCE_TX_POWER=y
|
||||
CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
|
||||
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
|
||||
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
|
||||
CONFIG_ESP_PHY_CALIBRATION_MODE=0
|
||||
# end of PHY
|
||||
|
||||
#
|
||||
|
|
@ -748,6 +760,7 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
|
|||
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
|
||||
# CONFIG_LWIP_NETIF_API is not set
|
||||
# CONFIG_LWIP_TCPIP_CORE_LOCKING is not set
|
||||
# CONFIG_LWIP_CHECK_THREAD_SAFETY is not set
|
||||
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
||||
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
||||
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
|
||||
|
|
@ -768,12 +781,15 @@ CONFIG_LWIP_IP6_FRAG=y
|
|||
# CONFIG_LWIP_ETHARP_TRUST_IP_MAC is not set
|
||||
CONFIG_LWIP_ESP_GRATUITOUS_ARP=y
|
||||
CONFIG_LWIP_GARP_TMR_INTERVAL=60
|
||||
CONFIG_LWIP_ESP_MLDV6_REPORT=y
|
||||
CONFIG_LWIP_MLDV6_TMR_INTERVAL=40
|
||||
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
|
||||
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
|
||||
# CONFIG_LWIP_DHCP_DISABLE_CLIENT_ID is not set
|
||||
CONFIG_LWIP_DHCP_DISABLE_VENDOR_CLASS_ID=y
|
||||
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
|
||||
CONFIG_LWIP_DHCP_OPTIONS_LEN=68
|
||||
CONFIG_LWIP_DHCP_COARSE_TIMER_SECS=1
|
||||
|
||||
#
|
||||
# DHCP server
|
||||
|
|
@ -1187,6 +1203,11 @@ CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
|
|||
# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set
|
||||
# end of Unity unit testing library
|
||||
|
||||
#
|
||||
# Root Hub configuration
|
||||
#
|
||||
# end of Root Hub configuration
|
||||
|
||||
#
|
||||
# Virtual file system
|
||||
#
|
||||
|
|
@ -1268,7 +1289,7 @@ CONFIG_TTN_PROVISION_UART_NUM=0
|
|||
# WebGUIApp
|
||||
#
|
||||
CONFIG_GPIO_RANGE_MIN=0
|
||||
CONFIG_GPIO_RANGE_MAX=36
|
||||
CONFIG_GPIO_RANGE_MAX=39
|
||||
CONFIG_DEVICE_MODEL_NAME="DEVICE MODEL NAME"
|
||||
CONFIG_WEBGUIAPP_HOSTNAME="DEVICE_HOSTNAME"
|
||||
CONFIG_WEBGUIAPP_USERNAME="user"
|
||||
|
|
@ -1497,7 +1518,6 @@ CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
|
|||
# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
|
||||
CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20
|
||||
CONFIG_ESP32_PHY_MAX_TX_POWER=20
|
||||
CONFIG_ESP32_REDUCE_PHY_TX_POWER=y
|
||||
# CONFIG_ESP32S2_PANIC_PRINT_HALT is not set
|
||||
CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y
|
||||
# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user