This commit is contained in:
dianke3yu 2025-06-13 16:27:04 +08:00
commit 4923934280
13 changed files with 413 additions and 50 deletions

View File

@ -675,8 +675,12 @@ static void handle_system_event(key_event_t event)
thing_init();
init_bat_timer();
// spi_led_init();
<<<<<<< HEAD
bk_printf("VER:%s\r\n","1.0.6");
=======
bk_printf("bk_misc_get_reset_reason = 0x%02X \n",bk_misc_get_reset_reason());
bk_printf("VER:1.0.3 2025.05.27\r\n");
>>>>>>> 0c7475e0d398483dba561d0acb30a572a0d6c861
#endif
#endif

View File

@ -20,6 +20,10 @@
#include "wifi_boarding_internal.h"
#include "wifi_boarding_utils.h"
//helloyifa
#include "../iot/iot_sleep_helper.h"
#include "../iot/iot_lamp.h"
#include "spi_led.h"
static ble_boarding_info_t *s_ble_boarding_info = NULL;
static beken_semaphore_t s_ble_sema = NULL;
@ -449,10 +453,11 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
bk_ble_gatts_get_attr_value(param->handle, &buff_size, &tmp_buff);
wboard_loge("state: %s", param->value);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>ָ<EFBFBD><D6B8>
char recv [param->len];
os_memcpy((char *)recv, param->value, param->len);
char* ptr;
if (NULL != (ptr = strstr((char *)param->value, "AT+SSID"))){
if (NULL != (ptr = strstr((char *)recv, "AT+SSID"))){
wboard_loge("start scan wifi!!");
//<2F>ص<EFBFBD>
if (s_ble_boarding_info && s_ble_boarding_info->scan_wifi_cb)
@ -460,7 +465,7 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
s_ble_boarding_info->scan_wifi_cb();
}
}
if (NULL != (ptr = strstr((char *)param->value, "AT+SCAN"))){
if (NULL != (ptr = strstr((char *)recv, "AT+SCAN"))){
wboard_loge("start scan wifi!!");
//<2F>ص<EFBFBD>
if (s_ble_boarding_info && s_ble_boarding_info->scan_wifi_cb)
@ -469,14 +474,14 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
}
}
if (NULL != (ptr = strstr((char *)param->value, "AT+WIFI"))){
if (NULL != (ptr = strstr((char *)recv, "AT+WIFI"))){
wboard_loge("recv wifi info!!");
char m_ssid[64] = {0};
char m_pwd [64] = {0};
memset(m_ssid,0,sizeof(m_ssid));
memset(m_pwd,0,sizeof(m_pwd));
sscanf((char *)param->value,"AT+WIFI=%[^,],%[^,]", m_ssid,m_pwd);
sscanf((char *)recv,"AT+WIFI=%[^,],%[^,]", m_ssid,m_pwd);
wboard_loge("%s %s ",m_ssid,m_pwd);
//<2F><><EFBFBD><EFBFBD>SSID
if(strlen(m_ssid) > 0){
@ -522,10 +527,240 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
}
}
/**
* 7.
* AT+VOLUME=100 (0-100)
* :AT+VOLUME=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+VOLUME")))
{
wboard_loge("AT+VOLUME!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char volume[12] = {0};
memset(volume, 0, sizeof(volume));
sscanf((char *)recv, "AT+VOLUME=%s", volume);
if (strcmp(volume, "?") == 0)
{
// 返回当前音量
}
else
{
// 设置音量
// int v = atoi(volume);
}
sprintf((char *)str_respone, "%s", "AT+VOLUME=OK");
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/**
*
* AT+BRIGHT=100 (0-100)
* :AT+BRIGHT=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+BRIGHT")))
{
wboard_loge("AT+BRIGHT!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char bright[12] = {0};
memset(bright, 0, sizeof(bright));
sscanf((char *)recv, "AT+BRIGHT=%s", bright);
if (strcmp(bright, "?") == 0)
{
// 返回当前亮度
sprintf((char *)str_respone, "%s", "AT+BRIGHT=100");
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
else
{
int brightness = atoi(bright);
ws2812_set_all_led_brightness(brightness);
sprintf((char *)str_respone, "%s", "AT+BRIGHT=OK");
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
}
/**
*
* AT+SLEEP_EN=1 (0- 1-)
* :AT+SLEEP_EN=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_EN")))
{
wboard_loge("AT+SLEEP_EN!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char enable[12] = {0};
memset(enable, 0, sizeof(enable));
sscanf((char *)recv, "AT+SLEEP_EN=%s", enable);
if (strcmp(enable, "?") == 0)
{
sprintf((char *)str_respone, "%s", "AT+SLEEP_EN=1");
}
else
{
int open = atoi(enable);
if(open){
sleep_helper_open();
}else{
sleep_helper_close();
}
sprintf((char *)str_respone, "%s", "AT+SLEEP_EN=OK");
}
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/**
*
* :AT+SLEEP_MODE=1 (1-3 3)
* :AT+SLEEP_MODE=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_MODE")))
{
wboard_loge("AT+SLEEP_MODE!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char mode[12] = {0};
memset(mode, 0, sizeof(mode));
sscanf((char *)recv, "AT+SLEEP_MODE=%s", mode);
if (strcmp(mode, "?") == 0)
{
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=1");
}
else
{
int v = atoi(mode);
switch(v){
case 1:
sleep_helper_set_mode(SLEEP_MODE_1);
break;
case 2:
sleep_helper_set_mode(SLEEP_MODE_1);
break;
case 3:
sleep_helper_set_mode(SLEEP_MODE_1);
break;
}
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=OK");
}
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/**
*
* :AT+SLEEP_TIMEOUT=1 (0-30 )
* :AT+SLEEP_TIMEOUT=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_TIMEOUT")))
{
wboard_loge("AT+SLEEP_TIMEOUT!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char mode[12] = {0};
memset(mode, 0, sizeof(mode));
sscanf((char *)recv, "AT+SLEEP_TIMEOUT=%s", mode);
if (strcmp(mode, "?") == 0)
{
sprintf((char *)str_respone, "%s", "AT+SLEEP_TIMEOUT=10");
}
else
{
int v = atoi(mode);
sleep_helper_set_timeout(v);
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=OK");
}
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/*
*11.
: AT+SLEEP_LEVEL=1 (1-9 9)
: AT+SLEEP_LEVEL=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+SLEEP_LEVEL")))
{
wboard_loge("AT+SLEEP_LEVEL!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char level[12] = {0};
memset(level, 0, sizeof(level));
sscanf((char *)recv, "AT+SLEEP_LEVEL=%s", level);
if (strcmp(level, "?") == 0)
{
sprintf((char *)str_respone, "%s", "AT+SLEEP_LEVEL=1");
}
else
{
int v = atoi(level);
sleep_helper_set_level(v);
sprintf((char *)str_respone, "%s", "AT+SLEEP_LEVEL=OK");
}
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/*
*11.
: AT+SLEEP_LEVEL=1 (1-9 9)
: AT+SLEEP_LEVEL=OK
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+VERSION")))
{
wboard_loge("AT+VERSION!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
char level[12] = {0};
memset(level, 0, sizeof(level));
sscanf((char *)recv, "AT+VERSION=%s", level);
if (strcmp(level, "?") == 0)
{
sprintf((char *)str_respone, "AT+VERSION=%s", IOT_LAMP_DEVICE_VERSION);
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
}
/**
* OTA
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+OTA")))
{
wboard_loge("AT+OTA!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
// char ota_url[128] = {0};
// memset(ota_url, 0, sizeof(ota_url));
// sscanf((char *)recv, "AT+OTA=%s", ota_url);
// 2. 查找等号位置
char *equal_pos = strchr((char *)param->value, '=');
if (equal_pos != NULL)
{
// 3. 计算等号后子串长度
int len = strlen(equal_pos + 1); // +1跳过等号本身
// 4. 动态分配内存
char *ota_url = (char *)malloc(len + 1); // +1存放结束符'\0'
// 5. 复制子串并添加结束符
strncpy(ota_url, equal_pos + 1, len);
ota_url[len] = '\0'; // 确保字符串终止
sprintf((char *)str_respone, "%s", "AT+OTA=OK");
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
if (strlen(ota_url) > 0)
{
wboard_loge("OTA-->%s", ota_url);
wboard_loge("OTA--len >%d", strlen(ota_url));
ws2812_led_start_ota();
lamp_http_ota_start(ota_url);
free(ota_url);
}
}
// int v = atoi(mode);
// sleep_helper_set_timeout(v);
}
//wifi_boarding_notify(param->value,param->len);
}
else
{
wboard_loge("invalid write handle %d", param->handle);

View File

@ -131,6 +131,9 @@ int rtc_websocket_audio_send_data(rtc_session *rtc_session, uint8_t *data_ptr, s
void rtc_websocket_audio_receive_data(rtc_session *rtc_session, uint8 *data, uint32_t len);
void rtc_websocket_audio_receive_data_opus(rtc_session *rtc_session, uint8 *data, uint32_t len);
int rtc_websocket_send_text(transport web_socket, void *str, enum MsgType msgtype);
//helloyifa
int rtc_websocket_send_json(transport web_socket, void *str, size_t data_len);
int rtc_websocket_parse_hello(cJSON *root);
void rtc_websocket_parse_text(text_info_t *text, cJSON *root);
void rtc_fill_audio_info(audio_info_t *info, char *type, uint32_t adc_rate, uint32_t dac_rate, uint32_t enc_ms, uint32_t dec_ms, uint32_t size);

View File

@ -23,12 +23,7 @@
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
#define IOT_LAMP_DEVICE_NAME "lamp"
#define IOT_LAMP_DEVICE_FUNS_SET_BRIGHTNESS "SetBrightness"
#define IOT_LAMP_DEVICE_GET_BATTERY "GetBattery"
#define IOT_LAMP_DEVICE_OTA "ota"
#define IOT_LAMP_DEVICE_VERSION "1.0.5"
#define IOT_LAMP_DEVICE_OTA_CHECK_URL "http://106.52.233.130:8888/ir58/ir58.json"
void lamp_init(){
@ -56,6 +51,17 @@ cJSON* iot_lamp_get_device_desc(){
cJSON_AddItemToObjectCS(lamp_desc,"properties",properties);
//定义version属性
cJSON *version = cJSON_CreateObject();
cJSON_AddStringToObject(version, "description", "当前拍拍灯软件版本");
cJSON_AddStringToObject(version, "type", "string");
//添加brightness属性到properties
cJSON_AddItemToObjectCS(properties,"version",version);
//添加properties 到lamp_desc 描述
cJSON_AddItemToObjectCS(lamp_desc,"properties",properties);
//定义方法methods
cJSON *methods = cJSON_CreateObject();

View File

@ -16,7 +16,12 @@ extern "C" {
//#include "beken_config.h"
//#include "bk_websocket_client.h"
#include "cJSON.h"
#define IOT_LAMP_DEVICE_NAME "lamp"
#define IOT_LAMP_DEVICE_FUNS_SET_BRIGHTNESS "SetBrightness"
#define IOT_LAMP_DEVICE_GET_BATTERY "GetBattery"
#define IOT_LAMP_DEVICE_OTA "ota"
#define IOT_LAMP_DEVICE_VERSION "1.0.6"
void lamp_init();
void lamp_http_ota_start(char *url);

View File

@ -18,7 +18,7 @@
#include <driver/gpio.h>
#include "gpio_driver.h"
#include "thing.h"
#include "iot_sleep_helper.h"
#define TAG "sleep_helper"
@ -180,7 +180,7 @@ typedef struct
sleep_model_level level;
} sleep_msg_t;
extern char *getGlobalSessionId(void);
static void sleep_helper_thread(void *arg)
{
@ -267,6 +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);
}
}
@ -322,6 +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);
}
}
@ -353,6 +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);
}
void sleep_helper_close(){
@ -365,6 +368,8 @@ 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);
}
cJSON* iot_sleep_helper_get_device_desc()
@ -374,12 +379,21 @@ cJSON* iot_sleep_helper_get_device_desc()
cJSON_AddStringToObject(sleep_helper_desc, "description", "这是助眠仪(睡眠辅助仪器)");
cJSON *properties = cJSON_CreateObject();
//volume 属性
//mode 属性
cJSON *mode = cJSON_CreateObject();
cJSON_AddStringToObject(mode, "description", "当前设备的模式");
cJSON_AddStringToObject(mode, "description", "当前工作模式 0表示关闭 1-3表示3种不同的模式");
cJSON_AddStringToObject(mode, "type", "number");
//添加brightness属性到properties
cJSON_AddItemToObjectCS(properties,"mode",mode);
//添加mode属性到properties
cJSON_AddItemToObjectCS(properties,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,mode);
//level 属性
cJSON *param_level = cJSON_CreateObject();
cJSON_AddStringToObject(param_level, "description", "当前工作等级");
cJSON_AddStringToObject(param_level, "type", "number");
//添加mode属性到properties
cJSON_AddItemToObjectCS(properties,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,param_level);
//添加properties speaker_desc 描述
cJSON_AddItemToObjectCS(sleep_helper_desc,"properties",properties);
@ -388,24 +402,24 @@ cJSON* iot_sleep_helper_get_device_desc()
cJSON *methods = cJSON_CreateObject();
//设置模式的方法
cJSON *setMode = cJSON_CreateObject();
cJSON_AddStringToObject(setMode, "description", "设置助眠仪工作模式");
cJSON_AddStringToObject(setMode, "description", "设置助眠仪工作模式");
cJSON *parameters = cJSON_CreateObject();
cJSON *p_mode = cJSON_CreateObject();
cJSON_AddStringToObject(p_mode, "type", "number");
cJSON_AddStringToObject(p_mode, "description", "1到3之间的整数");
cJSON_AddItemToObjectCS(parameters,"mode",p_mode);
cJSON_AddItemToObjectCS(parameters,IOT_SLEEP_HELPER_DEVICE_PARAM_MODE,p_mode);
cJSON_AddItemToObjectCS(setMode,"parameters",parameters);
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE,setMode);
//设置工作等级的方法
cJSON *setLevel = cJSON_CreateObject();
cJSON_AddStringToObject(setLevel, "description", "设置助眠仪工作等级强度");
cJSON_AddStringToObject(setLevel, "description", "设置助眠仪工作等级强度");
cJSON *parameters_set_level = cJSON_CreateObject();
cJSON *p_level = cJSON_CreateObject();
cJSON_AddStringToObject(p_level, "type", "number");
cJSON_AddStringToObject(p_level, "description", "1到9之间的整数");
cJSON_AddItemToObjectCS(parameters_set_level,"level",p_level);
cJSON_AddItemToObjectCS(parameters_set_level,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,p_level);
cJSON_AddItemToObjectCS(setLevel,"parameters",parameters_set_level);
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL,setLevel);

View File

@ -14,6 +14,10 @@ extern "C" {
#include "cJSON.h"
#define IOT_SLEEP_HELPER_DEVICE_NAME "sleep_helper"
#define IOT_SLEEP_HELPER_DEVICE_PARAM_MODE "mode"
#define IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL "level"
#define IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE "setMode"
#define IOT_SLEEP_HELPER_DEVICE_FUNS_SET_LEVEL "setLevel"
#define IOT_SLEEP_HELPER_DEVICE_OPEN "open"

View File

@ -22,6 +22,8 @@
#endif
#include "motor.h"
#endif
#include "iot_speaker.h"
#include "thing.h"
#define TAG "iot_speaker"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
@ -158,16 +160,16 @@ uint32_t speaker_volume_get_level_count()
cJSON* iot_speaker_get_device_desc()
{
cJSON *speaker_desc = cJSON_CreateObject();
cJSON_AddStringToObject(speaker_desc, "name", "speaker");
cJSON_AddStringToObject(speaker_desc, "description", "扬声器 音量调节");
cJSON_AddStringToObject(speaker_desc, "name", IOT_SPEAKER_DEVICE_NAME);
cJSON_AddStringToObject(speaker_desc, "description", "音量调节");
cJSON *properties = cJSON_CreateObject();
//volume 属性
cJSON *volume = cJSON_CreateObject();
cJSON_AddStringToObject(volume, "description", "当前设备音量");
cJSON_AddStringToObject(volume, "description", "当前设备音量 0-100");
cJSON_AddStringToObject(volume, "type", "number");
//添加brightness属性到properties
cJSON_AddItemToObjectCS(properties,"volume",volume);
cJSON_AddItemToObjectCS(properties,IOT_SPEAKER_DEVICE_PARAM_VOL,volume);
//添加properties speaker_desc 描述
cJSON_AddItemToObjectCS(speaker_desc,"properties",properties);
@ -175,7 +177,7 @@ cJSON* iot_speaker_get_device_desc()
//定义方法methods
cJSON *methods = cJSON_CreateObject();
cJSON *setVolume = cJSON_CreateObject();
cJSON_AddStringToObject(setVolume, "description", "设置音量");
cJSON_AddStringToObject(setVolume, "description", "设置音量和声音大小");
cJSON *parameters = cJSON_CreateObject();
cJSON *p_volume = cJSON_CreateObject();
@ -187,7 +189,7 @@ cJSON* iot_speaker_get_device_desc()
cJSON_AddItemToObjectCS(setVolume,"parameters",parameters);
//cJSON_AddStringToObject(SetBrightness, "type", "number");
cJSON_AddItemToObjectCS(methods,"setVolume",setVolume);
cJSON_AddItemToObjectCS(methods,IOT_SPEAKER_DEVICE_FUNS_SET_VOL,setVolume);
cJSON_AddItemToObjectCS(speaker_desc,"methods",methods);
//打印一下描述
@ -217,6 +219,8 @@ void iot_speaker_parser_invoke(char* cmd,char * paramters_json){
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);
}
cJSON_Delete(params);
}

View File

@ -5,6 +5,11 @@ extern "C" {
#endif
#include "cJSON.h"
#define IOT_SPEAKER_DEVICE_NAME "speaker"
#define IOT_SPEAKER_DEVICE_PARAM_VOL "volume"
#define IOT_SPEAKER_DEVICE_FUNS_SET_VOL "setVolume"
void speaker_volume_init();
cJSON* iot_speaker_get_device_desc();

View File

@ -16,31 +16,14 @@
#include "iot_lamp.h"
#include "iot_speaker.h"
#include "iot_sleep_helper.h"
#include "beken_rtc.h"
#define TAG "thing"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
#define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__)
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
/**
* IOT
*/
void thing_init()
{
#ifdef IOT_LAMP
lamp_init();
#endif
#ifdef IOT_SPEAKER
speaker_volume_init();
#endif
#ifdef IOT_SLEEP_HELPER
sleep_helper_init();
//sleep_helper_set_mode(SLEEP_MODE_1);
#endif
}
extern rtc_session *__get_beken_rtc(void);
cJSON* thing_gen_iot_descriptors(char *session_id)
{
@ -75,6 +58,65 @@ cJSON* thing_gen_iot_descriptors(char *session_id)
return messageRoot;
}
//{"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){
cJSON *messageRoot = cJSON_CreateObject();
cJSON_AddStringToObject(messageRoot, "session_id", session_id);
cJSON_AddStringToObject(messageRoot, "type", "iot");
cJSON_AddBoolToObject(messageRoot, "update", true);
cJSON *stateArray = cJSON_CreateArray();
cJSON *states_desc = cJSON_CreateObject();
cJSON_AddStringToObject(states_desc, "name", device);
//cJSON *state_obj = cJSON_CreateObject();
//{"volume":50}
cJSON *param = cJSON_CreateObject();
cJSON_AddStringToObject(param, properties_key, state);
//"state":{"volume":50}}
cJSON_AddItemToObjectCS(states_desc,"state",param);
cJSON_AddItemToArray(stateArray, states_desc);
cJSON_AddItemToObject(messageRoot, "states", stateArray);
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);
cJSON_Delete(messageRoot);
}
void thing_report_iot_state_number(char * session_id, char * device,char * properties_key, int state){
cJSON *messageRoot = cJSON_CreateObject();
cJSON_AddStringToObject(messageRoot, "session_id", session_id);
cJSON_AddStringToObject(messageRoot, "type", "iot");
cJSON_AddBoolToObject(messageRoot, "update", true);
cJSON *stateArray = cJSON_CreateArray();
cJSON *states_desc = cJSON_CreateObject();
cJSON_AddStringToObject(states_desc, "name", device);
//cJSON *state_obj = cJSON_CreateObject();
//{"volume":50}
cJSON *param = cJSON_CreateObject();
cJSON_AddNumberToObject(param, properties_key, state);
//"state":{"volume":50}}
cJSON_AddItemToObjectCS(states_desc,"state",param);
cJSON_AddItemToArray(stateArray, states_desc);
cJSON_AddItemToObject(messageRoot, "states", stateArray);
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);
cJSON_Delete(messageRoot);
}
/**
* IOT指令,
* :
@ -138,4 +180,23 @@ void thing_iot_invoke(char *iot_json){
// AddBooleanProperty
// AddMethod
/**
* IOT
*/
void thing_init()
{
#ifdef IOT_LAMP
lamp_init();
#endif
#ifdef IOT_SPEAKER
speaker_volume_init();
#endif
#ifdef IOT_SLEEP_HELPER
sleep_helper_init();
//sleep_helper_set_mode(SLEEP_MODE_1);
#endif
//thing_report_iot_state("111","lamp","version","1.0.6");
}

View File

@ -34,12 +34,22 @@ cJSON * thing_add_string_property(char * name,char *description);
},*/
cJSON * thing_add_number_property(char * name,char *description);
/**
* # Sending IoT descriptors
[{"name":"AudioSpeaker","description":"The audio speaker of the device","properties":{"volume":{"description":"Current audio volume value","type":"number"}},"methods":{"set_volume":{"description":"Set the audio volume","parameters":{"volume":{"description":"An integer between 0 and 100","type":"number"}}}}},{"name":"Lamp","description":"A test lamp","properties":{"power":{"description":"Whether the lamp is on","type":"boolean"}},"methods":{"turn_on":{"description":"Turn on the lamp","parameters":{}},"turn_off":{"description":"Turn off the lamp","parameters":{}}}}]
# Sending IoT states
{"session_id":"14c23594","type":"iot","update":true,"states":[{"name":"AudioSpeaker","state":{"volume":50}}]}
*/
//AddStringProperty
//AddNumberProperty
//AddBooleanProperty
//AddMethod
void thing_report_iot_state(char * session_id, char * device,char * properties_key, char* state);
void thing_report_iot_state_number(char * session_id, char * device,char * properties_key, int state);
/**
* IOT
*/

View File

@ -590,6 +590,7 @@ int demo_network_auto_reconnect(bool val) // val true means from disconnect to r
/*0x01110001:sta, 0x01110010:softap, 0x01110100:pan*/
if ((info.flag & 0x71l) == 0x71l)
{
BK_LOGE(TAG, "aaaaaaaaaaaaaaaa\n");
if (val == false)
{
network_reconnect_stop_timeout_check();
@ -597,6 +598,7 @@ int demo_network_auto_reconnect(bool val) // val true means from disconnect to r
app_event_send_msg(APP_EVT_RECONNECT_NETWORK, 0);
network_disc_evt_posted = 0;
}
BK_LOGE(TAG, "bbbbbbbbbbb\n");
demo_sta_app_init((char *)info.sta_ssid, (char *)info.sta_pwd);
return 0x71l;
}
@ -605,6 +607,7 @@ int demo_network_auto_reconnect(bool val) // val true means from disconnect to r
demo_softap_app_init((char *)info.ap_ssid, (char *)info.ap_pwd, NULL);
return 0x72l;
}
BK_LOGE(TAG, "ccccccccccccc\n");
#if CONFIG_NET_PAN
if ((info.flag & 0x74l) == 0x74l)
{
@ -625,6 +628,7 @@ int demo_network_auto_reconnect(bool val) // val true means from disconnect to r
int demo_save_network_auto_restart_info(netif_if_t type, void *val)
{
BK_LOGE(TAG, "demo_save_network_auto_restart_info type:%d\n",type);
BK_FAST_CONNECT_D info_tmp = {0};
__maybe_unused wifi_ap_config_t *ap_config = NULL;
__maybe_unused wifi_sta_config_t *sta_config = NULL;
@ -644,6 +648,7 @@ int demo_save_network_auto_restart_info(netif_if_t type, void *val)
os_memset((char *)info_tmp.sta_pwd, 0x0, 65);
os_strcpy((char *)info_tmp.sta_ssid, (char *)sta_config->ssid);
os_strcpy((char *)info_tmp.sta_pwd, (char *)sta_config->password);
BK_LOGE(TAG, "demo_save_network :%s %s\n",(char *)info_tmp.sta_ssid,(char *)info_tmp.sta_pwd);
}
else if (type == NETIF_IF_AP)
{
@ -725,6 +730,7 @@ static int bk_genie_sconf_netif_event_cb(void *arg, event_module_t event_module,
{
case EVENT_NETIF_GOT_IP4:
// helloyifa
BK_LOGE(TAG, "!!!!!!!!!!!!!!!!!!!!!!!\n");
result = rtos_init_timer(&led_wifi_connected_timer,
5000,
led_wifi_connected,
@ -744,12 +750,14 @@ static int bk_genie_sconf_netif_event_cb(void *arg, event_module_t event_module,
bk_printf("hi ws2812_led_wifi_connected\n");
network_disc_evt_posted = 0;
got_ip = (netif_event_got_ip4_t *)event_data;
BK_LOGI(TAG, "%s got ip %s.\n", got_ip->netif_if == NETIF_IF_STA ? "STA" : "BK PAN", got_ip->ip);
BK_LOGE(TAG, "%s got ip %s.\n", got_ip->netif_if == NETIF_IF_STA ? "STA" : "BK PAN", got_ip->ip);
if (smart_config_running)
{
app_event_send_msg(APP_EVT_NETWORK_PROVISIONING_SUCCESS, 0);
bk_wifi_sta_get_config(&sta_config);
BK_LOGE(TAG, "22222222222222222\n");
demo_save_network_auto_restart_info(got_ip->netif_if, &sta_config);
msg.event = DBEVT_WIFI_STATION_CONNECTED;
bk_genie_send_msg(&msg);
#if CONFIG_STA_AUTO_RECONNECT
@ -882,6 +890,7 @@ void be_set_smart_config_running(){
}
void bk_genie_prepare_for_smart_config(void)
{
BK_LOGE(TAG, "bk_genie_prepare_for_smart_config !!\n", __func__);
smart_config_running = true;
#if CONFIG_STA_AUTO_RECONNECT
first_time_for_network_provisioning = true;
@ -914,7 +923,7 @@ void bk_genie_prepare_for_smart_config(void)
int bk_genie_smart_config_init(void)
{
int flag;
BK_LOGE(TAG, "6666666 bk_genie_smart_config_init !!\n" );
event_handler_init();
flag = demo_network_auto_reconnect(false);

View File

@ -34,6 +34,7 @@
#include "audio_process.h"
#include "thing.h"
#include "iot_ota.h"
#include "iot_lamp.h"
#define TAG "WS_MAIN"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
@ -769,6 +770,8 @@ 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);
// 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);