连接物联网平台
优化WiFi连接,实现温度上传,底座电量上传,体温贴电量上传
This commit is contained in:
parent
9ce296cba1
commit
cac6ef59e3
@ -28,6 +28,7 @@
|
||||
#include "ring_queue.h"
|
||||
#include "charge.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "app_wifi.h"
|
||||
|
||||
|
||||
static app_temperature_info_t temperature_info;
|
||||
@ -41,7 +42,7 @@ static beken_timer_t timer_bind;
|
||||
static beken_timer_t timer_idle;
|
||||
static beken_timer_t timer_battery_refresh;
|
||||
static beken_timer_t timer_ble_scan;
|
||||
static beken_timer_t timer_charge_hell ;
|
||||
//static beken_timer_t timer_charge_hell ;
|
||||
|
||||
int start_bind_detect = 0;
|
||||
int hall_key_down_count = 0;
|
||||
@ -67,18 +68,13 @@ static RingQueue ring_queue;
|
||||
|
||||
extern mqtt_client client;
|
||||
|
||||
static int e = 0;
|
||||
static int mean_value = 0;
|
||||
|
||||
//WIFI信息
|
||||
extern char last_ssid[33] ;
|
||||
extern char last_password[65];
|
||||
char last_bssid[65];
|
||||
char last_channel[65];
|
||||
char last_security[65];
|
||||
|
||||
network_InitTypeDef_adv_st adv_config;
|
||||
|
||||
//MQTT账号密码
|
||||
char mqtt_username[128];
|
||||
char mqtt_password[128];
|
||||
|
||||
extern char g_sta_mac[6];
|
||||
|
||||
@ -304,6 +300,7 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
|
||||
last_body_temp = temp_body;
|
||||
app_enter_ui(UI_SHOW_TEMPERATURE);
|
||||
|
||||
|
||||
//添加数据到队列,数量足够后取出所有温度数据 计算方差 如果小于 N N可以趋近于0 暂定小于100 则表示温度稳定
|
||||
RingQueue_enqueue(&ring_queue,(int)last_body_temp);
|
||||
@ -311,31 +308,41 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
bk_printf("RingQueue_size -> %d \r\n", size);
|
||||
|
||||
if (RingQueue_isFull(&ring_queue)) {
|
||||
int i = 0;
|
||||
int t_datas[MAX_SIZE];
|
||||
for(i = 0;i < MAX_SIZE; i++){
|
||||
//int i = 0;
|
||||
//int t_datas[MAX_SIZE];
|
||||
//for(i = 0;i < MAX_SIZE; i++){
|
||||
int value = 0;
|
||||
RingQueue_dequeue(&ring_queue,&value);
|
||||
t_datas[i] = value;
|
||||
//t_datas[i] = value;
|
||||
bk_printf("%d ", value);
|
||||
}
|
||||
bk_printf("\r\n", size);
|
||||
//}
|
||||
bk_printf("size: %d\r\n", size);
|
||||
//计算平均值
|
||||
int sum = 0;
|
||||
for(i = 0;i < MAX_SIZE; i++){
|
||||
sum += t_datas[i];
|
||||
}
|
||||
int mean_value = sum / MAX_SIZE;
|
||||
bk_printf("mean_value:%d \r\n", mean_value);
|
||||
//for(i = 0;i < MAX_SIZE; i++){
|
||||
// sum += t_datas[i];
|
||||
//}
|
||||
//int mean_value = ring_queue.sum / MAX_SIZE;
|
||||
//bk_printf("mean_value:%d \r\n", mean_value);
|
||||
|
||||
//计算方差
|
||||
double sumOfSquares = 0;
|
||||
for (int i = 0; i < MAX_SIZE; i++) {
|
||||
sumOfSquares += (t_datas[i] - mean_value) * (t_datas[i] - mean_value);
|
||||
for (int j=0;j<MAX_SIZE;j++){
|
||||
sum += ring_queue.data[j];
|
||||
}
|
||||
int variance_value = sumOfSquares / MAX_SIZE; // 注意这里是n,而不是n-1(对于样本方差)
|
||||
mean_value = sum / MAX_SIZE;
|
||||
bk_printf("mean_value:%d \r\n", mean_value);
|
||||
//计算方差
|
||||
int sumOfSquares = 0;
|
||||
|
||||
for (int i = 0; i < MAX_SIZE; i++) {
|
||||
bk_printf("%d ", ring_queue.data[i]);
|
||||
sumOfSquares += (ring_queue.data[i] - mean_value) * (ring_queue.data[i] - mean_value);
|
||||
}
|
||||
bk_printf("\r\n");
|
||||
bk_printf("sumOfSquares:%d \r\n", sumOfSquares);
|
||||
|
||||
int variance_value = sumOfSquares*10 / MAX_SIZE; // 注意这里是n,而不是n-1(对于样本方差)
|
||||
bk_printf("variance_value:%d \r\n", variance_value);
|
||||
//方差小于 20 表示温度稳定 //10
|
||||
//方差小于 20 表示温度稳定 //10 //方差小于0.01°C可以认为平均温度代表实际温度(误差0.1°C条件下)
|
||||
if(variance_value <= 20){
|
||||
//测量完成
|
||||
temperature_info.device_state = STATE_DETECT_FINISH;
|
||||
@ -348,38 +355,31 @@ void temperature_adv_callback(recv_adv_t *r_ind)
|
||||
voice_player_play_temperature(mean_value);
|
||||
|
||||
if(client.isconnected){
|
||||
mqtt_upload_temperature(mean_value);
|
||||
//mqtt_upload_temperature(mean_value);
|
||||
}else{
|
||||
//connect_mqtt();
|
||||
bk_printf("mqtt not connected \r\n");
|
||||
}
|
||||
}
|
||||
for(int k = 0;k < MAX_SIZE; k++){
|
||||
int value111 = 0;
|
||||
RingQueue_dequeue(&ring_queue,&value111);
|
||||
//t_datas[i] = value;
|
||||
//bk_printf("%d ", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
e++;
|
||||
if(e>=MAX_SIZE){
|
||||
e=0;
|
||||
if(client.isconnected){
|
||||
if(mean_value!=0)
|
||||
mqtt_upload_temperature(mean_value);
|
||||
//mqtt_upload_boxbat(box_battery_percent);
|
||||
mqtt_upload_bat(temperature_info.batt_percent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MQTT上传温度
|
||||
void mqtt_upload_temperature(uint16_t t_value){
|
||||
uint16_t xy = t_value/10; //整数
|
||||
// uint16_t y = xy % 10 ;//个位
|
||||
// uint16_t x = (xy / 10) % 10 ;//十位
|
||||
// uint16_t z = t_value/10%10 ;//小数位
|
||||
char msg[128];
|
||||
char *topic_properties =(char *)os_malloc(128);
|
||||
char device_id [64];
|
||||
rt_memset(device_id,0,sizeof(device_id));
|
||||
rt_sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
PRODUCTID,g_sta_mac[0],g_sta_mac[1],g_sta_mac[2],g_sta_mac[3],g_sta_mac[4],g_sta_mac[5]);
|
||||
|
||||
os_memset(topic_properties,0,128);
|
||||
rt_sprintf(topic_properties, "/%s/%s/properties/report", PRODUCTID, device_id);
|
||||
|
||||
rt_sprintf(msg, "{\"properties\": {\"temperature\":%d}}", xy);
|
||||
paho_mqtt_publish(&client, QOS1, topic_properties, msg, strlen(msg));
|
||||
bk_printf("MQTT publish: %s\n", msg);
|
||||
bk_printf("device_id: %s\n", device_id);
|
||||
os_free(topic_properties);
|
||||
}
|
||||
|
||||
|
||||
UINT32 usb_power_is_pluged(void)
|
||||
{
|
||||
@ -388,7 +388,9 @@ UINT32 usb_power_is_pluged(void)
|
||||
return (reg & (1 << 21));
|
||||
}
|
||||
void box_poweroff_timeout_callback(void *arg);
|
||||
void timer_battery_refresh_callback(void *arg);
|
||||
int first_poweron = 0;
|
||||
static int s=0;
|
||||
void timer_check_device_run_callback(void *arg){
|
||||
|
||||
uint16_t reg_charge = CHARGE_REG0X2_CHARGE_X_STA_GET(0);
|
||||
@ -401,6 +403,11 @@ void timer_check_device_run_callback(void *arg){
|
||||
}
|
||||
// box_info.charge_state = 0;
|
||||
rt_kprintf("usb_power_is_pluged reg:%d state:%d hall:%d\r\n", reg_charge, box_info.charge_state, box_info.hall_state);
|
||||
s++;
|
||||
if(s>=10){
|
||||
timer_battery_refresh_callback(NULL);
|
||||
s=0;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 5; i++){ //1秒内处于合盖状态就关机
|
||||
if(hall || !first_poweron){
|
||||
@ -483,6 +490,7 @@ void app_show_box_battery(){
|
||||
OLED_Clear();
|
||||
char str_batt[12] = {0};
|
||||
rt_sprintf(str_batt,"%d%",box_battery_percent);
|
||||
|
||||
extern unsigned char f35x40_box_ico[];
|
||||
//满电显示屏显示不全 缩小字体显示
|
||||
if(box_battery_percent >= 100){
|
||||
@ -503,18 +511,47 @@ static void box_adc_detect_callback(int new_mv, void *user_data)
|
||||
{
|
||||
static int cnt = 0;
|
||||
box_batt_adc.user_data = (void*)new_mv;
|
||||
u32 kmah=0;
|
||||
//u32 kmah=0;
|
||||
if(cnt++ >= 20){
|
||||
cnt = 0;
|
||||
rt_kprintf("adc channel%d voltage:%d,%x\r\n",box_batt_adc.channel,new_mv,box_batt_adc.user_data);
|
||||
int bat_volt = new_mv*2;
|
||||
//int batt_min = 3300; //3300
|
||||
int batt_max = 4151;
|
||||
//int batt_max = 4151;
|
||||
if(box_info.charge_state){
|
||||
bat_volt -= 48 ;
|
||||
}
|
||||
rt_kprintf("battery_calc --> bat_volt:%d\n",bat_volt);
|
||||
if(bat_volt >= batt_max)
|
||||
if (bat_volt >= voltage_table[0].voltage) {
|
||||
printf("0000000000000000000000000000\r\n");
|
||||
printf("voltage:%d\r\n",voltage_table[0].voltage);
|
||||
box_battery_percent = 100;
|
||||
}
|
||||
// 电压低于最低阈值,返回0%
|
||||
else if (bat_volt <= voltage_table[BATTERY_TABLE_SIZE-1].voltage) {
|
||||
printf("11111111111111111111111111111\r\n");
|
||||
printf("voltage:%d\r\n",voltage_table[BATTERY_TABLE_SIZE-1].voltage);
|
||||
box_battery_percent = 0;
|
||||
}
|
||||
|
||||
// 查表法查找对应的电量百分比
|
||||
else{
|
||||
for (int i = 1; i < BATTERY_TABLE_SIZE; i++){
|
||||
if (bat_volt >= voltage_table[i].voltage){
|
||||
// 线性插值计算百分比
|
||||
//u16 voltage_range = voltage_table[i].voltage - voltage_table[i-1].voltage;
|
||||
//u16 voltage_offset = bat_val - voltage_table[i-1].voltage;
|
||||
box_battery_percent=(443570-voltage_table[i].mah)*100/443570;
|
||||
printf("i:%d \r\n", i);
|
||||
printf("voltage_table[i].mah:%d \r\n", voltage_table[i].voltage);
|
||||
printf("tmp_bat_val:%d \r\n", box_battery_percent);
|
||||
break;
|
||||
//return box_battery_percent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if(bat_volt >= batt_max)
|
||||
box_battery_percent = 100;
|
||||
else if(bat_volt <= batt_max && bat_volt >= 4000){
|
||||
kmah = (-28880*bat_volt+120895600)/151;
|
||||
@ -537,7 +574,7 @@ static void box_adc_detect_callback(int new_mv, void *user_data)
|
||||
box_battery_percent = (443570-kmah)*100/443570; // 3000~3400
|
||||
}
|
||||
else
|
||||
box_battery_percent = 1;
|
||||
box_battery_percent = 1;*/
|
||||
|
||||
// if (bat_volt < batt_min) {
|
||||
// box_battery_percent=0;
|
||||
@ -580,6 +617,8 @@ void timer_battery_refresh_callback(void *arg)
|
||||
// 重新采样电池电压
|
||||
adc_obj_start(&box_batt_adc);
|
||||
// 重新显示电量
|
||||
if(client.isconnected)
|
||||
mqtt_upload_boxbat(box_battery_percent);
|
||||
if(app_mode == UI_BOX_BATTERY || app_mode == UI_SHOW_MEMORY_INFO)
|
||||
{
|
||||
app_show_box_battery();
|
||||
@ -850,8 +889,7 @@ void app_enter_ui(app_ui_mode mode){
|
||||
app_show_box_battery();
|
||||
//static int battery_timer_inited = 0;
|
||||
|
||||
rtos_init_timer(&timer_battery_refresh, 10000, timer_battery_refresh_callback, NULL);
|
||||
rtos_start_timer(&timer_battery_refresh);
|
||||
|
||||
// battery_timer_inited = 1;
|
||||
|
||||
|
||||
@ -975,15 +1013,15 @@ void charge_sleep_on(int on) {
|
||||
// voice_player_mute(1); //声音
|
||||
// rtos_start_timer(&timer_detect);
|
||||
// bk_wlan_start_sta(BK_STATION); //WIFI
|
||||
belon_ble_scan_start(); //蓝牙扫描
|
||||
belon_ble_start_adv(); //蓝牙广播
|
||||
//belon_ble_scan_start(); //蓝牙扫描
|
||||
//belon_ble_start_adv(); //蓝牙广播
|
||||
}else{
|
||||
OLED_DisPlay_Off();//屏幕
|
||||
voice_player_mute(0); //声音
|
||||
// rtos_stop_timer(&timer_detect);
|
||||
// //bk_wlan_stop(BK_STATION); //WIFI
|
||||
belon_ble_scan_stop(); //蓝牙扫描
|
||||
belon_ble_deinit_adv(); //蓝牙广播
|
||||
//belon_ble_scan_stop(); //蓝牙扫描
|
||||
//belon_ble_deinit_adv(); //蓝牙广播
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1207,198 +1245,6 @@ void temperature_led_ble(bool onoff){
|
||||
}
|
||||
}
|
||||
|
||||
void connnect_wifi(char *oob_ssid,char *connect_key){//连接wifi
|
||||
/*定义一个结构体,用于传入参数*/
|
||||
network_InitTypeDef_st wNetConfig;
|
||||
int len;
|
||||
|
||||
/*把这个结构体置空*/
|
||||
os_memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
|
||||
|
||||
/*检查SSID的长度,不能超过32字节*/
|
||||
len = os_strlen(oob_ssid);
|
||||
if(SSID_MAX_LEN < len)
|
||||
{
|
||||
bk_printf("ssid name more than 32 Bytes\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*将SSID跟密码传入结构体*/
|
||||
os_strcpy((char *)wNetConfig.wifi_ssid, oob_ssid);
|
||||
os_strcpy((char *)wNetConfig.wifi_key, connect_key);
|
||||
|
||||
/*当前为客户端模式*/
|
||||
wNetConfig.wifi_mode = BK_STATION;
|
||||
/*采用DHCP CLIENT的方式获得,从路由器动态获取IP地址*/
|
||||
wNetConfig.dhcp_mode = DHCP_CLIENT;
|
||||
wNetConfig.wifi_retry_interval = 100;
|
||||
bk_printf("ssid:%s key:%s\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
|
||||
/*启动WiFi连接*/
|
||||
bk_wlan_start(&wNetConfig);
|
||||
//rt_thread_mdelay(5000);
|
||||
}
|
||||
|
||||
// 读取最新联网信息
|
||||
void wifi_read_info(char *ssid, size_t ssid_len, char *password, size_t pass_len,
|
||||
char *bssid, size_t bssid_len, char *channel, size_t channel_len, char *security, size_t security_len){
|
||||
|
||||
char *t_ssid = ef_get_env(BLE_WIFI_FLASH_KEY_SSID);
|
||||
char *t_pass = ef_get_env(BLE_WIFI_FLASH_KEY_PASS);
|
||||
char *t_bssid = ef_get_env(BLE_WIFI_FLASH_KEY_BSSID);
|
||||
char *t_channel = ef_get_env(BLE_WIFI_FLASH_KEY_CHANNEL);
|
||||
char *t_security = ef_get_env(BLE_WIFI_FLASH_KEY_SECURITY);
|
||||
|
||||
if(t_ssid) {
|
||||
strncpy(last_ssid, t_ssid, ssid_len - 1);
|
||||
last_ssid[ssid_len - 1] = '\0';
|
||||
}
|
||||
if(t_pass) {
|
||||
strncpy(last_password, t_pass, pass_len - 1);
|
||||
last_password[pass_len - 1] = '\0';
|
||||
}
|
||||
if (t_bssid) {
|
||||
strncpy(bssid, t_bssid, bssid_len - 1);
|
||||
bssid[bssid_len - 1] = '\0';
|
||||
}
|
||||
if (t_channel) {
|
||||
strncpy(channel, t_channel, channel_len - 1);
|
||||
channel[channel_len - 1] = '\0';
|
||||
}
|
||||
if (t_security) {
|
||||
strncpy(security, t_security, security_len - 1);
|
||||
security[security_len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
//将flash存储的mac地址字符串转换为二进制格式
|
||||
void mac_string_to_binary(const char *mac_str, uint8_t *mac_bin) {
|
||||
if (!mac_str || !mac_bin) return;
|
||||
|
||||
char temp[18];
|
||||
strncpy(temp, mac_str, sizeof(temp)-1);
|
||||
temp[sizeof(temp)-1] = '\0';
|
||||
|
||||
for (int i = 0; temp[i]; i++) {
|
||||
temp[i] = toupper(temp[i]);
|
||||
}
|
||||
|
||||
char *p = temp;
|
||||
char *end = temp + strlen(temp);
|
||||
while (p < end) {
|
||||
if (*p == ':' || *p == '-') {
|
||||
memmove(p, p+1, end - p);
|
||||
end--;
|
||||
} else {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(temp) != 12) {
|
||||
bk_printf("Invalid MAC length: %d\n", strlen(temp));
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
char byte_str[3] = { temp[i*2], temp[i*2+1], '\0' };
|
||||
char *endptr;
|
||||
mac_bin[i] = (uint8_t)strtol(byte_str, &endptr, 16);
|
||||
|
||||
if (*endptr != '\0') {
|
||||
bk_printf("MAC conversion error at position %d\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//int fast_connect_try = 0;
|
||||
//快速连接
|
||||
void fast_connect_wifi(){
|
||||
// 检查是否有效
|
||||
// if (fci.ssid[0] != 0 && strlen((char*)fci.ssid) < 32) {
|
||||
uint8_t mac_bin[6] ={0};
|
||||
int sec_value = atoi(last_security);
|
||||
|
||||
memset(&adv_config, 0, sizeof(adv_config));
|
||||
strncpy(adv_config.ap_info.ssid, last_ssid, sizeof(adv_config.ap_info.ssid));
|
||||
adv_config.ap_info.ssid[sizeof(adv_config.ap_info.ssid)-1] = '\0';
|
||||
|
||||
mac_string_to_binary(last_bssid, mac_bin);
|
||||
memcpy(adv_config.ap_info.bssid, mac_bin, 6);
|
||||
|
||||
adv_config.ap_info.channel = (uint8_t)atoi(last_channel);
|
||||
|
||||
if (sec_value >= BK_SECURITY_TYPE_NONE && sec_value <= BK_SECURITY_TYPE_AUTO) {
|
||||
adv_config.ap_info.security = (wlan_sec_type_t)sec_value;
|
||||
} else {
|
||||
adv_config.ap_info.security = BK_SECURITY_TYPE_AUTO;
|
||||
}
|
||||
|
||||
strncpy(adv_config.key, last_password, sizeof(adv_config.key));
|
||||
adv_config.key[sizeof(adv_config.key)-1] = '\0';
|
||||
adv_config.key_len = strlen(last_password);
|
||||
adv_config.dhcp_mode = DHCP_CLIENT;
|
||||
|
||||
bk_printf(" SSID: %s\n", adv_config.ap_info.ssid);
|
||||
bk_printf(" BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
adv_config.ap_info.bssid[0], adv_config.ap_info.bssid[1],
|
||||
adv_config.ap_info.bssid[2], adv_config.ap_info.bssid[3],
|
||||
adv_config.ap_info.bssid[4], adv_config.ap_info.bssid[5]);
|
||||
bk_printf(" Channel: %d\n", adv_config.ap_info.channel);
|
||||
bk_printf(" Security: %d\n", adv_config.ap_info.security);
|
||||
|
||||
bk_wlan_start_sta_adv(&adv_config);
|
||||
// } else {
|
||||
// fast_connect_try = 0;
|
||||
// //fast_connect_failed = 1;
|
||||
// bk_printf("No fast connect info, fallback to normal connect\n");
|
||||
// // 调用普通连接流程
|
||||
// }
|
||||
}
|
||||
|
||||
//wifi初始化连接
|
||||
void wifi_init(){
|
||||
wifi_read_info(last_ssid, sizeof(last_ssid), last_password, sizeof(last_password),
|
||||
last_bssid, sizeof(last_bssid), last_channel, sizeof(last_channel), last_security, sizeof(last_security));
|
||||
|
||||
//fast_connect_wifi();
|
||||
|
||||
if(last_ssid[0] != '\0' && last_password[0] != '\0') {
|
||||
bk_printf("Auto connect WiFi: SSID=%s, PASSWORD=%s\r\n", last_ssid, last_password);
|
||||
bk_printf("BSSID: %s\n", last_bssid);
|
||||
bk_printf("Channel: %s\n", last_channel);
|
||||
bk_printf("Security: %s\n", last_security);
|
||||
connnect_wifi(last_ssid, last_password);
|
||||
}else{
|
||||
bk_printf("NOT WiFi INFO\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
void poka_client_username(time_t now){
|
||||
rt_tick_t tick = rt_tick_get();
|
||||
uint32_t ms_part = (tick % RT_TICK_PER_SECOND) * 1000 / RT_TICK_PER_SECOND;
|
||||
uint64_t ms = ((uint64_t)now) * 1000 + ms_part;
|
||||
snprintf(mqtt_username, sizeof(mqtt_username), "%s|%llu", SECUREID_MQTT, (unsigned long long)ms);
|
||||
}
|
||||
|
||||
void poka_client_password(){
|
||||
char input[512];
|
||||
unsigned char md5sum[16];
|
||||
int i;
|
||||
|
||||
// 拼接 username 和 SECUREKEY_MQTT
|
||||
snprintf(input, sizeof(input), "%s|%s", mqtt_username, SECUREKEY_MQTT);
|
||||
MD5_CTX ctx;
|
||||
MMD5Init(&ctx);
|
||||
MMD5Update(&ctx, (unsigned char *)input, strlen(input));
|
||||
MMD5Final(&ctx,md5sum);
|
||||
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
sprintf(mqtt_password + i * 2, "%02x", md5sum[i]);
|
||||
mqtt_password[32] = '\0';
|
||||
|
||||
rt_kprintf("username=%s\r\n",mqtt_username);
|
||||
rt_kprintf("password=%s\r\n", mqtt_password);
|
||||
}
|
||||
|
||||
void record_init(void){
|
||||
app_detect_record_t record;
|
||||
@ -1440,6 +1286,8 @@ void temperature_init(void){
|
||||
rtos_init_timer(&timer_poweroff, BLE_TEMPERATURE_POWEROFF_TIMEOUT, box_poweroff_timeout_callback, NULL);
|
||||
rtos_init_timer(&timer_bind, BLE_TEMPERATURE_BIND_MODE_TIMEOUT, box_bind_timeout_callback, NULL);
|
||||
rtos_init_timer(&timer_idle, BLE_TEMPERATURE_IDLE_MODE_TIMEOUT, timer_app_idle_callback, NULL);
|
||||
|
||||
|
||||
//初始化电量
|
||||
box_init_power();
|
||||
//user_app_start();
|
||||
@ -1460,9 +1308,11 @@ void temperature_init(void){
|
||||
//app_enter_ui(UI_WAIT_TEMPERATURE);
|
||||
|
||||
//注册WIFI回调
|
||||
//bk_wlan_status_register_cb(wifi_status_cb);
|
||||
bk_wlan_status_register_cb(wifi_status_cb);
|
||||
//自动联网
|
||||
//if(wifi_auto_connect)
|
||||
wifi_init();
|
||||
rt_thread_mdelay(3000);
|
||||
|
||||
//初始化BLE
|
||||
belon_ble_active();
|
||||
@ -1475,9 +1325,11 @@ void temperature_init(void){
|
||||
//启动定时器 定时更新温度显示
|
||||
rtos_init_timer(&timer_detect, BLE_TEMPERATURE_DETECT_DEVICE_INTERVAL, timer_check_device_run_callback, NULL);
|
||||
rtos_start_timer(&timer_detect);
|
||||
rtos_init_timer(&timer_battery_refresh, 2000, timer_battery_refresh_callback, NULL);
|
||||
//rtos_start_timer(&timer_battery_refresh);
|
||||
|
||||
rtos_init_timer(&timer_charge_hell, 300000, timer_hall_detect_callback, NULL);
|
||||
rtos_start_timer(&timer_charge_hell);
|
||||
//rtos_init_timer(&timer_charge_hell, 300000, timer_hall_detect_callback, NULL);
|
||||
//rtos_start_timer(&timer_charge_hell);
|
||||
|
||||
charger_module_enable(0);
|
||||
//sctrl_ctrl(CMD_SCTRL_USB_CHARGE_STOP, 0);
|
||||
|
@ -106,8 +106,8 @@
|
||||
/**
|
||||
* MQTT ID and KEY
|
||||
*/
|
||||
#define SECUREID_MQTT "pokaAdmin"
|
||||
#define SECUREKEY_MQTT "poka@123456"
|
||||
#define SECUREID_MQTT "poka"
|
||||
#define SECUREKEY_MQTT "Poka&Lock12345"
|
||||
|
||||
/**
|
||||
* 配置文件easyflah KEY BIND MAC
|
||||
@ -127,6 +127,674 @@
|
||||
*/
|
||||
#define BLE_TEMPERATURE_FLASH_RECORD_KEY_VOLUME "m1_volume"
|
||||
|
||||
#define BATTERY_TABLE_SIZE 662 // 查表法数据点数量
|
||||
static const struct {
|
||||
u16 voltage; // 电压值(mV)
|
||||
u32 mah; // 对应电量
|
||||
} voltage_table[BATTERY_TABLE_SIZE] = {
|
||||
{4179, 0},
|
||||
{4174, 670},
|
||||
{4171, 1340},
|
||||
{4169, 2020},
|
||||
{4166, 2690},
|
||||
{4164, 3360},
|
||||
{4160, 4030},
|
||||
{4159, 4700},
|
||||
{4156, 5370},
|
||||
{4153, 6050},
|
||||
{4151, 6720},
|
||||
{4148, 7390},
|
||||
{4145, 8060},
|
||||
{4143, 8730},
|
||||
{4140, 9400},
|
||||
{4138, 10070},
|
||||
{4135, 10750},
|
||||
{4133, 11420},
|
||||
{4129, 12090},
|
||||
{4125, 12760},
|
||||
{4122, 13430},
|
||||
{4120, 14100},
|
||||
{4116, 14770},
|
||||
{4112, 15450},
|
||||
{4109, 16120},
|
||||
{4106, 16790},
|
||||
{4101, 17460},
|
||||
{4096, 18130},
|
||||
{4093, 18800},
|
||||
{4087, 19470},
|
||||
{4082, 20150},
|
||||
{4078, 20820},
|
||||
{4074, 21490},
|
||||
{4068, 22160},
|
||||
{4064, 22830},
|
||||
{4059, 23510},
|
||||
{4055, 24180},
|
||||
{4050, 24850},
|
||||
{4046, 25520},
|
||||
{4042, 26190},
|
||||
{4038, 26860},
|
||||
{4034, 27530},
|
||||
{4031, 28210},
|
||||
{4028, 28880},
|
||||
{4024, 29550},
|
||||
{4020, 30220},
|
||||
{4018, 30890},
|
||||
{4015, 31560},
|
||||
{4013, 32240},
|
||||
{4009, 32910},
|
||||
{4007, 33580},
|
||||
{4005, 34250},
|
||||
{4002, 34920},
|
||||
{4000, 35600},
|
||||
{3997, 36270},
|
||||
{3995, 36940},
|
||||
{3992, 37610},
|
||||
{3991, 38280},
|
||||
{3988, 38950},
|
||||
{3986, 39620},
|
||||
{3983, 40290},
|
||||
{3983, 40970},
|
||||
{3980, 41640},
|
||||
{3977, 42310},
|
||||
{3976, 42980},
|
||||
{3973, 43650},
|
||||
{3972, 44320},
|
||||
{3970, 44990},
|
||||
{3968, 45670},
|
||||
{3966, 46340},
|
||||
{3964, 47010},
|
||||
{3961, 47680},
|
||||
{3960, 48350},
|
||||
{3957, 49020},
|
||||
{3956, 49700},
|
||||
{3954, 50370},
|
||||
{3953, 51040},
|
||||
{3950, 51710},
|
||||
{3948, 52380},
|
||||
{3946, 53060},
|
||||
{3945, 53730},
|
||||
{3943, 54400},
|
||||
{3942, 55070},
|
||||
{3940, 55740},
|
||||
{3938, 56410},
|
||||
{3935, 57080},
|
||||
{3935, 57760},
|
||||
{3933, 58430},
|
||||
{3931, 59100},
|
||||
{3929, 59770},
|
||||
{3928, 60440},
|
||||
{3925, 61110},
|
||||
{3923, 61780},
|
||||
{3923, 62460},
|
||||
{3920, 63130},
|
||||
{3918, 63800},
|
||||
{3917, 64470},
|
||||
{3915, 65140},
|
||||
{3914, 65810},
|
||||
{3912, 66480},
|
||||
{3910, 67160},
|
||||
{3909, 67830},
|
||||
{3908, 68500},
|
||||
{3906, 69170},
|
||||
{3904, 69840},
|
||||
{3902, 70510},
|
||||
{3900, 71190},
|
||||
{3899, 71860},
|
||||
{3898, 72530},
|
||||
{3896, 73200},
|
||||
{3894, 73870},
|
||||
{3892, 74540},
|
||||
{3890, 75210},
|
||||
{3889, 75890},
|
||||
{3888, 76560},
|
||||
{3887, 77230},
|
||||
{3884, 77900},
|
||||
{3882, 78570},
|
||||
{3881, 79240},
|
||||
{3879, 79920},
|
||||
{3878, 80590},
|
||||
{3876, 81260},
|
||||
{3874, 81930},
|
||||
{3872, 82600},
|
||||
{3871, 83270},
|
||||
{3870, 83940},
|
||||
{3869, 84620},
|
||||
{3867, 85290},
|
||||
{3865, 85960},
|
||||
{3864, 86630},
|
||||
{3862, 87300},
|
||||
{3860, 87970},
|
||||
{3859, 88640},
|
||||
{3857, 89320},
|
||||
{3855, 89990},
|
||||
{3855, 90660},
|
||||
{3853, 91330},
|
||||
{3851, 92000},
|
||||
{3850, 92680},
|
||||
{3848, 93350},
|
||||
{3846, 94020},
|
||||
{3845, 94690},
|
||||
{3844, 95360},
|
||||
{3840, 96030},
|
||||
{3840, 96700},
|
||||
{3839, 97370},
|
||||
{3837, 98050},
|
||||
{3835, 98720},
|
||||
{3834, 99390},
|
||||
{3832, 100060},
|
||||
{3830, 100730},
|
||||
{3830, 101400},
|
||||
{3829, 102080},
|
||||
{3826, 102750},
|
||||
{3825, 103420},
|
||||
{3823, 104090},
|
||||
{3821, 104760},
|
||||
{3819, 105430},
|
||||
{3819, 106100},
|
||||
{3816, 106770},
|
||||
{3815, 107450},
|
||||
{3814, 108120},
|
||||
{3812, 108790},
|
||||
{3811, 109460},
|
||||
{3809, 110130},
|
||||
{3808, 110800},
|
||||
{3806, 111470},
|
||||
{3805, 112140},
|
||||
{3804, 112820},
|
||||
{3803, 113490},
|
||||
{3800, 114160},
|
||||
{3799, 114830},
|
||||
{3798, 115500},
|
||||
{3796, 116170},
|
||||
{3794, 116840},
|
||||
{3794, 117510},
|
||||
{3792, 118190},
|
||||
{3789, 118860},
|
||||
{3789, 119530},
|
||||
{3788, 120200},
|
||||
{3787, 120870},
|
||||
{3784, 121540},
|
||||
{3783, 122210},
|
||||
{3780, 122890},
|
||||
{3780, 123560},
|
||||
{3778, 124230},
|
||||
{3777, 124900},
|
||||
{3776, 125570},
|
||||
{3774, 126240},
|
||||
{3772, 126920},
|
||||
{3771, 127590},
|
||||
{3769, 128260},
|
||||
{3769, 128930},
|
||||
{3768, 129600},
|
||||
{3766, 130270},
|
||||
{3765, 130940},
|
||||
{3763, 131620},
|
||||
{3761, 132290},
|
||||
{3760, 132960},
|
||||
{3758, 133630},
|
||||
{3757, 134300},
|
||||
{3755, 134970},
|
||||
{3754, 135640},
|
||||
{3754, 136310},
|
||||
{3752, 136990},
|
||||
{3750, 137660},
|
||||
{3749, 138330},
|
||||
{3748, 139000},
|
||||
{3746, 139670},
|
||||
{3745, 140340},
|
||||
{3743, 141010},
|
||||
{3742, 141690},
|
||||
{3741, 142360},
|
||||
{3740, 143030},
|
||||
{3738, 143700},
|
||||
{3738, 144370},
|
||||
{3735, 145040},
|
||||
{3734, 145710},
|
||||
{3732, 146380},
|
||||
{3732, 147060},
|
||||
{3730, 147730},
|
||||
{3729, 148400},
|
||||
{3727, 149070},
|
||||
{3726, 149740},
|
||||
{3725, 150410},
|
||||
{3723, 151090},
|
||||
{3722, 151760},
|
||||
{3720, 152430},
|
||||
{3720, 153100},
|
||||
{3717, 153770},
|
||||
{3716, 154440},
|
||||
{3716, 155110},
|
||||
{3714, 155790},
|
||||
{3712, 156460},
|
||||
{3712, 157130},
|
||||
{3710, 157800},
|
||||
{3709, 158470},
|
||||
{3708, 159140},
|
||||
{3707, 159810},
|
||||
{3705, 160490},
|
||||
{3704, 161160},
|
||||
{3703, 161830},
|
||||
{3702, 162500},
|
||||
{3701, 163170},
|
||||
{3700, 163840},
|
||||
{3699, 164520},
|
||||
{3697, 165190},
|
||||
{3697, 165860},
|
||||
{3695, 166530},
|
||||
{3694, 167200},
|
||||
{3693, 167870},
|
||||
{3691, 168540},
|
||||
{3690, 169210},
|
||||
{3689, 169890},
|
||||
{3688, 170560},
|
||||
{3688, 171230},
|
||||
{3686, 171900},
|
||||
{3685, 172570},
|
||||
{3683, 173240},
|
||||
{3683, 173920},
|
||||
{3681, 174590},
|
||||
{3680, 175260},
|
||||
{3679, 175930},
|
||||
{3678, 176600},
|
||||
{3677, 177270},
|
||||
{3677, 177940},
|
||||
{3677, 178610},
|
||||
{3673, 179290},
|
||||
{3673, 179960},
|
||||
{3672, 180630},
|
||||
{3672, 181300},
|
||||
{3672, 181970},
|
||||
{3669, 182650},
|
||||
{3668, 183320},
|
||||
{3668, 183990},
|
||||
{3666, 184660},
|
||||
{3666, 185330},
|
||||
{3665, 186000},
|
||||
{3664, 186670},
|
||||
{3664, 187350},
|
||||
{3662, 188020},
|
||||
{3661, 188690},
|
||||
{3661, 189360},
|
||||
{3659, 190030},
|
||||
{3658, 190700},
|
||||
{3657, 191380},
|
||||
{3656, 192050},
|
||||
{3656, 192720},
|
||||
{3654, 193390},
|
||||
{3654, 194060},
|
||||
{3653, 194740},
|
||||
{3653, 195410},
|
||||
{3652, 196080},
|
||||
{3650, 196750},
|
||||
{3649, 197420},
|
||||
{3648, 198090},
|
||||
{3647, 198770},
|
||||
{3647, 199440},
|
||||
{3646, 200110},
|
||||
{3645, 200780},
|
||||
{3646, 201450},
|
||||
{3644, 202120},
|
||||
{3642, 202800},
|
||||
{3642, 203470},
|
||||
{3642, 204140},
|
||||
{3640, 204810},
|
||||
{3641, 205480},
|
||||
{3639, 206150},
|
||||
{3638, 206820},
|
||||
{3638, 207500},
|
||||
{3637, 208170},
|
||||
{3637, 208840},
|
||||
{3637, 209510},
|
||||
{3636, 210180},
|
||||
{3636, 210850},
|
||||
{3635, 211530},
|
||||
{3633, 212200},
|
||||
{3633, 212870},
|
||||
{3632, 213540},
|
||||
{3632, 214210},
|
||||
{3631, 214880},
|
||||
{3629, 215550},
|
||||
{3628, 216220},
|
||||
{3628, 216900},
|
||||
{3627, 217570},
|
||||
{3626, 218240},
|
||||
{3626, 218910},
|
||||
{3626, 219580},
|
||||
{3625, 220250},
|
||||
{3625, 220920},
|
||||
{3625, 221600},
|
||||
{3623, 222270},
|
||||
{3621, 222940},
|
||||
{3621, 223610},
|
||||
{3621, 224280},
|
||||
{3621, 224950},
|
||||
{3620, 225620},
|
||||
{3620, 226300},
|
||||
{3619, 226970},
|
||||
{3619, 227640},
|
||||
{3618, 228310},
|
||||
{3617, 228980},
|
||||
{3617, 229650},
|
||||
{3617, 230330},
|
||||
{3616, 231000},
|
||||
{3615, 231670},
|
||||
{3614, 232340},
|
||||
{3613, 233010},
|
||||
{3612, 233680},
|
||||
{3612, 234350},
|
||||
{3612, 235020},
|
||||
{3612, 235700},
|
||||
{3610, 236370},
|
||||
{3610, 237040},
|
||||
{3610, 237710},
|
||||
{3610, 238380},
|
||||
{3609, 239050},
|
||||
{3608, 239730},
|
||||
{3607, 240400},
|
||||
{3606, 241070},
|
||||
{3606, 241740},
|
||||
{3606, 242410},
|
||||
{3605, 243080},
|
||||
{3605, 243750},
|
||||
{3605, 244420},
|
||||
{3603, 245090},
|
||||
{3603, 245770},
|
||||
{3602, 246440},
|
||||
{3601, 247110},
|
||||
{3601, 247780},
|
||||
{3601, 248450},
|
||||
{3601, 249120},
|
||||
{3599, 249790},
|
||||
{3598, 250470},
|
||||
{3597, 251140},
|
||||
{3597, 251810},
|
||||
{3597, 252480},
|
||||
{3596, 253150},
|
||||
{3596, 253820},
|
||||
{3595, 254490},
|
||||
{3594, 255160},
|
||||
{3594, 255840},
|
||||
{3594, 256510},
|
||||
{3593, 257180},
|
||||
{3593, 257850},
|
||||
{3593, 258520},
|
||||
{3592, 259190},
|
||||
{3592, 259870},
|
||||
{3591, 260540},
|
||||
{3590, 261210},
|
||||
{3590, 261880},
|
||||
{3590, 262550},
|
||||
{3588, 263220},
|
||||
{3588, 263890},
|
||||
{3587, 264570},
|
||||
{3587, 265240},
|
||||
{3586, 265910},
|
||||
{3586, 266580},
|
||||
{3585, 267250},
|
||||
{3585, 267920},
|
||||
{3584, 268590},
|
||||
{3583, 269260},
|
||||
{3583, 269940},
|
||||
{3583, 270610},
|
||||
{3583, 271280},
|
||||
{3581, 271950},
|
||||
{3581, 272620},
|
||||
{3580, 273290},
|
||||
{3580, 273960},
|
||||
{3579, 274640},
|
||||
{3579, 275310},
|
||||
{3578, 275980},
|
||||
{3577, 276650},
|
||||
{3577, 277320},
|
||||
{3578, 277990},
|
||||
{3577, 278660},
|
||||
{3577, 279340},
|
||||
{3575, 280010},
|
||||
{3575, 280680},
|
||||
{3575, 281350},
|
||||
{3574, 282020},
|
||||
{3574, 282690},
|
||||
{3574, 283370},
|
||||
{3572, 284040},
|
||||
{3571, 284710},
|
||||
{3571, 285380},
|
||||
{3570, 286050},
|
||||
{3570, 286720},
|
||||
{3570, 287390},
|
||||
{3569, 288070},
|
||||
{3568, 288740},
|
||||
{3567, 289410},
|
||||
{3567, 290080},
|
||||
{3568, 290750},
|
||||
{3567, 291420},
|
||||
{3566, 292090},
|
||||
{3566, 292770},
|
||||
{3565, 293440},
|
||||
{3564, 294110},
|
||||
{3565, 294780},
|
||||
{3564, 295450},
|
||||
{3563, 296120},
|
||||
{3562, 296790},
|
||||
{3562, 297470},
|
||||
{3561, 298140},
|
||||
{3561, 298810},
|
||||
{3560, 299480},
|
||||
{3559, 300150},
|
||||
{3559, 300820},
|
||||
{3558, 301500},
|
||||
{3558, 302170},
|
||||
{3557, 302840},
|
||||
{3557, 303510},
|
||||
{3556, 304180},
|
||||
{3555, 304850},
|
||||
{3554, 305520},
|
||||
{3554, 306190},
|
||||
{3553, 306870},
|
||||
{3553, 307540},
|
||||
{3552, 308210},
|
||||
{3551, 308880},
|
||||
{3551, 309550},
|
||||
{3551, 310220},
|
||||
{3551, 310890},
|
||||
{3549, 311570},
|
||||
{3549, 312240},
|
||||
{3548, 312910},
|
||||
{3548, 313580},
|
||||
{3547, 314250},
|
||||
{3547, 314920},
|
||||
{3545, 315590},
|
||||
{3545, 316270},
|
||||
{3544, 316940},
|
||||
{3544, 317610},
|
||||
{3543, 318280},
|
||||
{3542, 318950},
|
||||
{3542, 319620},
|
||||
{3541, 320300},
|
||||
{3541, 320970},
|
||||
{3541, 321640},
|
||||
{3540, 322310},
|
||||
{3540, 322980},
|
||||
{3538, 323660},
|
||||
{3537, 324330},
|
||||
{3537, 325000},
|
||||
{3536, 325670},
|
||||
{3537, 326340},
|
||||
{3536, 327010},
|
||||
{3535, 327680},
|
||||
{3534, 328360},
|
||||
{3533, 329030},
|
||||
{3532, 329700},
|
||||
{3532, 330370},
|
||||
{3531, 331040},
|
||||
{3531, 331710},
|
||||
{3530, 332380},
|
||||
{3530, 333050},
|
||||
{3529, 333730},
|
||||
{3528, 334400},
|
||||
{3528, 335070},
|
||||
{3527, 335740},
|
||||
{3526, 336410},
|
||||
{3526, 337080},
|
||||
{3525, 337750},
|
||||
{3524, 338430},
|
||||
{3522, 339100},
|
||||
{3522, 339770},
|
||||
{3522, 340440},
|
||||
{3521, 341110},
|
||||
{3520, 341780},
|
||||
{3520, 342450},
|
||||
{3518, 343120},
|
||||
{3517, 343800},
|
||||
{3517, 344470},
|
||||
{3515, 345140},
|
||||
{3516, 345810},
|
||||
{3515, 346480},
|
||||
{3513, 347150},
|
||||
{3513, 347820},
|
||||
{3513, 348490},
|
||||
{3512, 349170},
|
||||
{3511, 349840},
|
||||
{3510, 350510},
|
||||
{3509, 351180},
|
||||
{3508, 351850},
|
||||
{3508, 352520},
|
||||
{3506, 353190},
|
||||
{3506, 353860},
|
||||
{3504, 354530},
|
||||
{3504, 355200},
|
||||
{3505, 355880},
|
||||
{3504, 356550},
|
||||
{3501, 357220},
|
||||
{3501, 357890},
|
||||
{3500, 358560},
|
||||
{3500, 359230},
|
||||
{3499, 359900},
|
||||
{3498, 360570},
|
||||
{3497, 361240},
|
||||
{3496, 361910},
|
||||
{3495, 362580},
|
||||
{3494, 363260},
|
||||
{3493, 363930},
|
||||
{3491, 364600},
|
||||
{3490, 365270},
|
||||
{3490, 365940},
|
||||
{3490, 366610},
|
||||
{3488, 367280},
|
||||
{3487, 367950},
|
||||
{3486, 368620},
|
||||
{3486, 369290},
|
||||
{3485, 369960},
|
||||
{3484, 370630},
|
||||
{3482, 371300},
|
||||
{3482, 371970},
|
||||
{3481, 372640},
|
||||
{3479, 373320},
|
||||
{3479, 373990},
|
||||
{3477, 374660},
|
||||
{3476, 375330},
|
||||
{3475, 376000},
|
||||
{3473, 376670},
|
||||
{3472, 377340},
|
||||
{3470, 378010},
|
||||
{3469, 378680},
|
||||
{3469, 379350},
|
||||
{3469, 380020},
|
||||
{3467, 380690},
|
||||
{3465, 381370},
|
||||
{3464, 382040},
|
||||
{3464, 382710},
|
||||
{3463, 383380},
|
||||
{3460, 384050},
|
||||
{3460, 384720},
|
||||
{3459, 385390},
|
||||
{3456, 386060},
|
||||
{3457, 386730},
|
||||
{3455, 387400},
|
||||
{3454, 388080},
|
||||
{3453, 388750},
|
||||
{3451, 389420},
|
||||
{3449, 390090},
|
||||
{3449, 390760},
|
||||
{3446, 391430},
|
||||
{3445, 392100},
|
||||
{3444, 392770},
|
||||
{3443, 393440},
|
||||
{3441, 394110},
|
||||
{3439, 394780},
|
||||
{3438, 395450},
|
||||
{3438, 396130},
|
||||
{3436, 396800},
|
||||
{3434, 397470},
|
||||
{3433, 398140},
|
||||
{3430, 398810},
|
||||
{3429, 399480},
|
||||
{3428, 400150},
|
||||
{3427, 400820},
|
||||
{3425, 401490},
|
||||
{3424, 402160},
|
||||
{3422, 402840},
|
||||
{3421, 403510},
|
||||
{3419, 404180},
|
||||
{3417, 404850},
|
||||
{3416, 405520},
|
||||
{3415, 406190},
|
||||
{3412, 406860},
|
||||
{3411, 407530},
|
||||
{3409, 408200},
|
||||
{3408, 408870},
|
||||
{3407, 409540},
|
||||
{3406, 410210},
|
||||
{3404, 410880},
|
||||
{3403, 411560},
|
||||
{3401, 412230},
|
||||
{3399, 412900},
|
||||
{3398, 413570},
|
||||
{3396, 414240},
|
||||
{3394, 414910},
|
||||
{3393, 415580},
|
||||
{3391, 416250},
|
||||
{3389, 416920},
|
||||
{3386, 417590},
|
||||
{3384, 418260},
|
||||
{3382, 418930},
|
||||
{3381, 419610},
|
||||
{3379, 420280},
|
||||
{3376, 420950},
|
||||
{3375, 421620},
|
||||
{3372, 422290},
|
||||
{3369, 422960},
|
||||
{3367, 423630},
|
||||
{3364, 424300},
|
||||
{3361, 424970},
|
||||
{3358, 425640},
|
||||
{3354, 426310},
|
||||
{3351, 426980},
|
||||
{3348, 427650},
|
||||
{3343, 428330},
|
||||
{3339, 429000},
|
||||
{3335, 429670},
|
||||
{3331, 430340},
|
||||
{3324, 431010},
|
||||
{3318, 431680},
|
||||
{3312, 432350},
|
||||
{3305, 433020},
|
||||
{3297, 433690},
|
||||
{3289, 434360},
|
||||
{3280, 435030},
|
||||
{3269, 435700},
|
||||
{3257, 436370},
|
||||
{3245, 437040},
|
||||
{3229, 437710},
|
||||
{3212, 438380},
|
||||
{3193, 439050},
|
||||
{3174, 439720},
|
||||
{3151, 440390},
|
||||
{3125, 441060},
|
||||
{3096, 441740},
|
||||
{3065, 442410},
|
||||
{3029, 443080},
|
||||
{3000, 443570}
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -207,6 +875,7 @@ void temperature_adv_callback(recv_adv_t *r_ind);
|
||||
void app_enter_bind_mode(bool enter);
|
||||
void mqtt_upload_temperature(uint16_t t_value);
|
||||
int mqtt_start(char username[],char password[]);
|
||||
int mqtt_start2(char* username,char *password ,char * client_id);
|
||||
void poka_client_password();
|
||||
void poka_client_username();
|
||||
void connnect_wifi(char *oob_ssid,char *connect_key);
|
||||
|
299
beken_rtt_sdk_release-SDK_3.0.76/applications/app_wifi.c
Normal file
299
beken_rtt_sdk_release-SDK_3.0.76/applications/app_wifi.c
Normal file
@ -0,0 +1,299 @@
|
||||
#include <rtthread.h>
|
||||
#include <finsh.h>
|
||||
#include "common.h"
|
||||
#include "param_config.h"
|
||||
#include "ble_pub.h"
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "wlan_ui_pub.h"
|
||||
#include "sys_ctrl_pub.h"
|
||||
#include "sys_ctrl.h"
|
||||
#include "target_util_pub.h"
|
||||
#include "drv_model_pub.h"
|
||||
#include "md5.h"
|
||||
#include "app_temperature.h"
|
||||
#include "BkDriverFlash.h"
|
||||
#include "manual_ps_pub.h"
|
||||
#ifdef PKG_USING_EASYFLASH
|
||||
#include "easyflash.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "mqtt_client.h"
|
||||
|
||||
extern mqtt_client client;
|
||||
|
||||
//WIFI信息
|
||||
extern char last_ssid[33] ;
|
||||
extern char last_password[65];
|
||||
char last_bssid[65];
|
||||
char last_channel[65];
|
||||
char last_security[65];
|
||||
|
||||
network_InitTypeDef_adv_st adv_config;
|
||||
|
||||
//MQTT账号密码
|
||||
char mqtt_username[128]={0};
|
||||
char mqtt_password[128]={0};
|
||||
|
||||
extern char g_sta_mac[6];
|
||||
|
||||
//MQTT上传温度
|
||||
void mqtt_upload_temperature(uint16_t t_value){
|
||||
uint16_t xy = t_value/10; //整数
|
||||
// uint16_t y = xy % 10 ;//个位
|
||||
// uint16_t x = (xy / 10) % 10 ;//十位
|
||||
// uint16_t z = t_value/10%10 ;//小数位
|
||||
char msg[128];
|
||||
char *topic_properties =(char *)os_malloc(128);
|
||||
char device_id [64];
|
||||
rt_memset(device_id,0,sizeof(device_id));
|
||||
rt_sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
PRODUCTID,g_sta_mac[0],g_sta_mac[1],g_sta_mac[2],g_sta_mac[3],g_sta_mac[4],g_sta_mac[5]);
|
||||
|
||||
os_memset(topic_properties,0,128);
|
||||
rt_sprintf(topic_properties, "/%s/%s/properties/report", PRODUCTID, device_id);
|
||||
|
||||
rt_sprintf(msg, "{\"properties\": {\"temperature\":%d}}", xy);
|
||||
paho_mqtt_publish(&client, QOS1, topic_properties, msg, strlen(msg));
|
||||
bk_printf("MQTT publish: %s\n", msg);
|
||||
bk_printf("device_id: %s\n", device_id);
|
||||
os_free(topic_properties);
|
||||
}
|
||||
|
||||
void mqtt_upload_boxbat(uint16_t b_value){
|
||||
uint16_t xy = b_value; //整数
|
||||
// uint16_t y = xy % 10 ;//个位
|
||||
// uint16_t x = (xy / 10) % 10 ;//十位
|
||||
// uint16_t z = t_value/10%10 ;//小数位
|
||||
char msg[128];
|
||||
char *topic_properties =(char *)os_malloc(128);
|
||||
char device_id [64];
|
||||
rt_memset(device_id,0,sizeof(device_id));
|
||||
rt_sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
PRODUCTID,g_sta_mac[0],g_sta_mac[1],g_sta_mac[2],g_sta_mac[3],g_sta_mac[4],g_sta_mac[5]);
|
||||
|
||||
os_memset(topic_properties,0,128);
|
||||
rt_sprintf(topic_properties, "/%s/%s/properties/report", PRODUCTID, device_id);
|
||||
|
||||
rt_sprintf(msg, "{\"properties\": {\"box_bat\":%d}}", xy);
|
||||
paho_mqtt_publish(&client, QOS1, topic_properties, msg, strlen(msg));
|
||||
bk_printf("MQTT publish: %s\n", msg);
|
||||
bk_printf("device_id: %s\n", device_id);
|
||||
os_free(topic_properties);
|
||||
}
|
||||
|
||||
void mqtt_upload_bat(uint16_t b_value){
|
||||
uint16_t xy = b_value; //整数
|
||||
// uint16_t y = xy % 10 ;//个位
|
||||
// uint16_t x = (xy / 10) % 10 ;//十位
|
||||
// uint16_t z = t_value/10%10 ;//小数位
|
||||
char msg[128];
|
||||
char *topic_properties =(char *)os_malloc(128);
|
||||
char device_id [64];
|
||||
rt_memset(device_id,0,sizeof(device_id));
|
||||
rt_sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
PRODUCTID,g_sta_mac[0],g_sta_mac[1],g_sta_mac[2],g_sta_mac[3],g_sta_mac[4],g_sta_mac[5]);
|
||||
|
||||
os_memset(topic_properties,0,128);
|
||||
rt_sprintf(topic_properties, "/%s/%s/properties/report", PRODUCTID, device_id);
|
||||
|
||||
rt_sprintf(msg, "{\"properties\": {\"bat\":%d}}", xy);
|
||||
paho_mqtt_publish(&client, QOS1, topic_properties, msg, strlen(msg));
|
||||
bk_printf("MQTT publish: %s\n", msg);
|
||||
bk_printf("device_id: %s\n", device_id);
|
||||
os_free(topic_properties);
|
||||
}
|
||||
|
||||
void connnect_wifi(char *oob_ssid,char *connect_key){//连接wifi
|
||||
/*定义一个结构体,用于传入参数*/
|
||||
network_InitTypeDef_st wNetConfig;
|
||||
int len;
|
||||
|
||||
/*把这个结构体置空*/
|
||||
os_memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
|
||||
|
||||
/*检查SSID的长度,不能超过32字节*/
|
||||
len = os_strlen(oob_ssid);
|
||||
if(SSID_MAX_LEN < len)
|
||||
{
|
||||
bk_printf("ssid name more than 32 Bytes\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*将SSID跟密码传入结构体*/
|
||||
os_strcpy((char *)wNetConfig.wifi_ssid, oob_ssid);
|
||||
os_strcpy((char *)wNetConfig.wifi_key, connect_key);
|
||||
|
||||
/*当前为客户端模式*/
|
||||
wNetConfig.wifi_mode = BK_STATION;
|
||||
/*采用DHCP CLIENT的方式获得,从路由器动态获取IP地址*/
|
||||
wNetConfig.dhcp_mode = DHCP_CLIENT;
|
||||
wNetConfig.wifi_retry_interval = 100;
|
||||
bk_printf("ssid:%s key:%s\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
|
||||
/*启动WiFi连接*/
|
||||
bk_wlan_start(&wNetConfig);
|
||||
//rt_thread_mdelay(5000);
|
||||
}
|
||||
|
||||
// 读取最新联网信息
|
||||
void wifi_read_info(char *ssid, size_t ssid_len, char *password, size_t pass_len,
|
||||
char *bssid, size_t bssid_len, char *channel, size_t channel_len, char *security, size_t security_len){
|
||||
|
||||
char *t_ssid = ef_get_env(BLE_WIFI_FLASH_KEY_SSID);
|
||||
char *t_pass = ef_get_env(BLE_WIFI_FLASH_KEY_PASS);
|
||||
char *t_bssid = ef_get_env(BLE_WIFI_FLASH_KEY_BSSID);
|
||||
char *t_channel = ef_get_env(BLE_WIFI_FLASH_KEY_CHANNEL);
|
||||
char *t_security = ef_get_env(BLE_WIFI_FLASH_KEY_SECURITY);
|
||||
|
||||
if(t_ssid) {
|
||||
strncpy(last_ssid, t_ssid, ssid_len - 1);
|
||||
last_ssid[ssid_len - 1] = '\0';
|
||||
}
|
||||
if(t_pass) {
|
||||
strncpy(last_password, t_pass, pass_len - 1);
|
||||
last_password[pass_len - 1] = '\0';
|
||||
}
|
||||
if (t_bssid) {
|
||||
strncpy(bssid, t_bssid, bssid_len - 1);
|
||||
bssid[bssid_len - 1] = '\0';
|
||||
}
|
||||
if (t_channel) {
|
||||
strncpy(channel, t_channel, channel_len - 1);
|
||||
channel[channel_len - 1] = '\0';
|
||||
}
|
||||
if (t_security) {
|
||||
strncpy(security, t_security, security_len - 1);
|
||||
security[security_len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
//将flash存储的mac地址字符串转换为二进制格式
|
||||
void mac_string_to_binary(const char *mac_str, uint8_t *mac_bin) {
|
||||
if (!mac_str || !mac_bin) return;
|
||||
|
||||
char temp[18];
|
||||
strncpy(temp, mac_str, sizeof(temp)-1);
|
||||
temp[sizeof(temp)-1] = '\0';
|
||||
|
||||
for (int i = 0; temp[i]; i++) {
|
||||
temp[i] = toupper(temp[i]);
|
||||
}
|
||||
|
||||
char *p = temp;
|
||||
char *end = temp + strlen(temp);
|
||||
while (p < end) {
|
||||
if (*p == ':' || *p == '-') {
|
||||
memmove(p, p+1, end - p);
|
||||
end--;
|
||||
} else {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(temp) != 12) {
|
||||
bk_printf("Invalid MAC length: %d\n", strlen(temp));
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
char byte_str[3] = { temp[i*2], temp[i*2+1], '\0' };
|
||||
char *endptr;
|
||||
mac_bin[i] = (uint8_t)strtol(byte_str, &endptr, 16);
|
||||
|
||||
if (*endptr != '\0') {
|
||||
bk_printf("MAC conversion error at position %d\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//int fast_connect_try = 0;
|
||||
//快速连接
|
||||
void fast_connect_wifi(){
|
||||
// 检查是否有效
|
||||
// if (fci.ssid[0] != 0 && strlen((char*)fci.ssid) < 32) {
|
||||
uint8_t mac_bin[6] ={0};
|
||||
int sec_value = atoi(last_security);
|
||||
|
||||
memset(&adv_config, 0, sizeof(adv_config));
|
||||
strncpy(adv_config.ap_info.ssid, last_ssid, sizeof(adv_config.ap_info.ssid));
|
||||
adv_config.ap_info.ssid[sizeof(adv_config.ap_info.ssid)-1] = '\0';
|
||||
|
||||
mac_string_to_binary(last_bssid, mac_bin);
|
||||
memcpy(adv_config.ap_info.bssid, mac_bin, 6);
|
||||
|
||||
adv_config.ap_info.channel = (uint8_t)atoi(last_channel);
|
||||
|
||||
if (sec_value >= BK_SECURITY_TYPE_NONE && sec_value <= BK_SECURITY_TYPE_AUTO) {
|
||||
adv_config.ap_info.security = (wlan_sec_type_t)sec_value;
|
||||
} else {
|
||||
adv_config.ap_info.security = BK_SECURITY_TYPE_AUTO;
|
||||
}
|
||||
|
||||
strncpy(adv_config.key, last_password, sizeof(adv_config.key));
|
||||
adv_config.key[sizeof(adv_config.key)-1] = '\0';
|
||||
adv_config.key_len = strlen(last_password);
|
||||
adv_config.dhcp_mode = DHCP_CLIENT;
|
||||
|
||||
bk_printf(" SSID: %s\n", adv_config.ap_info.ssid);
|
||||
bk_printf(" BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
adv_config.ap_info.bssid[0], adv_config.ap_info.bssid[1],
|
||||
adv_config.ap_info.bssid[2], adv_config.ap_info.bssid[3],
|
||||
adv_config.ap_info.bssid[4], adv_config.ap_info.bssid[5]);
|
||||
bk_printf(" Channel: %d\n", adv_config.ap_info.channel);
|
||||
bk_printf(" Security: %d\n", adv_config.ap_info.security);
|
||||
|
||||
bk_wlan_start_sta_adv(&adv_config);
|
||||
// } else {
|
||||
// fast_connect_try = 0;
|
||||
// //fast_connect_failed = 1;
|
||||
// bk_printf("No fast connect info, fallback to normal connect\n");
|
||||
// // 调用普通连接流程
|
||||
// }
|
||||
}
|
||||
|
||||
//wifi初始化连接
|
||||
void wifi_init(){
|
||||
wifi_read_info(last_ssid, sizeof(last_ssid), last_password, sizeof(last_password),
|
||||
last_bssid, sizeof(last_bssid), last_channel, sizeof(last_channel), last_security, sizeof(last_security));
|
||||
|
||||
//fast_connect_wifi();
|
||||
|
||||
if(last_ssid[0] != '\0' && last_password[0] != '\0') {
|
||||
bk_printf("Auto connect WiFi: SSID=%s, PASSWORD=%s\r\n", last_ssid, last_password);
|
||||
bk_printf("BSSID: %s\n", last_bssid);
|
||||
bk_printf("Channel: %s\n", last_channel);
|
||||
bk_printf("Security: %s\n", last_security);
|
||||
connnect_wifi(last_ssid, last_password);
|
||||
}else{
|
||||
bk_printf("NOT WiFi INFO\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
void poka_client_username(time_t now){
|
||||
rt_tick_t tick = rt_tick_get();
|
||||
uint32_t ms_part = (tick % RT_TICK_PER_SECOND) * 1000 / RT_TICK_PER_SECOND;
|
||||
uint64_t ms = ((uint64_t)now) * 1000 + ms_part;
|
||||
snprintf(mqtt_username, sizeof(mqtt_username), "%s|%llu", SECUREID_MQTT, (unsigned long long)ms);
|
||||
}
|
||||
|
||||
void poka_client_password(){
|
||||
char input[512];
|
||||
unsigned char md5sum[16];
|
||||
int i;
|
||||
|
||||
// 拼接 username 和 SECUREKEY_MQTT
|
||||
snprintf(input, sizeof(input), "%s|%s", mqtt_username, SECUREKEY_MQTT);
|
||||
MD5_CTX ctx;
|
||||
MMD5Init(&ctx);
|
||||
MMD5Update(&ctx, (unsigned char *)input, strlen(input));
|
||||
MMD5Final(&ctx,md5sum);
|
||||
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
sprintf(mqtt_password + i * 2, "%02x", md5sum[i]);
|
||||
mqtt_password[32] = '\0';
|
||||
|
||||
rt_kprintf("username=%s\r\n",mqtt_username);
|
||||
rt_kprintf("password=%s\r\n", mqtt_password);
|
||||
}
|
20
beken_rtt_sdk_release-SDK_3.0.76/applications/app_wifi.h
Normal file
20
beken_rtt_sdk_release-SDK_3.0.76/applications/app_wifi.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef _APP_WIFI_H_
|
||||
#define _APP_WIFI_H_
|
||||
#include <rtthread.h>
|
||||
#include <finsh.h>
|
||||
#include "common.h"
|
||||
#include "param_config.h"
|
||||
|
||||
void mqtt_upload_temperature(uint16_t t_value);
|
||||
void connnect_wifi(char *oob_ssid,char *connect_key);
|
||||
void wifi_read_info(char *ssid, size_t ssid_len, char *password, size_t pass_len,
|
||||
char *bssid, size_t bssid_len, char *channel, size_t channel_len, char *security, size_t security_len);
|
||||
void mac_string_to_binary(const char *mac_str, uint8_t *mac_bin);
|
||||
void fast_connect_wifi();
|
||||
void wifi_init();
|
||||
void poka_client_username(time_t now);
|
||||
void poka_client_password();
|
||||
void mqtt_upload_boxbat(uint16_t b_value);
|
||||
void mqtt_upload_bat(uint16_t b_value);
|
||||
|
||||
#endif
|
@ -135,7 +135,7 @@ uint8_t cli_ble_read_callback(read_req_t *read_req)
|
||||
read_req->value[2] = 0x30;
|
||||
return 3;
|
||||
}
|
||||
/*
|
||||
|
||||
static void ble_command_usage(void)
|
||||
{
|
||||
bk_printf("ble help - Help information\n");
|
||||
@ -149,12 +149,12 @@ static void ble_command_usage(void)
|
||||
|
||||
bk_printf("ble disc - Disconnect\n");
|
||||
bk_printf("ble dut - dut test\n");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void sdp_event_cb(sdp_notice_t notice, void *param)
|
||||
{
|
||||
/*switch (notice) {
|
||||
switch (notice) {
|
||||
case SDP_CHARAC_NOTIFY_EVENT:
|
||||
{
|
||||
sdp_event_t *g_sdp = (sdp_event_t *)param;
|
||||
@ -186,7 +186,7 @@ void sdp_event_cb(sdp_notice_t notice, void *param)
|
||||
default:
|
||||
bk_printf("[%s]Event:%d\r\n",__func__,notice);
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
void ble_cmd_cb(ble_cmd_t cmd, ble_cmd_param_t *param)
|
||||
@ -271,6 +271,12 @@ static void ntp_get_time_thread(void *parameter){ //获取ntp时间戳并生成m
|
||||
if (now > 0) {
|
||||
poka_client_username(now);
|
||||
poka_client_password();
|
||||
|
||||
char device_id [64]={0};
|
||||
rt_memset(device_id,0,sizeof(device_id));
|
||||
rt_sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
PRODUCTID,g_sta_mac[0],g_sta_mac[1],g_sta_mac[2],g_sta_mac[3],g_sta_mac[4],g_sta_mac[5]);
|
||||
|
||||
mqtt_start(mqtt_username, mqtt_password);
|
||||
}else{
|
||||
bk_printf("ntp_time failed!\r\n");
|
||||
@ -356,7 +362,7 @@ void wifi_status_cb(void *param){
|
||||
}
|
||||
}
|
||||
|
||||
void ble_connnect_wifi(uint8_t data[]){
|
||||
void ble_connect_wifi(uint8_t data[]){
|
||||
char ssid[33] = {0};
|
||||
char password[65] = {0};
|
||||
char *p = strchr((char *)data + 8, ',');
|
||||
@ -410,7 +416,7 @@ void ble_notice_cb(ble_notice_t notice, void *param)
|
||||
bk_wlan_start_scan();
|
||||
}
|
||||
if(strncmp((char *)data, "AT+WIFI:", 8) == 0){ //连接WiFi命令:AT+WIFI:SSID,PASSWORD
|
||||
ble_connnect_wifi(data);
|
||||
ble_connect_wifi(data);
|
||||
}
|
||||
if(strstr((char *)data,"AT+STATE")!=NULL){ //返回当前状态
|
||||
char msg[32] = "AT+STATE=0";
|
||||
@ -462,7 +468,7 @@ void ble_notice_cb(ble_notice_t notice, void *param)
|
||||
int new_volume;
|
||||
memset((void *)&record, 0, sizeof(record));
|
||||
volume_read_record(&record);
|
||||
if(sscanf((char*)data, "AT+VOLUME=%d", &new_volume) == 1) {
|
||||
if(sscanf((char*)data, "AT+SETVOICE=%d", &new_volume) == 1) {
|
||||
record.volume = new_volume;
|
||||
if(record.volume>=99)
|
||||
record.volume=99;
|
||||
@ -686,7 +692,7 @@ void ble_notice_cb(ble_notice_t notice, void *param)
|
||||
}
|
||||
|
||||
static void ble(int argc, char **argv)
|
||||
{/*
|
||||
{
|
||||
uint8_t adv_data[31];
|
||||
uint8_t actv_idx;
|
||||
if ((argc < 2) || (os_strcmp(argv[1], "help") == 0))
|
||||
@ -939,11 +945,11 @@ static void ble(int argc, char **argv)
|
||||
}else{
|
||||
bk_printf("handle(%x) error\r\n",handle);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
static void ble_advertise_start(int argc, char **argv)
|
||||
{/*
|
||||
{
|
||||
uint8_t adv_data[31];
|
||||
uint8_t actv_idx;
|
||||
uint8_t adv_data_len;
|
||||
@ -982,7 +988,7 @@ static void ble_advertise_start(int argc, char **argv)
|
||||
bk_ble_set_scan_rsp_data(actv_idx, adv_data, adv_data_len, ble_cmd_cb);
|
||||
|
||||
rt_thread_mdelay(10);
|
||||
bk_ble_start_advertising(actv_idx, 0, ble_cmd_cb);*/
|
||||
bk_ble_start_advertising(actv_idx, 0, ble_cmd_cb);
|
||||
}
|
||||
|
||||
void belon_ble_deinit_adv() {
|
||||
|
@ -12,6 +12,7 @@ void RingQueue_init(RingQueue *q) {
|
||||
q->front = 0;
|
||||
q->rear = 0;
|
||||
q->size = 0;
|
||||
//q->sum = 0;
|
||||
}
|
||||
bool RingQueue_isFull(RingQueue *q) {
|
||||
return q->size == MAX_SIZE;
|
||||
@ -24,6 +25,7 @@ bool RingQueue_enqueue(RingQueue *q, int value) {
|
||||
if (RingQueue_isFull(q)) {
|
||||
return false; // 队列已满,返回失败
|
||||
}
|
||||
//q->sum += value;
|
||||
q->data[q->rear] = value; // 将值放入队尾
|
||||
q->rear = (q->rear + 1) % MAX_SIZE; // 更新队尾指针,注意使用模运算实现循环
|
||||
q->size++; // 队列大小加一
|
||||
@ -35,6 +37,7 @@ bool RingQueue_dequeue(RingQueue *q, int *value) {
|
||||
return false;
|
||||
}
|
||||
*value = q->data[q->front]; // 获取队头元素的值
|
||||
//q->sum -= q->data[q->front];
|
||||
q->front = (q->front + 1) % MAX_SIZE; // 更新队头指针,注意使用模运算实现循环
|
||||
q->size--; // 队列大小减一
|
||||
return true; // 成功出队返回true
|
||||
|
@ -2,13 +2,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_SIZE 20
|
||||
#define MAX_SIZE 30
|
||||
|
||||
typedef struct {
|
||||
int data[MAX_SIZE]; // 存储数据的数组
|
||||
int front; // 队头指针
|
||||
int rear; // 队尾指针
|
||||
int size; // 队列当前大小
|
||||
//int sum;
|
||||
} RingQueue;
|
||||
|
||||
void RingQueue_init(RingQueue *q);
|
||||
|
@ -88,7 +88,7 @@ else:
|
||||
src += ["driver/pwm/pwm_bk7231n.c"]
|
||||
src += ["driver/gpio/gpio.c"]
|
||||
|
||||
src += ["demo/ieee802_11_demo.c"]
|
||||
#src += ["demo/ieee802_11_demo.c"]
|
||||
src += ["func/func.c"]
|
||||
src += ["func/audio/audio_intf.c"]
|
||||
src += ["func/power_save/power_save.c"]
|
||||
|
@ -99,7 +99,7 @@
|
||||
*/
|
||||
#define CFG_WIFI_AP_HW_MODE 0
|
||||
|
||||
#define CfG_MACRO_MAYBE_UNUSED 0
|
||||
#define CfG_MACRO_MAYBE_UNUSED 1
|
||||
#if CfG_MACRO_MAYBE_UNUSED
|
||||
#define CFG_WIFI_RSSI 1
|
||||
#define CFG_WIFI_VERSION 1
|
||||
@ -160,7 +160,7 @@
|
||||
/* The following four macro will be reconstruct
|
||||
* TODO
|
||||
*/
|
||||
#define CFG_ENABLE_SDIO_DEV 0
|
||||
#define CFG_ENABLE_SDIO_DEV 1
|
||||
#define CFG_SDIO 0
|
||||
#define CFG_SDIO_TRANS 0
|
||||
#define CFG_REAL_SDIO 0
|
||||
@ -233,8 +233,8 @@
|
||||
#define CFG_USE_LWIP_NETSTACK 1
|
||||
|
||||
/*section 9-----for DHCP servicers and client*/
|
||||
#define CFG_USE_DHCP 0//1
|
||||
#define CFG_USE_DHCPD 0//1 // for servicers in ap mode
|
||||
#define CFG_USE_DHCP 1
|
||||
#define CFG_USE_DHCPD 1 // for servicers in ap mode
|
||||
|
||||
/*section 11-----temperature detect*/
|
||||
#define CFG_USE_TEMPERATURE_DETECT 1
|
||||
@ -323,9 +323,9 @@
|
||||
|
||||
/*section 21 ----- support ota*/
|
||||
#if( ( CFG_SUPPORT_ALIOS ) || ( CFG_SUPPORT_RTT ) || (CFG_SUPPORT_MATTER == 1))
|
||||
#define CFG_SUPPORT_OTA_HTTP 0
|
||||
#define CFG_SUPPORT_OTA_HTTP 1
|
||||
#else
|
||||
#define CFG_SUPPORT_OTA_HTTP 0
|
||||
#define CFG_SUPPORT_OTA_HTTP 1
|
||||
#endif
|
||||
#define CFG_SUPPORT_OTA_TFTP 0
|
||||
|
||||
@ -430,10 +430,10 @@
|
||||
#define CFG_TASK_WDG_PERIOD_MS 60000
|
||||
|
||||
/*section 29 ----- peripheral interface open */
|
||||
#define CFG_USE_SPI 0
|
||||
#define CFG_USE_SPI_MASTER 0
|
||||
#define CFG_USE_SPI_SLAVE 0
|
||||
#define CFG_USE_SPI_DMA 0
|
||||
#define CFG_USE_SPI 1
|
||||
#define CFG_USE_SPI_MASTER 1
|
||||
#define CFG_USE_SPI_SLAVE 1
|
||||
#define CFG_USE_SPI_DMA 1
|
||||
|
||||
/*section 30 ----- peripheral interface test case */
|
||||
#define CFG_PERIPHERAL_TEST 0
|
||||
|
@ -381,7 +381,7 @@ SRC_C += ./beken378/app/net_work/video_demo_p2p.c
|
||||
|
||||
|
||||
#demo module
|
||||
SRC_C += ./beken378/demo/ieee802_11_demo.c
|
||||
#SRC_C += ./beken378/demo/ieee802_11_demo.c
|
||||
|
||||
#driver layer
|
||||
SRC_DRV_C += ./beken378/driver/common/dd.c
|
||||
|
@ -10,6 +10,6 @@ CPPPATH = [cwd]
|
||||
libs = ['aac_decoder']
|
||||
libpath = [cwd]
|
||||
|
||||
group = DefineGroup('aac_decoder', src, depend = ['PKG_USING_PLAYER'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
group = DefineGroup('aac_decoder', src, depend = ['PKG_USING_PLAYER1'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
|
||||
Return('group')
|
||||
|
@ -10,6 +10,6 @@ CPPPATH = [cwd]
|
||||
libs = ['amrnb_encoder']
|
||||
libpath = [cwd]
|
||||
|
||||
group = DefineGroup('amrnb_encoder', src, depend = ['PKG_USING_PLAYER'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
group = DefineGroup('amrnb_encoder', src, depend = ['PKG_USING_PLAYER1'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
|
||||
Return('group')
|
||||
|
@ -10,6 +10,6 @@ CPPPATH = [cwd + '/']
|
||||
libs = ['opencore_amr_arm968_gcc']
|
||||
libpath = [cwd]
|
||||
|
||||
group = DefineGroup('opencore_amr', src, depend = ['PKG_USING_PLAYER'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
group = DefineGroup('opencore_amr', src, depend = ['PKG_USING_PLAYER1'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
|
||||
Return('group')
|
||||
|
@ -9,6 +9,6 @@ CPPPATH = [cwd, cwd + '/include']
|
||||
libs = ['speex_arm968_gcc']
|
||||
libpath = [cwd]
|
||||
|
||||
group = DefineGroup('speex', src, depend = ['PKG_USING_PLAYER'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
group = DefineGroup('speex', src, depend = ['PKG_USING_PLAYER1'], CPPPATH = CPPPATH, LIBS = libs, LIBPATH = libpath)
|
||||
|
||||
Return('group')
|
||||
|
@ -266,7 +266,8 @@ int player(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
player_set_volume(volume);
|
||||
//player_set_volume(volume);
|
||||
rt_kprintf("set play ok? %d%%.\n", player_set_volume(volume));
|
||||
rt_kprintf("set play volume %d%%.\n", volume);
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@
|
||||
#define PKG_USING_WEBCLIENT
|
||||
#define WEBCLIENT_HEADER_BUFSZ 4096
|
||||
#define WEBCLIENT_RESPONSE_BUFSZ 4096
|
||||
//#define PKG_USING_WEBCLIENT_LATEST_VERSION
|
||||
#define PKG_USING_WEBCLIENT_LATEST_VERSION
|
||||
//#define PKG_USING_CJSON
|
||||
#define PKG_USING_CJSON_V102
|
||||
|
||||
|
@ -99,7 +99,7 @@
|
||||
*/
|
||||
#define CFG_WIFI_AP_HW_MODE 0
|
||||
|
||||
#define CfG_MACRO_MAYBE_UNUSED 0
|
||||
#define CfG_MACRO_MAYBE_UNUSED 1
|
||||
#if CfG_MACRO_MAYBE_UNUSED
|
||||
#define CFG_WIFI_RSSI 1
|
||||
#define CFG_WIFI_VERSION 1
|
||||
@ -160,7 +160,7 @@
|
||||
/* The following four macro will be reconstruct
|
||||
* TODO
|
||||
*/
|
||||
#define CFG_ENABLE_SDIO_DEV 0
|
||||
#define CFG_ENABLE_SDIO_DEV 1
|
||||
#define CFG_SDIO 0
|
||||
#define CFG_SDIO_TRANS 0
|
||||
#define CFG_REAL_SDIO 0
|
||||
@ -233,8 +233,8 @@
|
||||
#define CFG_USE_LWIP_NETSTACK 1
|
||||
|
||||
/*section 9-----for DHCP servicers and client*/
|
||||
#define CFG_USE_DHCP 0//1
|
||||
#define CFG_USE_DHCPD 0//1 // for servicers in ap mode
|
||||
#define CFG_USE_DHCP 1
|
||||
#define CFG_USE_DHCPD 1 // for servicers in ap mode
|
||||
|
||||
/*section 11-----temperature detect*/
|
||||
#define CFG_USE_TEMPERATURE_DETECT 1
|
||||
@ -323,9 +323,9 @@
|
||||
|
||||
/*section 21 ----- support ota*/
|
||||
#if( ( CFG_SUPPORT_ALIOS ) || ( CFG_SUPPORT_RTT ) || (CFG_SUPPORT_MATTER == 1))
|
||||
#define CFG_SUPPORT_OTA_HTTP 0
|
||||
#define CFG_SUPPORT_OTA_HTTP 1
|
||||
#else
|
||||
#define CFG_SUPPORT_OTA_HTTP 0
|
||||
#define CFG_SUPPORT_OTA_HTTP 1
|
||||
#endif
|
||||
#define CFG_SUPPORT_OTA_TFTP 0
|
||||
|
||||
@ -430,10 +430,10 @@
|
||||
#define CFG_TASK_WDG_PERIOD_MS 60000
|
||||
|
||||
/*section 29 ----- peripheral interface open */
|
||||
#define CFG_USE_SPI 0
|
||||
#define CFG_USE_SPI_MASTER 0
|
||||
#define CFG_USE_SPI_SLAVE 0
|
||||
#define CFG_USE_SPI_DMA 0
|
||||
#define CFG_USE_SPI 1
|
||||
#define CFG_USE_SPI_MASTER 1
|
||||
#define CFG_USE_SPI_SLAVE 1
|
||||
#define CFG_USE_SPI_DMA 1
|
||||
|
||||
/*section 30 ----- peripheral interface test case */
|
||||
#define CFG_PERIPHERAL_TEST 0
|
||||
|
@ -29,4 +29,5 @@ void audio_device_mic_set_rate(int sample_rate);
|
||||
void audio_device_mic_set_channel(int channel);
|
||||
int audio_device_mic_read(void *buffer, int size);
|
||||
void audio_device_mic_close(void);
|
||||
int audio_device_get_volume(void);
|
||||
#endif
|
||||
|
@ -26,7 +26,8 @@ mqtt_client client;
|
||||
extern char g_sta_mac[6];
|
||||
static int is_started = 0;
|
||||
static uint32_t reciver_num=0;
|
||||
static beken_timer_t mqtt_connect_timer;
|
||||
//static beken_timer_t mqtt_connect_timer;
|
||||
static char device_id[64];
|
||||
static void mqtt_sub_callback(mqtt_client *c, message_data *msg_data)
|
||||
{
|
||||
reciver_num++;
|
||||
@ -59,13 +60,14 @@ static void mqtt_connect_callback(mqtt_client *c)
|
||||
static void mqtt_online_callback(mqtt_client *c)
|
||||
{
|
||||
LOG_D("inter mqtt_online_callback!");
|
||||
rtos_stop_timer(&mqtt_connect_timer);
|
||||
//rtos_stop_timer(&mqtt_connect_timer);
|
||||
//paho_mqtt_subscribe(&client, QOS1, MQTT_SUBTOPIC, mqtt_sub_callback);
|
||||
}
|
||||
|
||||
static void mqtt_offline_callback(mqtt_client *c)
|
||||
{
|
||||
LOG_D("inter mqtt_offline_callback!");
|
||||
connect_mqtt();
|
||||
}
|
||||
|
||||
// void mqtt_connect_timeout_cb(void *arg)
|
||||
@ -83,7 +85,6 @@ static void mqtt_offline_callback(mqtt_client *c)
|
||||
// }
|
||||
// is_started = 0;
|
||||
// }
|
||||
|
||||
int mqtt_start(char username[],char password[])
|
||||
{
|
||||
/* init condata param by using MQTTPacket_connectData_initializer */
|
||||
@ -102,13 +103,100 @@ int mqtt_start(char username[],char password[])
|
||||
/* config connect param */
|
||||
memcpy(&client.condata, &condata, sizeof(condata));
|
||||
|
||||
char device_id [64];
|
||||
|
||||
rt_memset(device_id,0,sizeof(device_id));
|
||||
rt_sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
sprintf(device_id,"%s_%02X%02X%02X%02X%02X%02X",
|
||||
PRODUCTID,g_sta_mac[0],g_sta_mac[1],g_sta_mac[2],g_sta_mac[3],g_sta_mac[4],g_sta_mac[5]);
|
||||
device_id[17]='\0';
|
||||
|
||||
bk_printf("username: %s\n", username);
|
||||
bk_printf("password: %s\n", password);
|
||||
bk_printf("device_id: %s\n", device_id);
|
||||
|
||||
client.condata.username.cstring = username;
|
||||
client.condata.password.cstring = password;
|
||||
client.condata.clientID.cstring = device_id;
|
||||
client.condata.keepAliveInterval = 60;
|
||||
client.condata.cleansession = 1;
|
||||
|
||||
/* config MQTT will param. */
|
||||
client.condata.willFlag = 1;
|
||||
client.condata.will.qos = 1;
|
||||
client.condata.will.retained = 0;
|
||||
client.condata.will.topicName.cstring = "/mqtt/will";//MQTT_SUBTOPIC;
|
||||
client.condata.will.message.cstring = MQTT_WILLMSG;
|
||||
|
||||
/* malloc buffer. */
|
||||
client.buf_size = client.readbuf_size = 1024;
|
||||
client.buf = rt_calloc(1, client.buf_size);
|
||||
client.readbuf = rt_calloc(1, client.readbuf_size);
|
||||
if (!(client.buf && client.readbuf))
|
||||
{
|
||||
LOG_E("no memory for MQTT client buffer!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set event callback function */
|
||||
client.connect_callback = mqtt_connect_callback;
|
||||
client.online_callback = mqtt_online_callback;
|
||||
client.offline_callback = mqtt_offline_callback;
|
||||
|
||||
/* set subscribe table and event callback */
|
||||
client.message_handlers[0].topicFilter = rt_strdup(MQTT_SUBTOPIC);
|
||||
client.message_handlers[0].callback = mqtt_sub_callback;
|
||||
client.message_handlers[0].qos = QOS1;
|
||||
|
||||
/* set default subscribe event callback */
|
||||
client.default_message_handlers = mqtt_sub_default_callback;
|
||||
}
|
||||
|
||||
{
|
||||
int value;
|
||||
uint16_t u16Value;
|
||||
value = 5;
|
||||
paho_mqtt_control(&client, MQTT_CTRL_SET_CONN_TIMEO, &value);
|
||||
value = 5;
|
||||
paho_mqtt_control(&client, MQTT_CTRL_SET_MSG_TIMEO, &value);
|
||||
value = 5;
|
||||
paho_mqtt_control(&client, MQTT_CTRL_SET_RECONN_INTERVAL, &value);
|
||||
value = 30;
|
||||
paho_mqtt_control(&client, MQTT_CTRL_SET_KEEPALIVE_INTERVAL, &value);
|
||||
u16Value = 3;
|
||||
paho_mqtt_control(&client, MQTT_CTRL_SET_KEEPALIVE_COUNT, &u16Value);
|
||||
}
|
||||
|
||||
/* run mqtt client */
|
||||
paho_mqtt_start(&client, 8196, 20);
|
||||
// rtos_init_timer(&mqtt_connect_timer, 10000, mqtt_connect_timeout_cb, NULL);
|
||||
// rtos_start_timer(&mqtt_connect_timer);
|
||||
|
||||
is_started = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int mqtt_start2(char* username,char *password ,char * client_id)
|
||||
{
|
||||
/* init condata param by using MQTTPacket_connectData_initializer */
|
||||
MQTTPacket_connectData condata = MQTTPacket_connectData_initializer;
|
||||
|
||||
if (is_started)
|
||||
{
|
||||
LOG_E("mqtt client is already connected.");
|
||||
return -1;
|
||||
}
|
||||
/* config MQTT context param */
|
||||
{
|
||||
client.isconnected = 0;
|
||||
client.uri = MQTT_URI;
|
||||
|
||||
/* config connect param */
|
||||
memcpy(&client.condata, &condata, sizeof(condata));
|
||||
|
||||
|
||||
|
||||
client.condata.clientID.cstring = client_id;
|
||||
client.condata.username.cstring = username;
|
||||
client.condata.password.cstring = password;
|
||||
client.condata.keepAliveInterval = 60;
|
||||
@ -169,6 +257,7 @@ int mqtt_start(char username[],char password[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int mqtt_stop(int argc, char **argv)
|
||||
{
|
||||
|
@ -188,7 +188,7 @@
|
||||
#define PKG_USING_WEBCLIENT
|
||||
#define WEBCLIENT_HEADER_BUFSZ 4096
|
||||
#define WEBCLIENT_RESPONSE_BUFSZ 4096
|
||||
//#define PKG_USING_WEBCLIENT_LATEST_VERSION
|
||||
#define PKG_USING_WEBCLIENT_LATEST_VERSION
|
||||
//#define PKG_USING_CJSON
|
||||
#define PKG_USING_CJSON_V102
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#define MIC_DAC_LOOP_TEST
|
||||
//#define MIC_DAC_LOOP_TEST
|
||||
|
||||
#if 0
|
||||
/*adc test*/
|
||||
@ -78,4 +78,4 @@
|
||||
|
||||
#define PSRAM_TEST
|
||||
#endif
|
||||
#define PM_TEST
|
||||
//#define PM_TEST
|
BIN
副本702030-400 0.2C放电曲线 250322_004_1_1.xls
Normal file
BIN
副本702030-400 0.2C放电曲线 250322_004_1_1.xls
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user