优化升级
This commit is contained in:
parent
410018accb
commit
150f485b6a
@ -28,6 +28,9 @@
|
|||||||
#define IOT_LAMP_DEVICE_GET_BATTERY "GetBattery"
|
#define IOT_LAMP_DEVICE_GET_BATTERY "GetBattery"
|
||||||
#define IOT_LAMP_DEVICE_OTA "ota"
|
#define IOT_LAMP_DEVICE_OTA "ota"
|
||||||
|
|
||||||
|
#define IOT_LAMP_DEVICE_VERSION "1.0.4"
|
||||||
|
#define IOT_LAMP_DEVICE_OTA_CHECK_URL "http://106.52.233.130:8888/ir58/ir58.json"
|
||||||
|
|
||||||
void lamp_init(){
|
void lamp_init(){
|
||||||
//ws2812_init();
|
//ws2812_init();
|
||||||
}
|
}
|
||||||
@ -86,7 +89,8 @@ cJSON* iot_lamp_get_device_desc(){
|
|||||||
|
|
||||||
|
|
||||||
cJSON *methods_ota = cJSON_CreateObject();
|
cJSON *methods_ota = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(methods_ota, "description", "升级拍拍灯软件[必须要用户二次确认]");
|
//[警告:此操作将导致设备完全关闭,请慎重使用]
|
||||||
|
cJSON_AddStringToObject(methods_ota, "description", "升级拍拍灯最新软件[必须要用户二次确认]");
|
||||||
|
|
||||||
|
|
||||||
//cJSON_AddStringToObject(SetBrightness, "type", "number");
|
//cJSON_AddStringToObject(SetBrightness, "type", "number");
|
||||||
@ -111,15 +115,17 @@ void iot_lamp_report_state(int brightness){
|
|||||||
int bk_https_ota_download(const char *url);
|
int bk_https_ota_download(const char *url);
|
||||||
void bk_https_start_download(beken_thread_arg_t arg) {
|
void bk_https_start_download(beken_thread_arg_t arg) {
|
||||||
int ret;
|
int ret;
|
||||||
ret = bk_http_ota_download("http://106.52.233.130:8888/ir58_ota.rbl");
|
char *ota_url = (char*)arg;
|
||||||
|
BK_LOGE(TAG,"ota_url %s\n",ota_url);
|
||||||
|
ret = bk_http_ota_download(ota_url);
|
||||||
//ret = bk_https_ota_download("https://xiaozhi.xa-poka.com/xiaozhi/otaMag/download/59cc091e-eaf3-417d-a524-d5e3d95883f4");
|
//ret = bk_https_ota_download("https://xiaozhi.xa-poka.com/xiaozhi/otaMag/download/59cc091e-eaf3-417d-a524-d5e3d95883f4");
|
||||||
if(ret != BK_OK) {
|
if(ret != BK_OK) {
|
||||||
os_printf("%s download fail, ret:%d\r\n", __func__, ret);
|
os_printf("%s download fail, ret:%d\r\n", __func__, ret);
|
||||||
}
|
}
|
||||||
rtos_delete_thread(NULL);
|
rtos_delete_thread(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void https_ota_start(void)
|
void https_ota_start(char *url)
|
||||||
{
|
{
|
||||||
UINT32 ret;
|
UINT32 ret;
|
||||||
|
|
||||||
@ -128,7 +134,7 @@ void https_ota_start(void)
|
|||||||
"https_ota",
|
"https_ota",
|
||||||
(beken_thread_function_t)bk_https_start_download,
|
(beken_thread_function_t)bk_https_start_download,
|
||||||
5120,
|
5120,
|
||||||
0);
|
url);
|
||||||
|
|
||||||
if (kNoErr != ret)
|
if (kNoErr != ret)
|
||||||
os_printf("https_ota_start failed\r\n");
|
os_printf("https_ota_start failed\r\n");
|
||||||
@ -136,6 +142,132 @@ void https_ota_start(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int iot_lamp_check_ota(){
|
||||||
|
int ret = 0;
|
||||||
|
struct webclient_session* session = NULL;
|
||||||
|
unsigned char *buffer = NULL;
|
||||||
|
int bytes_read, resp_status;
|
||||||
|
int content_length = -1;
|
||||||
|
char *url = NULL;
|
||||||
|
|
||||||
|
url = web_strdup(IOT_LAMP_DEVICE_OTA_CHECK_URL);
|
||||||
|
if(url == NULL)
|
||||||
|
{
|
||||||
|
BK_LOGE(TAG,"no memory for create get request uri buffer.\n");
|
||||||
|
return BK_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = (unsigned char *) web_malloc(1024);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
BK_LOGE(TAG,"no memory for receive buffer.\n");
|
||||||
|
|
||||||
|
goto __exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create webclient session and set header response size */
|
||||||
|
session = webclient_session_create(1024);
|
||||||
|
if (session == NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send GET request by default header */
|
||||||
|
if ((resp_status = webclient_get(session, url)) != 200)
|
||||||
|
{
|
||||||
|
BK_LOGE(TAG,"webclient GET request failed, response(%d) error.\n", resp_status);
|
||||||
|
ret = BK_ERR_STATE;
|
||||||
|
goto __exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
BK_LOGI(TAG,"webclient get response data: \n");
|
||||||
|
|
||||||
|
content_length = webclient_content_length_get(session);
|
||||||
|
if (content_length < 0)
|
||||||
|
{
|
||||||
|
BK_LOGI(TAG,"webclient GET request type is chunked.\n");
|
||||||
|
do
|
||||||
|
{
|
||||||
|
bytes_read = webclient_read(session, (void *)buffer, 1024);
|
||||||
|
if (bytes_read <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (1);
|
||||||
|
|
||||||
|
BK_LOGI(TAG,"\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int content_pos = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
bytes_read = webclient_read(session, (void *)buffer,
|
||||||
|
content_length - content_pos > 1024 ?
|
||||||
|
1024 : content_length - content_pos);
|
||||||
|
if (bytes_read <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
content_pos += bytes_read;
|
||||||
|
BK_LOGE(TAG,"%s bytes_read:%d content_pos:%d\n", __func__, bytes_read, content_pos);
|
||||||
|
} while (content_pos < content_length);
|
||||||
|
|
||||||
|
if (content_pos != content_length) {
|
||||||
|
BK_LOGE(TAG,"%s error! recv:%d content_length:%d\n", __func__, content_pos, content_length);
|
||||||
|
ret = BK_ERR_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BK_LOGE(TAG,"%s recv:%s \n", __func__,buffer);
|
||||||
|
if(content_length >0){
|
||||||
|
cJSON* ota = cJSON_Parse((char*)buffer);
|
||||||
|
if(ota!=NULL){
|
||||||
|
char *version = cJSON_GetObjectItem(ota, "version")->valuestring;
|
||||||
|
char *otafile = cJSON_GetObjectItem(ota, "otafile")->valuestring;
|
||||||
|
|
||||||
|
BK_LOGE(TAG,"%s ota->current:%s \n", __func__,IOT_LAMP_DEVICE_VERSION);
|
||||||
|
|
||||||
|
BK_LOGE(TAG,"%s ota->version:%s \n", __func__,version);
|
||||||
|
BK_LOGE(TAG,"%s ota->otafile:%s \n", __func__,otafile);
|
||||||
|
if (!strcmp(version, IOT_LAMP_DEVICE_VERSION) == 0){
|
||||||
|
|
||||||
|
BK_LOGE(TAG,"%s do ota!!! \n",version);
|
||||||
|
ws2812_led_start_ota();
|
||||||
|
https_ota_start(otafile);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
BK_LOGE(TAG,"%s device version is lasted:%s \n",version);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
__exit:
|
||||||
|
if (session)
|
||||||
|
{
|
||||||
|
webclient_close(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer)
|
||||||
|
{
|
||||||
|
web_free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url)
|
||||||
|
{
|
||||||
|
web_free(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
|
void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
|
||||||
|
|
||||||
//设置亮度
|
//设置亮度
|
||||||
@ -157,8 +289,9 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
|
|||||||
}
|
}
|
||||||
else if (strcmp(cmd, IOT_LAMP_DEVICE_OTA) == 0){
|
else if (strcmp(cmd, IOT_LAMP_DEVICE_OTA) == 0){
|
||||||
LOGE("invoke ota !!\n");
|
LOGE("invoke ota !!\n");
|
||||||
ws2812_led_start_ota();
|
iot_lamp_check_ota();
|
||||||
https_ota_start();
|
//ws2812_led_start_ota();
|
||||||
|
//https_ota_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,7 @@ static mode_info_t mode_3[49] = {
|
|||||||
{-1, 20},
|
{-1, 20},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {65, 60, 55, 50, 45, 40, 35,30,25};
|
||||||
static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {25, 30, 35, 40, 45, 50, 55,60,60};
|
static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {25, 30, 35, 40, 45, 50, 55,60,60};
|
||||||
//static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = { 30, 35, 40, 45, 50, 55};
|
//static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = { 30, 35, 40, 45, 50, 55};
|
||||||
|
|
||||||
@ -255,8 +256,7 @@ void sleep_helper_init(){
|
|||||||
//GPIO
|
//GPIO
|
||||||
gpio_dev_unmap(GPIO_44);
|
gpio_dev_unmap(GPIO_44);
|
||||||
gpio_dev_unmap(GPIO_45);
|
gpio_dev_unmap(GPIO_45);
|
||||||
bk_gpio_enable_output(44);
|
|
||||||
bk_gpio_enable_output(45);
|
|
||||||
|
|
||||||
gpio_dev_unmap(GPIO_50);
|
gpio_dev_unmap(GPIO_50);
|
||||||
bk_gpio_enable_input(GPIO_50);
|
bk_gpio_enable_input(GPIO_50);
|
||||||
@ -292,24 +292,7 @@ void sleep_helper_init(){
|
|||||||
|
|
||||||
void sleep_helper_set_mode(sleep_mode mode){
|
void sleep_helper_set_mode(sleep_mode mode){
|
||||||
current_mode = mode;
|
current_mode = mode;
|
||||||
if (mode == SLEEP_MODE_OFF)
|
|
||||||
{
|
|
||||||
|
|
||||||
// 关闭睡眠仪
|
|
||||||
// 关闭PWM
|
|
||||||
bk_pwm_stop(pwm_chan);
|
|
||||||
// 关闭电源输出
|
|
||||||
bk_gpio_set_output_low(GPIO_44);
|
|
||||||
bk_gpio_set_output_low(GPIO_45);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t insert_value = bk_gpio_get_input(GPIO_50);
|
|
||||||
LOGE("sleep_helper insert_value %d \n",insert_value);
|
|
||||||
socket_insert = insert_value;
|
|
||||||
if(socket_insert == 1){
|
|
||||||
LOGE("sleep_helper open fail!! cable not insert %d \n",insert_value);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if (sleep_helper_msg_que)
|
if (sleep_helper_msg_que)
|
||||||
{
|
{
|
||||||
sleep_msg_t msg;
|
sleep_msg_t msg;
|
||||||
@ -321,11 +304,7 @@ void sleep_helper_set_mode(sleep_mode mode){
|
|||||||
void sleep_helper_set_level(sleep_model_level level){
|
void sleep_helper_set_level(sleep_model_level level){
|
||||||
|
|
||||||
if(current_mode == SLEEP_MODE_OFF){
|
if(current_mode == SLEEP_MODE_OFF){
|
||||||
pwm_init_config_t config = {0};
|
sleep_helper_open();
|
||||||
config.period_cycle = 100;
|
|
||||||
config.duty_cycle = g_mode_level[0];
|
|
||||||
bk_pwm_init(pwm_chan, &config);
|
|
||||||
bk_pwm_start(pwm_chan);
|
|
||||||
}
|
}
|
||||||
if(level>0 && level< 10){
|
if(level>0 && level< 10){
|
||||||
current_level = level;
|
current_level = level;
|
||||||
@ -337,6 +316,40 @@ void sleep_helper_set_level(sleep_model_level level){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sleep_helper_open(){
|
||||||
|
LOGE("sleep_helper_open\n");
|
||||||
|
bk_gpio_enable_output(44);
|
||||||
|
bk_gpio_enable_output(45);
|
||||||
|
uint8_t insert_value = bk_gpio_get_input(GPIO_50);
|
||||||
|
LOGE("sleep_helper insert_value %d \n",insert_value);
|
||||||
|
socket_insert = insert_value;
|
||||||
|
if(socket_insert == 1){
|
||||||
|
LOGE("sleep_helper open fail!! cable not insert %d \n",insert_value);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pwm_init_config_t config = {0};
|
||||||
|
config.period_cycle = 100;
|
||||||
|
config.duty_cycle = g_mode_level[0];//默认等级1
|
||||||
|
bk_pwm_init(pwm_chan, &config);
|
||||||
|
bk_pwm_start(pwm_chan);
|
||||||
|
//默认模式1
|
||||||
|
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sleep_helper_close(){
|
||||||
|
LOGE("sleep_helper_close\n");
|
||||||
|
current_mode = SLEEP_MODE_OFF;
|
||||||
|
// 关闭睡眠仪
|
||||||
|
// 关闭PWM
|
||||||
|
bk_pwm_stop(pwm_chan);
|
||||||
|
// 关闭电源输出
|
||||||
|
bk_gpio_set_output_low(GPIO_44);
|
||||||
|
bk_gpio_set_output_low(GPIO_45);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON* iot_sleep_helper_get_device_desc()
|
cJSON* iot_sleep_helper_get_device_desc()
|
||||||
{
|
{
|
||||||
cJSON *sleep_helper_desc = cJSON_CreateObject();
|
cJSON *sleep_helper_desc = cJSON_CreateObject();
|
||||||
@ -362,7 +375,7 @@ cJSON* iot_sleep_helper_get_device_desc()
|
|||||||
cJSON *parameters = cJSON_CreateObject();
|
cJSON *parameters = cJSON_CreateObject();
|
||||||
cJSON *p_mode = cJSON_CreateObject();
|
cJSON *p_mode = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(p_mode, "type", "number");
|
cJSON_AddStringToObject(p_mode, "type", "number");
|
||||||
cJSON_AddStringToObject(p_mode, "description", "0到3之间的整数 0代表关闭助眠仪");
|
cJSON_AddStringToObject(p_mode, "description", "1到3之间的整数");
|
||||||
cJSON_AddItemToObjectCS(parameters,"mode",p_mode);
|
cJSON_AddItemToObjectCS(parameters,"mode",p_mode);
|
||||||
cJSON_AddItemToObjectCS(setMode,"parameters",parameters);
|
cJSON_AddItemToObjectCS(setMode,"parameters",parameters);
|
||||||
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE,setMode);
|
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE,setMode);
|
||||||
@ -380,6 +393,17 @@ cJSON* iot_sleep_helper_get_device_desc()
|
|||||||
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL,setLevel);
|
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL,setLevel);
|
||||||
|
|
||||||
|
|
||||||
|
//打开助眠仪
|
||||||
|
cJSON *methods_open = cJSON_CreateObject();
|
||||||
|
cJSON_AddStringToObject(methods_open, "description", "打开助眠仪");
|
||||||
|
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_OPEN,methods_open);
|
||||||
|
|
||||||
|
//打开助眠仪
|
||||||
|
cJSON *methods_close = cJSON_CreateObject();
|
||||||
|
cJSON_AddStringToObject(methods_close, "description", "关闭助眠仪");
|
||||||
|
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_CLOSE,methods_close);
|
||||||
|
|
||||||
|
|
||||||
cJSON_AddItemToObjectCS(sleep_helper_desc,"methods",methods);
|
cJSON_AddItemToObjectCS(sleep_helper_desc,"methods",methods);
|
||||||
|
|
||||||
//打印一下描述
|
//打印一下描述
|
||||||
@ -396,7 +420,7 @@ void iot_sleep_helper_parser_invoke(char* cmd,char * paramters_json){
|
|||||||
cJSON* params = cJSON_Parse(paramters_json);
|
cJSON* params = cJSON_Parse(paramters_json);
|
||||||
if(params == NULL){
|
if(params == NULL){
|
||||||
LOGE("params == NULL\n");
|
LOGE("params == NULL\n");
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
//设置模式
|
//设置模式
|
||||||
if (strcmp(cmd, IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE) == 0)
|
if (strcmp(cmd, IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE) == 0)
|
||||||
@ -408,13 +432,20 @@ void iot_sleep_helper_parser_invoke(char* cmd,char * paramters_json){
|
|||||||
}
|
}
|
||||||
if (strcmp(cmd, IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL) == 0)
|
if (strcmp(cmd, IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL) == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
// {"level": 60}
|
// {"level": 60}
|
||||||
int level = cJSON_GetObjectItem(params, "level")->valueint;
|
int level = cJSON_GetObjectItem(params, "level")->valueint;
|
||||||
LOGE("level :%d\n",level);
|
LOGE("level :%d\n",level);
|
||||||
sleep_helper_set_level(level);
|
sleep_helper_set_level(level);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (strcmp(cmd, IOT_SLEEP_HELPER_DEVICE_OPEN) == 0)
|
||||||
|
{
|
||||||
|
sleep_helper_open();
|
||||||
|
}
|
||||||
|
if (strcmp(cmd, IOT_SLEEP_HELPER_DEVICE_CLOSE) == 0)
|
||||||
|
{
|
||||||
|
sleep_helper_close();
|
||||||
|
}
|
||||||
cJSON_Delete(params);
|
cJSON_Delete(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ extern "C" {
|
|||||||
#define IOT_SLEEP_HELPER_DEVICE_NAME "sleep_helper"
|
#define IOT_SLEEP_HELPER_DEVICE_NAME "sleep_helper"
|
||||||
#define IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE "setMode"
|
#define IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE "setMode"
|
||||||
#define IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL "setLevel"
|
#define IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL "setLevel"
|
||||||
|
#define IOT_SLEEP_HELPER_DEVICE_OPEN "open"
|
||||||
|
#define IOT_SLEEP_HELPER_DEVICE_CLOSE "close"
|
||||||
/**
|
/**
|
||||||
* 3种模式
|
* 3种模式
|
||||||
*/
|
*/
|
||||||
@ -58,6 +59,8 @@ typedef struct
|
|||||||
|
|
||||||
|
|
||||||
void sleep_helper_init();
|
void sleep_helper_init();
|
||||||
|
void sleep_helper_open();
|
||||||
|
void sleep_helper_close();
|
||||||
void sleep_helper_set_mode(sleep_mode mode);
|
void sleep_helper_set_mode(sleep_mode mode);
|
||||||
void sleep_helper_set_level(sleep_model_level level);
|
void sleep_helper_set_level(sleep_model_level level);
|
||||||
void sleep_helper_deinit();
|
void sleep_helper_deinit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user