diff --git a/src/httpclient/http_client.c b/src/httpclient/http_client.c
index 35d7b3094..fb72274ba 100644
--- a/src/httpclient/http_client.c
+++ b/src/httpclient/http_client.c
@@ -353,7 +353,7 @@ int httpclient_send_header(httpclient_t *client, const char *url, int method, ht
}
if (client_data->post_buf != NULL) {
- snprintf(buf, HTTPCLIENT_SEND_BUF_SIZE, "Content-Length: %d\r\n", client_data->post_buf_len);
+ snprintf(buf, HTTPCLIENT_SEND_BUF_SIZE, "Content-Length: %u\r\n", client_data->post_buf_len);
httpclient_get_info(client, send_buf, &len, buf, os_strlen(buf));
if (client_data->post_content_type != NULL) {
@@ -454,14 +454,14 @@ int httpclient_recv(httpclient_t *client, char *buf, int min_len, int max_len, i
int httpclient_retrieve_content(httpclient_t *client, char *data, int len, uint32_t timeout_ms,
httpclient_data_t *client_data)
{
- int count = 0;
- int templen = 0;
- int crlf_pos;
+ //int count = 0;
+ //int templen = 0;
+ //int crlf_pos;
iotx_time_t timer;
- char * b_data = NULL;
+ //char * b_data = NULL;
- iotx_time_init(&timer);
- utils_time_countdown_ms(&timer, timeout_ms);
+ //iotx_time_init(&timer);
+ //utils_time_countdown_ms(&timer, timeout_ms);
/* Receive data */
log_debug("Current data len: %d\r\n", len);
@@ -481,6 +481,7 @@ int httpclient_retrieve_content(httpclient_t *client, char *data, int len, uint3
+#ifdef INCLUDE_OLD_FUNCTION
// called with data and len from header parser.
// called with len = 0 when getting more
int httpclient_retrieve_content_old(httpclient_t *client, char *data, int len, uint32_t timeout_ms,
@@ -687,6 +688,8 @@ int httpclient_retrieve_content_old(httpclient_t *client, char *data, int len, u
return SUCCESS_RETURN;
}
+#endif
+
int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_t timeout_ms,
httpclient_data_t *client_data)
diff --git a/src/httpclient/http_client.h b/src/httpclient/http_client.h
index f29187e1a..5e3952125 100644
--- a/src/httpclient/http_client.h
+++ b/src/httpclient/http_client.h
@@ -143,6 +143,7 @@ typedef struct httprequest_t_tag{
* @endcode
*/
int async_request(httprequest_t *request);
+void httpclient_set_custom_header(httpclient_t *client, char *header);
#ifdef __cplusplus
}
diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c
index c51f9176d..10310fb28 100644
--- a/src/httpserver/http_tcp_server.c
+++ b/src/httpserver/http_tcp_server.c
@@ -1,8 +1,10 @@
#include "../new_common.h"
+#include "ctype.h"
#include "lwip/sockets.h"
#include "lwip/ip_addr.h"
#include "lwip/inet.h"
#include "../logging/logging.h"
+#include "new_http.h"
static void tcp_server_thread( beken_thread_arg_t arg );
static void tcp_client_thread( beken_thread_arg_t arg );
@@ -29,11 +31,11 @@ static void tcp_client_thread( beken_thread_arg_t arg )
OSStatus err = kNoErr;
int fd = (int) arg;
int len = 0;
- fd_set readfds, errfds, readfds2;
+ //fd_set readfds, errfds, readfds2;
char *buf = NULL;
char *reply = NULL;
int replyBufferSize = 10000;
- int res;
+ //int res;
//char reply[8192];
//my_fd = fd;
diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c
index 04640bd89..908c35427 100644
--- a/src/httpserver/new_http.c
+++ b/src/httpserver/new_http.c
@@ -1,8 +1,11 @@
#include "../new_common.h"
+#include "str_pub.h"
#include "new_http.h"
#include "../new_pins.h"
+#include "../new_cfg.h"
+#include "../ota/ota.h"
/*
GET / HTTP/1.1
@@ -180,13 +183,15 @@ const char *htmlIndex = "";
-//const char *htmlPinRoles = "\
-//\
-//\
-//\
-//\
-//\
-//";
+/*
+const char *htmlPinRoles = "\
+\
+\
+\
+\
+\
+";
+*/
const char *htmlPinRoleNames[] = {
" ",
diff --git a/src/httpserver/new_http.h b/src/httpserver/new_http.h
index 21c3ff789..0b6b8a31c 100644
--- a/src/httpserver/new_http.h
+++ b/src/httpserver/new_http.h
@@ -8,6 +8,7 @@ extern const char htmlEnd[];
extern const char htmlReturnToMenu[];
int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize);
+void http_setup(char *o, const char *type);
// callback function for http
diff --git a/src/logging/logging.c b/src/logging/logging.c
index f3b525271..6f35ebcf0 100644
--- a/src/logging/logging.c
+++ b/src/logging/logging.c
@@ -208,7 +208,7 @@ void log_server_thread( beken_thread_arg_t arg )
}
if ( err != kNoErr )
- tcp_server_log( "Server listerner thread exit with err: %d", err );
+ addLog( "Server listerner thread exit with err: %d", err );
close( tcp_listen_fd );
rtos_delete_thread( NULL );
@@ -218,16 +218,8 @@ void log_server_thread( beken_thread_arg_t arg )
static char tcplogbuf[TCPLOGBUFSIZE];
static void log_client_thread( beken_thread_arg_t arg )
{
- OSStatus err = kNoErr;
int fd = (int) arg;
int len = 0;
- fd_set readfds, errfds, readfds2;
- char *buf = NULL;
- char *reply = NULL;
- int replyBufferSize = 128;
- int res;
-
-
while ( 1 ){
int count = getTcp(tcplogbuf, TCPLOGBUFSIZE);
if (count){
@@ -240,9 +232,7 @@ static void log_client_thread( beken_thread_arg_t arg )
rtos_delay_milliseconds(10);
}
-exit:
- if ( err != kNoErr )
- addLog( "TCP client thread exit with err: %d", err );
+ addLog( "TCP client thread exit with err: %d", len );
close( fd );
rtos_delete_thread( NULL );
diff --git a/src/new_cfg.h b/src/new_cfg.h
index e69de29bb..79d450177 100644
--- a/src/new_cfg.h
+++ b/src/new_cfg.h
@@ -0,0 +1,24 @@
+
+
+const char *CFG_GetDeviceName();
+const char *CFG_GetShortDeviceName();
+void CFG_CreateDeviceNameUnique();
+int CFG_GetMQTTPort();
+void CFG_SetMQTTPort(int p);
+void CFG_SetOpenAccessPoint();
+const char *CFG_GetWiFiSSID();
+const char *CFG_GetWiFiPass();
+void CFG_SetWiFiSSID(const char *s);
+void CFG_SetWiFiPass(const char *s);
+const char *CFG_GetMQTTHost();
+const char *CFG_GetMQTTBrokerName();
+const char *CFG_GetMQTTUserName();
+const char *CFG_GetMQTTPass();
+void CFG_SetMQTTHost(const char *s);
+void CFG_SetMQTTBrokerName(const char *s);
+void CFG_SetMQTTUserName(const char *s);
+void CFG_SetMQTTPass(const char *s);
+void CFG_SaveWiFi();
+void CFG_LoadWiFi();
+void CFG_SaveMQTT();
+void CFG_LoadMQTT();
diff --git a/src/new_common.c b/src/new_common.c
index 786c2847a..4e046f9b0 100644
--- a/src/new_common.c
+++ b/src/new_common.c
@@ -1,5 +1,5 @@
#include "new_common.h"
-
+#include "ctype.h"
// returns amount of space left in buffer (0=overflow happened)
int strcat_safe(char *tg, const char *src, int tgMaxLen) {
@@ -49,10 +49,12 @@ int strcpy_safe(char *tg, const char *src, int tgMaxLen) {
return tgMaxLen-curOfs;
}
-void urldecode2_safe(char *dst, const char *src, int maxDstLen)
+void urldecode2_safe(char *dst, const char *srcin, int maxDstLen)
{
int curLen = 1;
- char a, b;
+ int a, b;
+ // avoid signing issues in conversion to int for isxdigit(int c)
+ const unsigned char *src = (const unsigned char *)srcin;
while (*src) {
if(curLen>=maxDstLen)
break;
diff --git a/src/ota/ota.c b/src/ota/ota.c
index 96b38a921..44c88336d 100644
--- a/src/ota/ota.c
+++ b/src/ota/ota.c
@@ -2,6 +2,7 @@
#include "../new_common.h"
#include "typedef.h"
#include "flash_pub.h"
+//#include "flash.h"
#include "../logging/logging.h"
#include "../httpclient/http_client.h"
@@ -11,12 +12,14 @@ int sectorlen = 0;
unsigned int addr = 0xff000;
#define SECTOR_SIZE 0x1000
static void store_sector(unsigned int addr, unsigned char *data);
+extern void flash_protection_op(UINT8 mode,PROTECT_TYPE type);
+
int init_ota(unsigned int startaddr){
flash_init();
- flash_protection_op(FLASH_XTX_16M_SR_WRITE_ENABLE, FLASH_PROTECT_NONE);
+ flash_protection_op(FLASH_XTX_16M_SR_WRITE_ENABLE, FLASH_PROTECT_NONE);
if (startaddr > 0xff000){
if (sector){
addLog("aborting OTS, sector already non-null\n");
@@ -46,7 +49,7 @@ void close_ota(){
os_free(sector);
sector = (void *)0;
- flash_protection_op(FLASH_XTX_16M_SR_WRITE_ENABLE, FLASH_UNPROTECT_LAST_BLOCK);
+ flash_protection_op(FLASH_XTX_16M_SR_WRITE_ENABLE, FLASH_UNPROTECT_LAST_BLOCK);
}
void add_otadata(unsigned char *data, int len){
@@ -104,7 +107,7 @@ int myhttpclientcallback(httprequest_t* request){
break;
case 1: // data
if (request->client_data.response_buf_filled){
- unsigned char *d = request->client_data.response_buf;
+ unsigned char *d = (unsigned char *)request->client_data.response_buf;
int l = request->client_data.response_buf_filled;
add_otadata(d, l);
}
diff --git a/src/printnetinfo/printnetinfo.c b/src/printnetinfo/printnetinfo.c
index 62af33d2a..37eae5e5c 100644
--- a/src/printnetinfo/printnetinfo.c
+++ b/src/printnetinfo/printnetinfo.c
@@ -1,3 +1,7 @@
+
+
+#include "../new_common.h"
+#include "str_pub.h"
#include "wlan_ui_pub.h"
#include "../logging/logging.h"
diff --git a/src/printnetinfo/printnetinfo.h b/src/printnetinfo/printnetinfo.h
new file mode 100644
index 000000000..3c03fff4c
--- /dev/null
+++ b/src/printnetinfo/printnetinfo.h
@@ -0,0 +1 @@
+void print_network_info();
\ No newline at end of file
diff --git a/src/tuya_device.c b/src/tuya_device.c
index 6206dcd6f..d28457a76 100644
--- a/src/tuya_device.c
+++ b/src/tuya_device.c
@@ -29,18 +29,29 @@
#include "lwip/ip_addr.h"
#include "lwip/inet.h"
+#include "mem_pub.h"
+#include "str_pub.h"
+#include "ethernet_intf.h"
+
/* Private includes ----------------------------------------------------------*/
#include "tuya_device.h"
#include "httpserver/new_http.h"
#include "new_pins.h"
+#include "new_cfg.h"
#include "logging/logging.h"
#include "httpserver/http_tcp_server.h"
+#include "printnetinfo/printnetinfo.h"
#include "../../beken378/func/key/multi_button.h"
#include "../../beken378/app/config/param_config.h"
#include "lwip/apps/mqtt.h"
+#undef os_printf
+#undef PR_DEBUG
+#undef PR_NOTICE
+#undef Malloc
+#undef Free
#define os_printf addLog
#define PR_DEBUG addLog
#define PR_NOTICE addLog
@@ -90,7 +101,7 @@ void connect_to_wifi(const char *oob_ssid,const char *connect_key)
os_memset( &wNetConfigAdv, 0x0, sizeof(network_InitTypeDef_adv_st) );
os_strcpy((char*)wNetConfigAdv.ap_info.ssid, oob_ssid);
- hwaddr_aton("48:ee:0c:48:93:12", wNetConfigAdv.ap_info.bssid);
+ hwaddr_aton("48:ee:0c:48:93:12", (u8 *)wNetConfigAdv.ap_info.bssid);
wNetConfigAdv.ap_info.security = SECURITY_TYPE_WPA2_MIXED;
wNetConfigAdv.ap_info.channel = 5;
@@ -204,11 +215,13 @@ int g_incoming_channel_mqtt = 0;
static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags)
{
int iValue;
- const struct mqtt_connect_client_info_t* client_info = (const struct mqtt_connect_client_info_t*)arg;
+ // unused - left here as example
+ //const struct mqtt_connect_client_info_t* client_info = (const struct mqtt_connect_client_info_t*)arg;
+
//PR_NOTICE("MQTT client in mqtt_incoming_data_cb\n");
PR_NOTICE("MQTT client in mqtt_incoming_data_cb data is %s for ch %i\n",data,g_incoming_channel_mqtt);
- iValue = atoi(data);
+ iValue = atoi((char *)data);
CHANNEL_Set(g_incoming_channel_mqtt,iValue,0);
// PR_NOTICE(("MQTT client \"%s\" data cb: len %d, flags %d\n", client_info->client_id, (int)len, (int)flags));
@@ -217,7 +230,9 @@ static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t f
static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len)
{
const char *p;
- const struct mqtt_connect_client_info_t* client_info = (const struct mqtt_connect_client_info_t*)arg;
+ // unused - left here as example
+ //const struct mqtt_connect_client_info_t* client_info = (const struct mqtt_connect_client_info_t*)arg;
+
//PR_NOTICE("MQTT client in mqtt_incoming_publish_cb\n");
PR_NOTICE("MQTT client in mqtt_incoming_publish_cb topic %s\n",topic);
// TODO: better
@@ -239,7 +254,7 @@ mqtt_request_cb(void *arg, err_t err)
{
const struct mqtt_connect_client_info_t* client_info = (const struct mqtt_connect_client_info_t*)arg;
- PR_NOTICE(("MQTT client \"%s\" request cb: err %d\n", client_info->client_id, (int)err));
+ PR_NOTICE("MQTT client \"%s\" request cb: err %d\n", client_info->client_id, (int)err);
}
static void mqtt_sub_request_cb(void *arg, err_t result)
{
@@ -251,7 +266,6 @@ static void mqtt_sub_request_cb(void *arg, err_t result)
void example_do_connect(mqtt_client_t *client);
static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status)
{
- int i;
char tmp[64];
const char *baseName;
err_t err = ERR_OK;
@@ -411,9 +425,9 @@ static int setup_wifi_open_access_point(void)
PR_NOTICE("no flash configuration, use default\r\n");
mac = (u8*)&ap_info.bssid.array;
- // this is MAC for Access Point, it's different than Client one
- // see wifi_get_mac_address source
- wifi_get_mac_address(mac, CONFIG_ROLE_AP);
+ // this is MAC for Access Point, it's different than Client one
+ // see wifi_get_mac_address source
+ wifi_get_mac_address((char *)mac, CONFIG_ROLE_AP);
ap_info.chann = APP_DRONE_DEF_CHANNEL;
ap_info.cipher_suite = 0;
//os_memcpy(ap_info.ssid.array, APP_DRONE_DEF_SSID, os_strlen(APP_DRONE_DEF_SSID));