1.优化蓝牙控制设备 2.优化FunctionCall 获取设备状态 3.减少log输出
This commit is contained in:
parent
828f92af0b
commit
05d112badb
@ -925,19 +925,19 @@ static int ws_client_recv(transport client)
|
||||
|
||||
if (client->last_opcode == WS_TRANSPORT_OPCODES_PING) {
|
||||
const char *data = (client->payload_len == 0) ? NULL : client->rx_buffer;
|
||||
BK_LOGE(TAG, "Received ping, Sending PONG with payload len=%d\r\n", client->payload_len);
|
||||
BK_LOGE(TAG, "----------sending pong packet----------\r\n");
|
||||
BK_LOGD(TAG, "Received ping, Sending PONG with payload len=%d\r\n", client->payload_len);
|
||||
BK_LOGD(TAG, "----------sending pong packet----------\r\n");
|
||||
ws_write(client, WS_TRANSPORT_OPCODES_PONG | WS_TRANSPORT_OPCODES_FIN, WS_MASK, data, client->payload_len,
|
||||
WEBSOCKET_NETWORK_TIMEOUT_MS);
|
||||
} else if (client->last_opcode == WS_TRANSPORT_OPCODES_PONG) {
|
||||
BK_LOGE(TAG, "Received pong frame, send ping success\r\n");
|
||||
BK_LOGD(TAG, "Received pong frame, send ping success\r\n");
|
||||
client->wait_for_pong_resp = false;
|
||||
} else if (client->last_opcode == WS_TRANSPORT_OPCODES_CLOSE) {
|
||||
BK_LOGE(TAG, "Received close frame\r\n");
|
||||
BK_LOGD(TAG, "Received close frame\r\n");
|
||||
client->state = WEBSOCKET_STATE_CLOSING;
|
||||
} else if (client->last_opcode == WS_TRANSPORT_OPCODES_TEXT) {
|
||||
BK_LOGE(TAG, "Received text frame: \r\n");
|
||||
bk_hex_dump(client->rx_buffer, client->payload_len);
|
||||
BK_LOGD(TAG, "Received text frame: \r\n");
|
||||
//bk_hex_dump(client->rx_buffer, client->payload_len);
|
||||
}
|
||||
|
||||
return BK_OK;
|
||||
@ -1365,12 +1365,12 @@ void websocket_client_task(beken_thread_arg_t *thread_param)
|
||||
client->ping_tick_ms = bk_tick_get_ms();
|
||||
|
||||
if (status_bits & PING_SENT_BIT) {
|
||||
BK_LOGE(TAG, "----------Sending ping packet----------\r\n");
|
||||
BK_LOGD(TAG, "----------Sending ping packet----------\r\n");
|
||||
rtos_lock_mutex(&client->mutex);
|
||||
ws_write(client, WS_TRANSPORT_OPCODES_PING | WS_TRANSPORT_OPCODES_FIN, WS_MASK, NULL, 0, WEBSOCKET_NETWORK_TIMEOUT_MS);
|
||||
rtos_unlock_mutex(&client->mutex);
|
||||
} else if(status_bits & TEXT_SENT_BIT) {
|
||||
BK_LOGE(TAG, "----------Sending text packet----------\r\n");
|
||||
BK_LOGD(TAG, "----------Sending text packet----------\r\n");
|
||||
test_case_text(client);
|
||||
}
|
||||
if (!client->wait_for_pong_resp) {
|
||||
|
@ -362,11 +362,7 @@ static void handle_system_event(key_event_t event)
|
||||
poweroff_voice();
|
||||
ws2812_led_clear_all();
|
||||
ispoweron = 0;
|
||||
<<<<<<< HEAD
|
||||
rtos_delay_milliseconds(400);
|
||||
=======
|
||||
rtos_delay_milliseconds(1000);
|
||||
>>>>>>> 055e7e84bd6a0e47612d1047b42c9c6184b187e9
|
||||
bk_gpio_enable_output(51);
|
||||
bk_gpio_set_output_low(51);
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "../iot/iot_sleep_helper.h"
|
||||
#include "../iot/iot_lamp.h"
|
||||
#include "spi_led.h"
|
||||
#include "bk_wifi.h"
|
||||
#include "../iot/iot_speaker.h"
|
||||
|
||||
static ble_boarding_info_t *s_ble_boarding_info = NULL;
|
||||
static beken_semaphore_t s_ble_sema = NULL;
|
||||
@ -458,11 +460,11 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
else if (s_char_cmd_char_handle == param->handle)
|
||||
{
|
||||
bk_ble_gatts_get_attr_value(param->handle, &buff_size, &tmp_buff);
|
||||
|
||||
wboard_loge("state: %s", param->value);
|
||||
char recv [param->len];
|
||||
os_memcpy((char *)recv, param->value, param->len);
|
||||
|
||||
if(param->len ==0 || param->value == NULL) return ret;
|
||||
uint8_t recv [param->len+1];
|
||||
os_memset(recv,0,sizeof(recv));
|
||||
os_memcpy((uint8_t *)recv, param->value, param->len);
|
||||
wboard_loge("recv: %s", recv);
|
||||
char* ptr;
|
||||
if (NULL != (ptr = strstr((char *)recv, "AT+SSID"))){
|
||||
wboard_loge("start scan wifi!!");
|
||||
@ -555,14 +557,19 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
if (strcmp(volume, "?") == 0)
|
||||
{
|
||||
// 返回当前音量
|
||||
int vol = speaker_volume_get_current();
|
||||
sprintf((char *)str_respone, "AT+VOLUME=%d", vol);
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 设置音量
|
||||
// int v = atoi(volume);
|
||||
int v = atoi(volume);
|
||||
speaker_set_volume(v);
|
||||
sprintf((char *)str_respone, "%s", "AT+VOLUME=OK");
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
sprintf((char *)str_respone, "%s", "AT+VOLUME=OK");
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
|
||||
}
|
||||
/**
|
||||
* 蓝牙控制灯光亮度
|
||||
@ -580,7 +587,8 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
if (strcmp(bright, "?") == 0)
|
||||
{
|
||||
// 返回当前亮度
|
||||
sprintf((char *)str_respone, "%s", "AT+BRIGHT=100");
|
||||
int br = lamp_get_bright();
|
||||
sprintf((char *)str_respone, "AT+BRIGHT=%d", br);
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
else
|
||||
@ -646,10 +654,10 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
break;
|
||||
case 2:
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
sleep_helper_set_mode(SLEEP_MODE_2);
|
||||
break;
|
||||
case 3:
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
sleep_helper_set_mode(SLEEP_MODE_3);
|
||||
break;
|
||||
}
|
||||
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=OK");
|
||||
@ -727,7 +735,9 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于APP 查找设备
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+SOU_DEVICE")))
|
||||
{
|
||||
wboard_loge("AT+SOU_DEVICE!!");
|
||||
@ -738,6 +748,42 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 12.获取设备状态
|
||||
发送: AT+STATE=?
|
||||
回复: AT+STATE=A,B,C,D,E
|
||||
A: WIFI 连接状态 0 - 表示当前没有连接WIFI 1- 当前已经连接wifi
|
||||
B: 设备音量 0 - 100 0 表示静音
|
||||
C: 设备灯光亮度 0 -100 0 表示关闭
|
||||
D: 助眠仪模式 0 - 3 0 表示关闭 1-3 分别代表三种模式
|
||||
E: 助眠仪等级 1 - 9 表示9个强度等级
|
||||
*/
|
||||
else if (NULL != (ptr = strstr((char *)recv, "AT+STATE")))
|
||||
{
|
||||
wboard_loge("AT+STATE!!");
|
||||
uint8_t str_respone[32] = {0};
|
||||
memset(str_respone, 0, sizeof(str_respone));
|
||||
int err = kNoErr;
|
||||
wifi_link_status_t link_status = {0};
|
||||
os_memset(&link_status, 0x0, sizeof(link_status));
|
||||
err = bk_wifi_sta_get_link_status(&link_status);
|
||||
if (err != kNoErr)
|
||||
{
|
||||
os_printf("get sta link status fail!\n");
|
||||
}
|
||||
int connect_state = 0;
|
||||
if(link_status.state == WIFI_LINKSTATE_STA_GOT_IP){
|
||||
connect_state = 1;
|
||||
}
|
||||
os_printf("link_status.state:%d\n",link_status.state);
|
||||
int device_volme = speaker_volume_get_current();
|
||||
int device_bright = lamp_get_bright();
|
||||
int sleep_mode = sleep_helper_get_mode();
|
||||
int sleep_level = sleep_helper_get_level();
|
||||
int sleep_work_time = sleep_helper_get_work_timeout();
|
||||
sprintf((char *)str_respone, "AT+STATE=%d,%d,%d,%d,%d,%d", connect_state,device_volme,device_bright,sleep_mode,sleep_level,sleep_work_time);
|
||||
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
|
||||
}
|
||||
|
||||
/**
|
||||
* 蓝牙控制OTA
|
||||
|
@ -15,6 +15,7 @@
|
||||
//OTA
|
||||
#include "modules/ota.h"
|
||||
#include "spi_led.h"
|
||||
#include "thing.h"
|
||||
|
||||
#define TAG "iot_lamp"
|
||||
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
|
||||
@ -34,6 +35,10 @@ void lamp_deinit(){
|
||||
//ws2812_deinit();
|
||||
}
|
||||
|
||||
int lamp_get_bright(){
|
||||
return ws2812_get_brightness();
|
||||
}
|
||||
|
||||
cJSON* iot_lamp_get_device_desc(){
|
||||
|
||||
cJSON *lamp_desc = cJSON_CreateObject();
|
||||
@ -87,7 +92,7 @@ cJSON* iot_lamp_get_device_desc(){
|
||||
cJSON_AddStringToObject(p_brightness, "description", "0到100之间的整数 0表示关灯 非0表示打开,默认100");
|
||||
|
||||
|
||||
cJSON_AddItemToObjectCS(parameters,"brightness",p_brightness);
|
||||
cJSON_AddItemToObjectCS(parameters,IOT_LAMP_DEVICE_PARAM_BRIGHTNESS,p_brightness);
|
||||
cJSON_AddItemToObjectCS(SetBrightness,"parameters",parameters);
|
||||
|
||||
//cJSON_AddStringToObject(SetBrightness, "type", "number");
|
||||
@ -287,7 +292,7 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
|
||||
cJSON* params = cJSON_Parse(paramters_json);
|
||||
if(params == NULL) return;
|
||||
// {"brightness": 60}
|
||||
int brightness = cJSON_GetObjectItem(params, "brightness")->valueint;
|
||||
int brightness = cJSON_GetObjectItem(params, IOT_LAMP_DEVICE_PARAM_BRIGHTNESS)->valueint;
|
||||
LOGE("invoke brightness-->%d\n",brightness);
|
||||
if(brightness == 0){
|
||||
ws2812_led_clear_all();
|
||||
@ -295,6 +300,7 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
|
||||
//ws2812_set_all_led(0xFFFFFF,brightness);
|
||||
ws2812_set_all_led_brightness(brightness);
|
||||
}
|
||||
thing_report_iot_state_number(IOT_LAMP_DEVICE_NAME,IOT_LAMP_DEVICE_PARAM_BRIGHTNESS,brightness);
|
||||
cJSON_Delete(params);
|
||||
}
|
||||
else if (strcmp(cmd, IOT_LAMP_DEVICE_OTA) == 0){
|
||||
|
@ -18,6 +18,8 @@ extern "C" {
|
||||
#include "cJSON.h"
|
||||
#define IOT_LAMP_DEVICE_NAME "lamp"
|
||||
#define IOT_LAMP_DEVICE_FUNS_SET_BRIGHTNESS "SetBrightness"
|
||||
#define IOT_LAMP_DEVICE_PARAM_BRIGHTNESS "brightness"
|
||||
|
||||
#define IOT_LAMP_DEVICE_GET_BATTERY "GetBattery"
|
||||
#define IOT_LAMP_DEVICE_OTA "ota"
|
||||
|
||||
@ -26,6 +28,11 @@ extern "C" {
|
||||
void lamp_init();
|
||||
void lamp_http_ota_start(char *url);
|
||||
void lamp_deinit();
|
||||
/**
|
||||
* 获取当前亮度
|
||||
* 0-100
|
||||
*/
|
||||
int lamp_get_bright();
|
||||
|
||||
cJSON * iot_lamp_get_device_desc();
|
||||
void iot_lamp_parser_invoke(char* cmd,char * paramters_json);
|
||||
|
@ -267,7 +267,7 @@ void sleep_helper_set_mode(sleep_mode mode){
|
||||
sleep_msg_t msg;
|
||||
msg.mode = mode;
|
||||
rtos_push_to_queue(&sleep_helper_msg_que, &msg, BEKEN_NO_WAIT);
|
||||
//thing_report_iot_state_number(getGlobalSessionId(),IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,mode);
|
||||
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,mode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ void sleep_helper_set_level(sleep_model_level level){
|
||||
config.duty_cycle = s_period*g_mode_level[level-1]/100;
|
||||
LOGE("sleep_helper_set_level %d \n",g_mode_level[level-1]);
|
||||
bk_pwm_set_period_duty(pwm_chan,&config);
|
||||
//thing_report_iot_state_number(getGlobalSessionId(),IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,level);
|
||||
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,level);
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +355,7 @@ void sleep_helper_open(){
|
||||
//默认模式1
|
||||
sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
sleep_helper_start_timer();
|
||||
//thing_report_iot_state_number(getGlobalSessionId(),IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,SLEEP_MODE_1);
|
||||
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,SLEEP_MODE_1);
|
||||
}
|
||||
|
||||
void sleep_helper_close(){
|
||||
@ -369,7 +369,7 @@ void sleep_helper_close(){
|
||||
bk_gpio_set_output_low(GPIO_44);
|
||||
bk_gpio_set_output_low(GPIO_45);
|
||||
|
||||
//thing_report_iot_state_number(getGlobalSessionId(),IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,0);
|
||||
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,0);
|
||||
}
|
||||
|
||||
cJSON* iot_sleep_helper_get_device_desc()
|
||||
@ -522,6 +522,18 @@ void sleep_helper_init(){
|
||||
rtos_init_timer(&timer_close_handle, work_timeout, sleep_helper_close_timer_handle, 0);
|
||||
}
|
||||
|
||||
int sleep_helper_is_open(){
|
||||
return current_mode;
|
||||
}
|
||||
int sleep_helper_get_mode(){
|
||||
return current_mode;
|
||||
}
|
||||
int sleep_helper_get_level(){
|
||||
return current_level;
|
||||
}
|
||||
int sleep_helper_get_work_timeout(){
|
||||
return work_timeout/60/1000;
|
||||
}
|
||||
|
||||
void sleep_helper_deinit(){
|
||||
|
||||
|
@ -68,6 +68,10 @@ void sleep_helper_close();
|
||||
void sleep_helper_set_mode(sleep_mode mode);
|
||||
void sleep_helper_set_timeout(int timeout);
|
||||
void sleep_helper_set_level(sleep_model_level level);
|
||||
int sleep_helper_is_open();
|
||||
int sleep_helper_get_mode();
|
||||
int sleep_helper_get_level();
|
||||
int sleep_helper_get_work_timeout();
|
||||
void sleep_helper_deinit();
|
||||
|
||||
cJSON * iot_sleep_helper_get_device_desc();
|
||||
|
@ -49,8 +49,10 @@ void speaker_volume_init(void)
|
||||
{
|
||||
BK_LOGE(TAG, "storage volume: %d fail\n", volume);
|
||||
}
|
||||
}else{
|
||||
volume = volume_size;
|
||||
}
|
||||
|
||||
|
||||
/* SPK_GAIN_MAX * [(exp(i/(SPK_VOLUME_LEVEL-1)-1)/(exp(1)-1)] */
|
||||
//uint32_t step[SPK_VOLUME_LEVEL] = {0, 6, 12, 20, 28, 37, 47, 58, 71, 84, 100};
|
||||
//for (uint32_t i = 0; i < SPK_VOLUME_LEVEL; i++)
|
||||
@ -147,7 +149,7 @@ void speaker_volume_set_abs(uint8_t level, uint8_t has_precision)
|
||||
|
||||
uint32_t speaker_volume_get_current()
|
||||
{
|
||||
return volume;
|
||||
return volume*10;
|
||||
}
|
||||
|
||||
uint32_t speaker_volume_get_level_count()
|
||||
@ -199,7 +201,16 @@ cJSON* iot_speaker_get_device_desc()
|
||||
return speaker_desc;
|
||||
}
|
||||
|
||||
|
||||
void speaker_set_volume(int volume)
|
||||
{
|
||||
if (volume >= 0 && volume <= 100)
|
||||
{
|
||||
int level = volume / 10;
|
||||
LOGE("speaker_setVolume--> volume :%d level:%d\n", volume, level);
|
||||
speaker_volume_set_abs(level, 0);
|
||||
thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME, IOT_SPEAKER_DEVICE_PARAM_VOL, volume);
|
||||
}
|
||||
}
|
||||
void iot_speaker_parser_invoke(char* cmd,char * paramters_json){
|
||||
|
||||
LOGE("iot_speaker_parser_invoke :%s\n",paramters_json);
|
||||
@ -215,13 +226,7 @@ void iot_speaker_parser_invoke(char* cmd,char * paramters_json){
|
||||
// {"volume": 60}
|
||||
int volume = cJSON_GetObjectItem(params, "volume")->valueint;
|
||||
LOGE("volume :%d\n",volume);
|
||||
if(volume > 10){
|
||||
int level = volume/10;
|
||||
LOGE("speaker_setVolume--> volume :%d level:%d\n",volume,level);
|
||||
speaker_volume_set_abs(level,0);
|
||||
//extern char *getGlobalSessionId(void);
|
||||
//thing_report_iot_state_number(getGlobalSessionId(),IOT_SPEAKER_DEVICE_NAME,IOT_SPEAKER_DEVICE_PARAM_VOL,volume);
|
||||
}
|
||||
speaker_set_volume(volume);
|
||||
cJSON_Delete(params);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,11 @@ void speaker_volume_init();
|
||||
|
||||
cJSON* iot_speaker_get_device_desc();
|
||||
void iot_speaker_parser_invoke(char* cmd,char * paramters_json);
|
||||
/**
|
||||
* 获取当前音量
|
||||
*/
|
||||
uint32_t speaker_volume_get_current();
|
||||
void speaker_set_volume(int volume);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -24,6 +24,18 @@
|
||||
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
|
||||
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
|
||||
extern rtc_session *__get_beken_rtc(void);
|
||||
extern char *getGlobalSessionId(void);
|
||||
|
||||
static beken_queue_t thing_msg_que = NULL;
|
||||
static beken_thread_t thing_thread_hdl = NULL;
|
||||
static int thing_start = 0;
|
||||
typedef struct
|
||||
{
|
||||
int type ;
|
||||
char *data;
|
||||
int data_len;
|
||||
} thing_msg_t;
|
||||
|
||||
|
||||
cJSON* thing_gen_iot_descriptors(char *session_id)
|
||||
{
|
||||
@ -59,9 +71,9 @@ cJSON* thing_gen_iot_descriptors(char *session_id)
|
||||
}
|
||||
|
||||
//{"session_id":"14c23594","type":"iot","update":true,"states":[{"name":"AudioSpeaker","state":{"volume":50}}]}
|
||||
void thing_report_iot_state(char * session_id, char * device,char * properties_key, char* state){
|
||||
void thing_report_iot_state(char * device,char * properties_key, char* state){
|
||||
cJSON *messageRoot = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(messageRoot, "session_id", session_id);
|
||||
cJSON_AddStringToObject(messageRoot, "session_id", getGlobalSessionId());
|
||||
cJSON_AddStringToObject(messageRoot, "type", "iot");
|
||||
cJSON_AddBoolToObject(messageRoot, "update", true);
|
||||
cJSON *stateArray = cJSON_CreateArray();
|
||||
@ -81,16 +93,26 @@ void thing_report_iot_state(char * session_id, char * device,char * properties_k
|
||||
cJSON_AddItemToObject(messageRoot, "states", stateArray);
|
||||
char *message = cJSON_PrintUnformatted(messageRoot);
|
||||
LOGE("iot -->(len:%d) %s\n",strlen(message),message);
|
||||
//将数据发送到队列 使用线程发送
|
||||
if (thing_msg_que != NULL)
|
||||
{
|
||||
thing_msg_t msg;
|
||||
msg.type = 0;
|
||||
msg.data = os_malloc(strlen(message)+1);
|
||||
strcpy(msg.data, message);
|
||||
msg.data_len = strlen(message);
|
||||
rtos_push_to_queue(&thing_msg_que, &msg, BEKEN_NO_WAIT);
|
||||
}
|
||||
|
||||
rtc_session *beken_rtc = __get_beken_rtc();
|
||||
transport bk_rtc_ws = beken_rtc->bk_rtc_client;
|
||||
websocket_client_send_text(bk_rtc_ws, message, strlen(message), 10*1000);
|
||||
//rtc_session *beken_rtc = __get_beken_rtc();
|
||||
//transport bk_rtc_ws = beken_rtc->bk_rtc_client;
|
||||
//websocket_client_send_text(bk_rtc_ws, message, strlen(message), 10*1000);
|
||||
cJSON_Delete(messageRoot);
|
||||
}
|
||||
|
||||
void thing_report_iot_state_number(char * session_id, char * device,char * properties_key, int state){
|
||||
void thing_report_iot_state_number(char * device,char * properties_key, int state){
|
||||
cJSON *messageRoot = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(messageRoot, "session_id", session_id);
|
||||
cJSON_AddStringToObject(messageRoot, "session_id", getGlobalSessionId());
|
||||
cJSON_AddStringToObject(messageRoot, "type", "iot");
|
||||
cJSON_AddBoolToObject(messageRoot, "update", true);
|
||||
cJSON *stateArray = cJSON_CreateArray();
|
||||
@ -111,9 +133,20 @@ void thing_report_iot_state_number(char * session_id, char * device,char * prope
|
||||
char *message = cJSON_PrintUnformatted(messageRoot);
|
||||
LOGE("iot -->(len:%d) %s\n",strlen(message),message);
|
||||
|
||||
rtc_session *beken_rtc = __get_beken_rtc();
|
||||
transport bk_rtc_ws = beken_rtc->bk_rtc_client;
|
||||
websocket_client_send_text(bk_rtc_ws, message, strlen(message), 10*1000);
|
||||
//rtc_session *beken_rtc = __get_beken_rtc();
|
||||
//transport bk_rtc_ws = beken_rtc->bk_rtc_client;
|
||||
//websocket_client_send_text(bk_rtc_ws, message, strlen(message), 10*1000);
|
||||
//将数据发送到队列 使用线程发送
|
||||
if (thing_msg_que != NULL)
|
||||
{
|
||||
thing_msg_t msg;
|
||||
msg.type = 0;
|
||||
msg.data = os_malloc(strlen(message)+1);
|
||||
strcpy(msg.data, message);
|
||||
msg.data_len = strlen(message);
|
||||
rtos_push_to_queue(&thing_msg_que, &msg, BEKEN_NO_WAIT);
|
||||
}
|
||||
|
||||
cJSON_Delete(messageRoot);
|
||||
}
|
||||
|
||||
@ -183,6 +216,55 @@ void thing_iot_invoke(char *iot_json){
|
||||
/**
|
||||
* 生成IOT 描述文件 用于意图识别控制
|
||||
*/
|
||||
|
||||
|
||||
static void thing_thread_task(void *arg)
|
||||
{
|
||||
bk_err_t ret = BK_OK;
|
||||
while(thing_start){
|
||||
|
||||
thing_msg_t msg;
|
||||
ret = rtos_pop_from_queue(&thing_msg_que, &msg, BEKEN_WAIT_FOREVER);
|
||||
if (kNoErr == ret)
|
||||
{
|
||||
switch (msg.type)
|
||||
{
|
||||
// 发送数据到平台
|
||||
case 0:
|
||||
{
|
||||
rtc_session *beken_rtc = __get_beken_rtc();
|
||||
transport bk_rtc_ws = beken_rtc->bk_rtc_client;
|
||||
websocket_client_send_text(bk_rtc_ws, msg.data, msg.data_len, 10*1000);
|
||||
os_free(msg.data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* delete msg queue */
|
||||
ret = rtos_deinit_queue(&thing_msg_que);
|
||||
if (ret != kNoErr)
|
||||
{
|
||||
bk_printf("delete spi_led_msg_que fail\n");
|
||||
}
|
||||
thing_msg_que = NULL;
|
||||
/* delete task */
|
||||
if(thing_thread_hdl!= NULL) {
|
||||
rtos_delete_thread(&thing_thread_hdl);
|
||||
thing_thread_hdl = NULL;
|
||||
}
|
||||
bk_printf("delete thing_thread_hdl task\n");
|
||||
}
|
||||
|
||||
void thing_report_device_state(){
|
||||
//上报当前软件版本
|
||||
thing_report_iot_state(IOT_LAMP_DEVICE_NAME,"version", IOT_LAMP_DEVICE_VERSION);
|
||||
//上报当前亮度
|
||||
thing_report_iot_state_number(IOT_LAMP_DEVICE_NAME,IOT_LAMP_DEVICE_PARAM_BRIGHTNESS,lamp_get_bright());
|
||||
//上报当前音量
|
||||
thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME,IOT_SPEAKER_DEVICE_PARAM_VOL,speaker_volume_get_current());
|
||||
//thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME,IOT_SPEAKER_DEVICE_PARAM_VOL,volume*10);
|
||||
}
|
||||
void thing_init()
|
||||
{
|
||||
#ifdef IOT_LAMP
|
||||
@ -198,5 +280,25 @@ void thing_init()
|
||||
//sleep_helper_set_mode(SLEEP_MODE_1);
|
||||
#endif
|
||||
|
||||
//thing_report_iot_state("111","lamp","version","1.0.6");
|
||||
thing_start = 1;
|
||||
bk_err_t ret = BK_OK;
|
||||
ret = rtos_init_queue(&thing_msg_que, "thing_msg_que", sizeof(thing_msg_t), 5);
|
||||
if (ret != kNoErr)
|
||||
{
|
||||
bk_printf("create thing_msg_que queue fail\n");
|
||||
}
|
||||
ret = rtos_create_thread(&thing_thread_hdl,
|
||||
4,
|
||||
"spi_led",
|
||||
(beken_thread_function_t)thing_thread_task,
|
||||
5 * 1024,
|
||||
NULL);
|
||||
if (ret != kNoErr)
|
||||
{
|
||||
thing_thread_hdl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void thing_deinit(){
|
||||
thing_start = 0;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define IOT_SLEEP_HELPER 1
|
||||
|
||||
void thing_init();
|
||||
void thing_deinit();
|
||||
|
||||
cJSON * thing_create(char * name,char *description);
|
||||
|
||||
@ -47,9 +48,9 @@ cJSON * thing_add_number_property(char * name,char *description);
|
||||
//AddBooleanProperty
|
||||
//AddMethod
|
||||
|
||||
void thing_report_iot_state(char * session_id, char * device,char * properties_key, char* state);
|
||||
void thing_report_iot_state(char * device,char * properties_key, char* state);
|
||||
|
||||
void thing_report_iot_state_number(char * session_id, char * device,char * properties_key, int state);
|
||||
void thing_report_iot_state_number(char * device,char * properties_key, int state);
|
||||
/**
|
||||
* 生成IOT 描述文件 用于意图识别控制
|
||||
*/
|
||||
@ -58,4 +59,9 @@ cJSON* thing_gen_iot_descriptors(char *session_id);
|
||||
/**
|
||||
* 解析平台下发的IOT指令,获取响应的参数调用不同的硬件功能
|
||||
*/
|
||||
void thing_iot_invoke(char *iot_json);
|
||||
void thing_iot_invoke(char *iot_json);
|
||||
|
||||
/**
|
||||
*连接服务器成功后 上报当前设备状态
|
||||
*/
|
||||
void thing_report_device_state();
|
@ -389,3 +389,7 @@ void ws2812_led_clear_all(){
|
||||
void ws2812_stop_led_start_ota(){
|
||||
ws2812_start = 0;
|
||||
}
|
||||
|
||||
int ws2812_get_brightness(){
|
||||
return (int)current_brightness;
|
||||
}
|
@ -38,6 +38,7 @@ void ws2812_led_asr_wakeup();
|
||||
void ws2812_led_change_color();
|
||||
void ws2812_led_start_ota();
|
||||
void ws2812_stop_led_start_ota();
|
||||
int ws2812_get_brightness();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -771,13 +771,14 @@ void rtc_websocket_event_handler(void *event_handler_arg, char *event_base, int3
|
||||
rtos_delay_milliseconds(100);
|
||||
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_IOT_DESC);
|
||||
rtos_delay_milliseconds(20);
|
||||
thing_report_iot_state(getGlobalSessionId(), IOT_LAMP_DEVICE_NAME,"version", IOT_LAMP_DEVICE_VERSION);
|
||||
thing_report_device_state();
|
||||
|
||||
// rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START_LISTEN);
|
||||
// rtos_delay_milliseconds(200);
|
||||
// rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_LISTEN);
|
||||
break;
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
bk_printf("WEBSOCKET_EVENT_DISCONNECTED~~~~\n");
|
||||
//bk_printf("WEBSOCKET_EVENT_DISCONNECTED~~~~\n");
|
||||
LOGE("Disconnected from WebSocket server\r\n");
|
||||
g_connected_flag = false;
|
||||
__get_beken_rtc()->disconnecting_state++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user