曰本美女∴一区二区特级A级黄色大片, 国产亚洲精品美女久久久久久2025, 页岩实心砖-高密市宏伟建材有限公司, 午夜小视频在线观看欧美日韩手机在线,国产人妻奶水一区二区,国产玉足,妺妺窝人体色WWW网站孕妇,色综合天天综合网中文伊,成人在线麻豆网观看

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

用安信可Wi-Fi6 & 藍(lán)牙模組+VC-02語(yǔ)音控制HA設(shè)備

AIoT行業(yè)洞察 ? 來(lái)源:AIoT行業(yè)洞察 ? 作者:AIoT行業(yè)洞察 ? 2024-08-13 14:08 ? 次閱讀

智能家居的話,如果只能手動(dòng)控制會(huì)覺(jué)得不太智能,如果能用說(shuō)的或者自動(dòng)的話體驗(yàn)可能會(huì)更好一些。

智能家居其實(shí)就是為了給生活添加一些便利,懶人推送科技發(fā)展是沒(méi)錯(cuò)的。

對(duì)于個(gè)人而言接入智能家居無(wú)非有以下幾個(gè)原因:

1、動(dòng)動(dòng)手動(dòng)動(dòng)嘴不動(dòng)腿就是懶恨不能意念控制

2、開(kāi)關(guān)對(duì)小朋友不友好,個(gè)頭不夠摸不到開(kāi)關(guān)

3、全屋聯(lián)動(dòng)回家模式離家模式等等

基于以上幾個(gè)原因

通過(guò)嘗試。實(shí)現(xiàn)了語(yǔ)音控制 HA 設(shè)備的基本功能。

主要思路如圖:

wKgaoma6-FmADONeAAC7s6NWiwE81.jpeg

開(kāi)始想著增加機(jī)械開(kāi)關(guān)手動(dòng)去操作,后來(lái)想了以下都語(yǔ)音控制了還要物理開(kāi)關(guān)干嘛呢。

小朋友和老人,直接語(yǔ)音控制開(kāi)關(guān)設(shè)備。就很舒服呢。

對(duì)于紅外設(shè)備,還沒(méi)研究透徹怎么去獲取遙控器的紅外編碼,然后發(fā)射出來(lái)。這樣就可以實(shí)現(xiàn)更多的功能。

可以語(yǔ)音控制空調(diào)、電視等紅外設(shè)備。

[智能家居]MQTT 控制 HomeAssistant 設(shè)備

https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=44644&fromuid=15918

(出處: 物聯(lián)網(wǎng)開(kāi)發(fā)者社區(qū)-安信可論壇)

這里主要還是用到了 HomeAssistant 的自動(dòng)化功能,這種設(shè)置不需要對(duì) HomeAssistant 有很深的了解,簡(jiǎn)單配置即可。

對(duì)于小白用戶體驗(yàn)更好一些,上手就用。對(duì)于大佬的話,可以延伸出更多的功能。

下面介紹一下主要功能模塊

一、離線語(yǔ)音模組系列

VC 系列模組是我司開(kāi)發(fā)的一款 AI 離線語(yǔ)音識(shí)別的產(chǎn)品,主芯片是云知聲推出的離線語(yǔ)音識(shí)別芯片鋒鳥(niǎo) M(US516P6),具有高可靠性,通用性強(qiáng)的特點(diǎn)。在語(yǔ)音識(shí)別技術(shù)上實(shí)現(xiàn)了高可靠的喚醒識(shí)別率、更遠(yuǎn)距離的喚醒、更低誤喚醒率、更強(qiáng)的抗噪音能力、更快的響應(yīng)識(shí)別時(shí)間,免聯(lián)網(wǎng)的純離線識(shí)別。

VC 系列模組采用了 32bit RISC 架構(gòu)內(nèi)核,并加入了專門(mén)針對(duì)信號(hào)處理和語(yǔ)音識(shí)別所需要的 DSP 指令集,支持浮點(diǎn)運(yùn)算的 FPU 運(yùn)算單元,以及 FFT 加速器。支持最高 150 條本地指令離線識(shí)別,支持 RTOS 輕量級(jí)系統(tǒng),以及簡(jiǎn)單友好的客制化工具。

VC 系列模組具有豐富的外圍接口,包括 UART/I2C/PWM/SPI,以及簡(jiǎn)單友好的二次開(kāi)發(fā)工具,方便客戶實(shí)現(xiàn)單模組的語(yǔ)音控制應(yīng)用場(chǎng)景方案。

VC-02 模組

wKgZoma6-FmAWfbGAACE9TU9KNA51.jpeg

揚(yáng)聲器功率盡量不要太大,如果用 M61-32S 供電揚(yáng)聲器功率過(guò)高會(huì)導(dǎo)致掉電。

揚(yáng)聲器:

SPK-8Ω2W

SPK+8Ω2W

官方資料

VC-02 模組規(guī)格書(shū):

中文: https://docs.ai-thinker.com/_media/vc-02_v1.0.0%E8%A7%84%E6%A0%BC%E4%B9%A6_516.pdf

EN:https://docs.ai-thinker.com/_media/vc-02_v1.0.0_specification_516.pdf

VC-02 原理圖:https://docs.ai-thinker.com/_media/vc-02_v1.0_%E5%8E%9F%E7%90%86%E5%9B%BE-20220531.pdf

VC-02 封裝: https://mp.weixin.qq.com/s?__biz=MzIzODA0NDgxNg==&mid=2650092833&idx=5&sn=b8dfe99e2b08c31a704256f79c351b47&chksm=f13ec6dec6494fc88d033ff313ab824fc41695f4a188a9e98b237bf563e0c6fc07a1c5f4fabd&token=2098411327&lang=zh_CN#rd

串口燒錄工具

定制語(yǔ)音

安信可語(yǔ)音開(kāi)放平臺(tái):http://voice.ai-thinker.com/

在安信可語(yǔ)音開(kāi)放平臺(tái)創(chuàng)建產(chǎn)品,選擇 VC 系列模組。

wKgaoma6-FmAHpqXAACb-uX2Bfs83.jpeg

然后修改喚醒詞

wKgZoma6-GSAOC5HAAAv-VgF0_049.jpeg

設(shè)置 Pin 引腳功能

wKgaoma6-GSAJkk0AABfxm2s1iQ45.jpeg

波特率設(shè)置 115200,引腳 B6 設(shè)置為 UART1_RX 引腳 B7 設(shè)置為 UART1_TX,用來(lái)發(fā)送接收數(shù)據(jù)。注意不要配置多個(gè) UART1,否則不生效。

添加語(yǔ)音指令

wKgZoma6-G6AR1w2AACj3_s7Gwc76.jpeg

然后添加控制詳情

wKgaoma6-G-APHmPAABlklqGUv422.jpeg

這里主要用到的就是串口數(shù)據(jù),這里發(fā)送指令 第一位是指令開(kāi)頭默認(rèn) A1,第二位定義的是設(shè)備位置,第三位定義的是設(shè)備類型,第四位定義的是開(kāi)關(guān)狀態(tài),第五位結(jié)束位默認(rèn) FF。根據(jù)自己的需要設(shè)置解析即可。

還有免喚醒命令,不用喚醒詞直接就可以用,比如開(kāi)燈、關(guān)燈等等。

wKgZoma6-G-AI7FwAABGIrsrfxA60.jpeg

免喚醒命令詞最多 10 個(gè)選擇自己需要的添加,添多了也是默認(rèn)取前 10 條。

二、Ai-M61-32S Wi-Fi 模組

Ai-M61 系列模組(下稱模組)是由深圳市安信可科技有限公司開(kāi)發(fā)的 Wi-Fi6 & 藍(lán)牙雙模模組,搭載 BL618 芯片作為處理器,支持 Wi-Fi 802.11b/g/n/ax 協(xié)議和 BLE 5.3 協(xié)議。BL618 芯片內(nèi)置低功耗的 32 位 RISC-V CPU,最高主頻可達(dá) 320M. 豐富的外圍接口,包括 DVP、MJPEG、Dispaly、Audio Codec、USB2.0、SDU、以太網(wǎng)(EMAC)、SD/MMC(SDH)、SPI、UART、I2C、I2S、PWM、GPDAC、GPADC、ACOMP 和 GPIO 等。可廣泛應(yīng)用于音視頻多媒體、物聯(lián)網(wǎng)(IoT)、移動(dòng)設(shè)備、可穿戴電子設(shè)備、智能家居等領(lǐng)域。

M61-32S 模組

wKgaoma6-G-AD5uIAAFKHzGBJmQ17.jpeg

官方資料

Ai-M61-32S-Kit 開(kāi)發(fā)板規(guī)格書(shū):

中文:https://docs.ai-thinker.com/_media/ai-m61-32s-kit_v1.1.2_product_specification_cn.pdf

EN:https://docs.ai-thinker.com/_media/ai-m61-32s-kit_v1.1.2_product_specification_en.pdf

Ai-M61-32S 開(kāi)發(fā)板原理圖:https://docs.ai-thinker.com/_media/nodemcu-ai-m61-32s-kit_v1.1.pdf

Ai-M61-32S 模組規(guī)格書(shū):

中文 :https://docs.ai-thinker.com/_media/ai-m61-32s_v1.3.0_product_specification_cn.pdf

EN:https://docs.ai-thinker.com/_media/ai-m61-32s_v1.3.0_product_specification_en.pdf

Ai-M61-32S 推薦封裝:點(diǎn)擊下載

Ai-M61 系列出廠固件

固件下載工具:點(diǎn)擊下載

固件燒錄指南:M61/M62 系列燒錄指導(dǎo)(包含模組&開(kāi)發(fā)板)https://blog.csdn.net/Boantong_/article/details/140183535?

三、代碼部分

主要用 wifi、mqtt、uart、flash

uart 代碼主要參考

【完全開(kāi)源】智能桌面助手——AiPi-DSL_Dashboard

程序代碼

#include 
#include 
#include 
#include 
#include 
#include 
#include "log.h"
#include "board.h"
#include "mem.h"
//easy flash
#include "easyflash.h"
#include "bflb_mtd.h"
#include "bl_fw_api.h"
#include "wifi_mgmr_ext.h"
#include "wifi_mgmr.h"
#include "ha_task.h"
#include "wifi_event.h"
#include "voice_uart.h"
int main(void)
{
board_init();
wifi_start_firmware_task();
//init easyflash
bflb_mtd_init();
easyflash_init();
xTaskCreate(voice_uart_task, "uart task", 1024, NULL, 10, NULL);
xTaskCreate(queue_receive_task, "queue_receive_task", 1024*3, NULL, 3, NULL);
vTaskStartScheduler();
}

VC02 模組交互代碼

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "ha_task.h"
#include "bflb_uart.h"
#include "bflb_gpio.h"
#include "voice_uart.h"
#include "user_mqtt.h"
#include "log.h"
#define GBD_TAG "UART"
static void uart_init(void);
extern xQueueHandle queue;
uart_rx_cmd_t uart_cmd;
static struct bflb_device_s* uart1;
static char uart_buff[5] = { 0 };
static const uart_data_t g_uart_buf[] = {
{{0xA1, 0x00, 0x01, 0x00, 0xFF}, 5}, //wakeup_uni
{{0xA1, 0x00, 0x01, 0x01, 0xFF}, 5}, //openL
{{0xA1, 0x00, 0x01, 0x00, 0xFF}, 5}, //closeL
};
void voice_uart_task(void* arg)
{
uart_init();
while (1) {
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
static int voice_cmd_check(char* buff, int len)
{
int data_cnt = 0, j = 0;
// char* uart_txbuf = pvPortMalloc(4);
// memset(uart_txbuf, 0, 4);
while (1) {
for (size_t i = 0; i < 5; i++)
{
if (buff[i]==g_uart_buf[j].data[i]) data_cnt++;
else break;
}
if (data_cnt==g_uart_buf-?>len) break;
data_cnt = 0;
j++;
if (j>23) return -1;
}
LOG_I("check uart cmd=%d", j);
return j;
}
static void uart_isr(int irq, void* arg)
{
uint32_t intstatus = bflb_uart_get_intstatus(uart1);
uint32_t rx_data_len = 0;
char data_type[1] = { 0 };
if (intstatus & UART_INTSTS_RX_FIFO) {
int index = 0;
memset(uart_buff, 0, 5);
LOG_I("rx fiforn");
while (bflb_uart_rxavailable(uart1)) {
uart_buff[index++] = bflb_uart_getchar(uart1);
}
LOG_I("uart recv:%02X %02X %02X %02X %02X", uart_buff[0], uart_buff[1], uart_buff[2], uart_buff[3], uart_buff[4]);
}
}
/**
* @brief
*/
static void uart_init(void)
{
struct bflb_device_s* gpio;
struct bflb_uart_config_s cfg = {
.baudrate = 115200,
.data_bits = UART_DATA_BITS_8,
.stop_bits = UART_STOP_BITS_1,
.parity = UART_PARITY_NONE,
.flow_ctrl = 0,
.tx_fifo_threshold = 4,
.rx_fifo_threshold = 4,
};
gpio = bflb_device_get_by_name("gpio");
uart1 = bflb_device_get_by_name("uart1");
bflb_gpio_uart_init(gpio, GPIO_PIN_25, GPIO_UART_FUNC_UART1_TX);
bflb_gpio_uart_init(gpio, GPIO_PIN_26, GPIO_UART_FUNC_UART1_RX);
bflb_uart_init(uart1, &cfg);
bflb_uart_txint_mask(uart1, false);
bflb_uart_rxint_mask(uart1, false);
bflb_irq_attach(uart1->irq_num, uart_isr, NULL);
bflb_irq_enable(uart1->irq_num);
}

MQTT 與 WIFI

wifi

#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include 
#include 
#include 
#include "bl_fw_api.h"
#include "wifi_mgmr_ext.h"
#include "wifi_mgmr.h"
#include "bflb_irq.h"
#include "bflb_uart.h"
#include "bflb_l1c.h"
#include "bflb_mtimer.h"
#include "bl616_glb.h"
#include "rfparam_adapter.h"
#include "board.h"
#include "log.h"
#include "ha_task.h"
#include "config.h"
#define DBG_TAG "WIFI EVENT"
#define WIFI_STACK_SIZE (1024*4)
#define TASK_PRIORITY_FW (16)
static wifi_conf_t conf =
{
.country_code = "CN",
};
static TaskHandle_t wifi_fw_task;
static uint32_t sta_ConnectStatus = 0;
extern TaskHandle_t https_Handle;
/**
* @brief WiFi 任務(wù)
* @return int
*/
int wifi_start_firmware_task(void)
{
LOG_I("Starting wifi ...");
/* enable wifi clock */
GLB_PER_Clock_UnGate(GLB_AHB_CLOCK_IP_WIFI_PHY | GLB_AHB_CLOCK_IP_WIFI_MAC_PHY | GLB_AHB_CLOCK_IP_WIFI_PLATFORM);
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_WIFI);
/* set ble controller EM Size */
GLB_Set_EM_Sel(GLB_WRAM160KB_EM0KB);
if (0 != rfparam_init(0, NULL, 0)) {
LOG_I("PHY RF init failed!");
return 0;
}
LOG_I("PHY RF init success!");
/* Enable wifi irq */
extern void interrupt0_handler(void);
bflb_irq_attach(WIFI_IRQn, (irq_callback)interrupt0_handler, NULL);
bflb_irq_enable(WIFI_IRQn);
xTaskCreate(wifi_main, (char*)"fw", WIFI_STACK_SIZE, NULL, TASK_PRIORITY_FW, &wifi_fw_task);
return 0;
}
/**
* @brief wifi event handler
* WiFi 事件回調(diào)
* @param code
*/
void wifi_event_handler(uint32_t code)
{
sta_ConnectStatus = code;
switch (code) {
case CODE_WIFI_ON_INIT_DONE:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_INIT_DONE", __func__);
wifi_mgmr_init(&conf);
}
break;
case CODE_WIFI_ON_MGMR_DONE:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_MGMR_DONE", __func__);
}
break;
case CODE_WIFI_ON_SCAN_DONE:
{
char* scan_msg = pvPortMalloc(128);
wifi_mgmr_sta_scanlist();
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_SCAN_DONE SSID numbles:%d", __func__, wifi_mgmr_sta_scanlist_nums_get());
sprintf(scan_msg, "{"wifi_scan":{"status":0}}");
vPortFree(scan_msg);
}
break;
case CODE_WIFI_ON_CONNECTED:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_CONNECTED", __func__);
void mm_sec_keydump();
mm_sec_keydump();
}
break;
case CODE_WIFI_ON_GOT_IP:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP", __func__);
mqtt_client_init(MQTT_HOST, MQTT_PORT);
mqtt_client_register_event();
vTaskDelay(500/portTICK_PERIOD_MS);
mqtt_start_connect(MQTT_HOST, MQTT_PORT, MQTT_USERNAME, MQTT_PASSWORD);
mqtt_app_subscribe("sub", 0);
}
break;
case CODE_WIFI_ON_DISCONNECT:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT", __func__);
}
break;
case CODE_WIFI_ON_AP_STARTED:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STARTED", __func__);
}
break;
case CODE_WIFI_ON_AP_STOPPED:
{
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STOPPED", __func__);
}
break;
case CODE_WIFI_ON_AP_STA_ADD:
{
LOG_I("[APP] [EVT] [AP] [ADD] %lld", xTaskGetTickCount());
}
break;
case CODE_WIFI_ON_AP_STA_DEL:
{
LOG_I("[APP] [EVT] [AP] [DEL] %lld", xTaskGetTickCount());
}
break;
default:
{
LOG_I("[APP] [EVT] Unknown code %u ", code);
}
}
}
uint8_t wifi_connect(char* ssid, char* passwd)
{
int ret = 255;
// struct fhost_vif_ip_addr_cfg ip_cfg = { 0 };
uint32_t ipv4_addr = 0;
char* queue_buff = pvPortMalloc(128);
memset(queue_buff, 0, 128);
if (NULL==ssid || 0==strlen(ssid)) {
return 1;
}
//先斷開(kāi)WiFi
if (wifi_mgmr_sta_state_get() == 1) {
wifi_sta_disconnect();
}
LOG_I("WiFi STA connect .....");
if (wifi_sta_connect(ssid, passwd, NULL, NULL, 0, 0, 0, 1)

mqtt

#include 
#include 
#include 
#include "FreeRTOS.h"
#include "log.h"
#include 
#include "user_mqtt.h"
#include "ha_task.h"
#include 
#include "bflb_uart.h"
#include 
#include 
#include 
#include 
#include "bflb_uart.h"
#include "voice_uart.h"
#include "utils_getopt.h"
#include "config.h"
#define DBG_TAG "MQTT"
// #define USER_MQTT
int test_sockfd;
struct mqtt_client client;
static mqtt_event_t event;
uint8_t sendbuf[2048]; /* sendbuf should be large enough to hold multiple whole mqtt messages */
uint8_t recvbuf[1024]; /* recvbuf should be large enough any whole mqtt message expected to be received */
static TaskHandle_t client_daemon;
static int open_socket(const char* host, const char* port);
static int open_socket(const char* host, const char* port)
{
struct addrinfo hints = { 0 };
hints.ai_family = AF_UNSPEC; /* IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* Must be TCP */
int sockfd = -1;
int rv;
struct addrinfo* p, * servinfo;
/* get address information */
LOG_I("host:%s, port=%s", host, port);
rv = getaddrinfo(host, port, &hints, &servinfo);
if (rv != 0) {
LOG_E("Failed to open socket (getaddrinfo): %d", rv);
return -1;
}
/* open the first possible socket */
for (p = servinfo; p != NULL; p = p->ai_next) {
sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
if (sockfd == -1) continue;
/* connect to server */
rv = connect(sockfd, p->ai_addr, p->ai_addrlen);
if (rv == -1) {
close(sockfd);
sockfd = -1;
continue;
}
break;
}
/* free servinfo */
freeaddrinfo(servinfo);
/* make non-blocking */
if (sockfd != -1) {
int iMode = 1;
ioctlsocket(sockfd, FIONBIO, &iMode);
}
return sockfd;
}
/**
* @brief
* @param sig
*/
static void test_close(void)
{
if (test_sockfd)
{
close(test_sockfd);
}
vTaskDelete(client_daemon);
}
/**
* @brief
* @param unused
* @param published
*/
static void publish_callback_1(void** unused, struct mqtt_response_publish* published)
{
/* not used in this example */
char* topic_name = (char*)malloc(published->topic_name_size + 1);
memcpy(topic_name, published->topic_name, published->topic_name_size);
topic_name[published->topic_name_size] = '';
char* topic_msg = (char*)malloc(published->application_message_size + 1);
memcpy(topic_msg, published->application_message, published->application_message_size);
topic_msg[published->application_message_size] = '';
printf("%s:[%s]rn", topic_name, topic_msg);
char* queue_buff = pvPortMalloc(512);
memset(queue_buff, 0, 512);
sprintf(queue_buff, "{"mqtt_msg":{"topic":"%s","data":%.*s}}", topic_name, published->application_message_size, topic_msg);
vPortFree(queue_buff);
free(topic_name);
free(topic_msg);
}
/**
* @brief _inspector_callback
* @param client_arg
* @return enum MQTTErrors
*/
enum MQTTErrors _inspector_callback(struct mqtt_client* client_arg)
{
if (client_arg->mq.queue_tail->state!=MQTT_QUEUED_UNSENT) return MQTT_OK; //識(shí)別消息狀態(tài)是否有更新,沒(méi)有更新就返回
event = client_arg->mq.queue_tail->control_type;
static struct bflb_device_s* uartx;
uartx = bflb_device_get_by_name("uart1");
switch (event) {
case MQTT_EVENT_CONNECT:
{
LOG_I("MQTT_EVENT_CONNECT");
}
break;
case MQTT_EVENT_CONNACK:
{
LOG_I("MQTT_EVENT_CONNACK");
}
break;
case MQTT_EVENT_PUBLISH:
{
LOG_I("MQTT_EVENT_PUBLISH");
}
break;
case MQTT_EVENT_PUBACK:
{
LOG_I("MQTT_EVENT_PUBACK");
}
break;
case MQTT_EVENT_PUBREC:
{
LOG_I("MQTT_EVENT_PUBREC");
}
break;
case MQTT_EVENT_PUBREL:
{
LOG_I("MQTT_EVENT_PUBREL");
}
break;
case MQTT_EVENT_PUBCOMP:
{
LOG_I("MQTT_EVENT_PUBCOMP");
}
break;
case MQTT_EVENT_SUBSCRIBE:
{
LOG_I("MQTT_EVENT_SUBSCRIBE");
}
break;
case MQTT_EVENT_SUBACK:
{
LOG_I("MQTT_EVENT_SUBACK");
}
break;
case MQTT_EVENT_UNSUBSCRIBE:
{
LOG_I("MQTT_EVENT_UNSUBSCRIBE");
}
break;
case MQTT_EVENT_UNSUBACK:
{
LOG_I("MQTT_EVENT_UNSUBACK");
}
break;
case MQTT_EVENT_PINGREQ:
{
LOG_I("MQTT_EVENT_PINGREQ");
}
break;
case MQTT_EVENT_PINGRESP:
{
LOG_I("MQTT_EVENT_PINGRESP");
}
break;
case MQTT_EVENT_DISCONNECT:
{
LOG_I("MQTT_EVENT_DISCONNECT");
}
break;
default:
break;
}
return MQTT_OK;
}
/**
* @brief
* @param host
* @param port
*/
void mqtt_client_init(const char* host, int port)
{
LOG_I("MQTT init start");
test_sockfd = open_socket(host, "1883");
if (test_sockfd < 0) {
LOG_E("Failed to open socket: %d", test_sockfd);
test_close();
return;
}
LOG_I(" test_sockfd crater OK id=%d", test_sockfd);
mqtt_init(&client, test_sockfd, sendbuf, sizeof(sendbuf), recvbuf, sizeof(recvbuf), publish_callback_1);
}
/**
* @brief
* @param client
*/
static void client_refresher(void* arg)
{
struct mqtt_client* client = (struct mqtt_client*)arg;
while (1)
{
mqtt_sync(client);
vTaskDelay(200/portTICK_PERIOD_MS);
}
}
/**
* @brief mqtt_start_connect
* MQTT啟動(dòng)連接
* @param host
* @param port
* @param user_name
* @param pass
* @return int
*/
int mqtt_start_connect(char* host, uint16_t port, char* user_name, char* pass)
{
int ret = 0;
/* Ensure we have a clean session */
uint8_t connect_flags = MQTT_CONNECT_CLEAN_SESSION;
/* Send connection request to the broker. */
ret = mqtt_connect(&client, MQTT_CLIENT_ID, NULL, NULL, 0, user_name, pass, connect_flags, 400);
if (ret != MQTT_OK)
{
LOG_E("MQTT init fail");
}
/* check that we don't have any errors */
if (client.error != MQTT_OK) {
LOG_E("error: %s", mqtt_error_str(client.error));
test_close();
}
xTaskCreate(client_refresher, (char*)"client_ref", 1024, &client, 10, &client_daemon);
return 0;
}
void mqtt_app_diconnect(void)
{
test_close();
}
/**
* @brief mqtt_app_publish
* @param topic
* @param payload
* @param qos
* @return int
*/
int mqtt_app_publish(const char* topic, const char* payload, int qos)
{
static enum MQTTPublishFlags qos_flags;
if (qos==0)qos_flags = MQTT_PUBLISH_QOS_0;
else if (qos==1)qos_flags = MQTT_PUBLISH_QOS_1;
else qos_flags = MQTT_PUBLISH_QOS_2;
mqtt_publish(&client, topic, payload, strlen(payload), qos_flags);
if (client.error != MQTT_OK) {
LOG_E("error: %s", mqtt_error_str(client.error));
test_close();
return -1;
}
return 0;
}
/**
* @brief mqtt_app_subscribe
* @param topic
* @param qos
* @return int
*/
int mqtt_app_subscribe(char* topic, int qos)
{
mqtt_subscribe(&client, topic, 0);
return 0;
}
void mqtt_client_register_event(void)
{
client.inspector_callback = _inspector_callback;
}

配置文件

#define SSID_KEY "SSID"
#define PASS_KEY "PASS"
#define USER_SSID "******"
#define USER_PASSWORD "******"
#define MQTT_HOST "192.168.5*.*"
#define MQTT_PORT 1883
#define MQTT_USERNAME "******"
#define MQTT_PASSWORD "******"
#define MQTT_TOPIC "/HA/Ai/topic"
#define MQTT_MSG_OPEN_L "{status:true}"
#define MQTT_MSG_CLOSE_L "{status:false}"

如果感興趣的話可以看下

[智能家居]小安派 DSL 通過(guò) MQTT 控制 Home Assistant 燈

https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=44671&fromuid=15918

(出處: 物聯(lián)網(wǎng)開(kāi)發(fā)者社區(qū)-安信可論壇)

【完全開(kāi)源】智能桌面助手——AiPi-DSL_Dashboard

https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=42026&fromuid=15918

自動(dòng)化方案低配置,低代碼。操作簡(jiǎn)單。

現(xiàn)在手里只有 M61 開(kāi)發(fā)板,不知道有沒(méi)有小一些功耗低一些的模組。希望一塊小電池能堅(jiān)持一個(gè)月那種。

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 智能家居
    +關(guān)注

    關(guān)注

    1932

    文章

    9720

    瀏覽量

    188880
  • 語(yǔ)音控制
    +關(guān)注

    關(guān)注

    5

    文章

    495

    瀏覽量

    28592
  • 藍(lán)牙模組
    +關(guān)注

    關(guān)注

    0

    文章

    41

    瀏覽量

    4264
  • 安信可
    +關(guān)注

    關(guān)注

    0

    文章

    180

    瀏覽量

    4328
  • wifi6
    +關(guān)注

    關(guān)注

    4

    文章

    510

    瀏覽量

    39150
收藏 人收藏

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    運(yùn)營(yíng)商集采Wi-Fi 6,中國(guó)9月將跨入Wi-Fi6時(shí)代

    2020年的智能手機(jī)除了5G和常規(guī)的處理器升級(jí)之外,Wi-Fi6、UFS3.0、LPDDR5和高刷新率成為了新的宣傳點(diǎn)。最近幾個(gè)月,國(guó)內(nèi)手機(jī)廠商發(fā)布的新手機(jī)基本都搭載了Wi-Fi6功能,在智能家居領(lǐng)域,三星還推出了支持Wi-Fi6
    的頭像 發(fā)表于 06-16 10:13 ?1.1w次閱讀

    Wi-Fi6Wi-Fi6E的區(qū)別是什么

    E?  Wi-Fi6和上一代Wi-Fi一樣,使用2.4GHz和5GHz無(wú)線電頻段?!?b class='flag-5'>Wi-Fi6E”設(shè)備也可以在6GHz頻段上運(yùn)行?! ?/div>
    發(fā)表于 09-02 18:00

    ESP32-DOWDQ6藍(lán)牙&amp;Wifi 兩個(gè)單獨(dú)控制的 CPU 內(nèi)核

    ESP32-D0WDQ6,ESP32-D0WD,ESP32-D2WD,ESP32-S0WDESP32-D0WDQ6:32-bit MCU &amp; 2.4 GHz Wi-Fi + B
    發(fā)表于 11-24 09:20

    ESP32-DOWDQ6藍(lán)牙&amp;Wifi 兩個(gè)單獨(dú)控制的 CPU 內(nèi)核

    ESP32-D0WDQ6,ESP32-D0WD,ESP32-D2WD,ESP32-S0WDESP32-D0WDQ6:32-bit MCU &amp; 2.4 GHz Wi-Fi + B
    發(fā)表于 12-02 14:20

    如何正確打開(kāi)Wi-Fi6?

    三招正確打開(kāi)Wi-Fi6
    發(fā)表于 12-08 07:58

    到底哪些公司更適合Wi-Fi6呢?部署Wi-Fi6時(shí)又該注意些什么?

    Wi-Fi 6到底有多“6”?到底哪些公司更適合Wi-Fi6呢?部署Wi-Fi6時(shí)又該注意些什么?
    發(fā)表于 03-15 06:21

    Wi-Fi6技術(shù)的發(fā)展還有哪些抑制因素和顧慮?

    Wi-Fi6技術(shù)的發(fā)展還有哪些抑制因素和顧慮?
    發(fā)表于 06-18 06:10

    Wi-Fi6Wi-Fi7之間有什么區(qū)別

      首先,我們Wi-Fi6Wi-Fi7對(duì)比,隨著科技圈的發(fā)展越來(lái)越迅速,當(dāng)我們還在等待Wi-Fi6終端大范圍普及時(shí),第七代Wi-Fi7技
    發(fā)表于 05-05 11:47

    Wi-Fi7相比Wi-Fi6會(huì)有哪些改進(jìn)的地方

    如果熟悉Wi-Fi6的用戶可能知道,其主要提升在于,它的QAM調(diào)制精度翻倍,使得單臺(tái)設(shè)備網(wǎng)速更快,并且引入OFDMA技術(shù),可以容納更多設(shè)備連接;此外,Wi-Fi6還引入了BSS著色技術(shù)
    發(fā)表于 04-20 11:25 ?1802次閱讀

    關(guān)于連接的問(wèn)答:歐盟 Wi-Fi 6 &amp;amp; 6E 的未來(lái)發(fā)展

    關(guān)于連接的問(wèn)答:歐盟 Wi-Fi 6 &amp; 6E 的未來(lái)發(fā)展
    的頭像 發(fā)表于 12-26 10:16 ?1165次閱讀

    新品發(fā)布 | 離線語(yǔ)音VC-01/02:卸掉APP,秒控你的家電!

    科技的VC-01/VC-02離線語(yǔ)音方案具有免聯(lián)網(wǎng)、迅速響應(yīng)、隱私安全保護(hù)、接入門(mén)檻較低等
    的頭像 發(fā)表于 06-13 16:15 ?1468次閱讀
    新品發(fā)布 | 離線<b class='flag-5'>語(yǔ)音</b><b class='flag-5'>VC</b>-01/<b class='flag-5'>02</b>:卸掉APP,秒控你的家電!

    Ai-WB2系列模組概述

    Ai-WB2系列模組科技開(kāi)發(fā)的Wi-Fi&;BT模組,該
    的頭像 發(fā)表于 09-09 10:01 ?1703次閱讀

    推出Wi-Fi 6+BLE5.3模組Ai-M62-M2-I

    隨著Wi-Fi標(biāo)準(zhǔn)的演進(jìn),Wi-Fi6已走向大規(guī)模商用階段。去年通過(guò)長(zhǎng)期研發(fā)設(shè)計(jì)及反復(fù)打磨,推出WiFi
    的頭像 發(fā)表于 02-25 09:54 ?1339次閱讀
    <b class='flag-5'>安</b><b class='flag-5'>信</b><b class='flag-5'>可</b>推出<b class='flag-5'>Wi-Fi</b> <b class='flag-5'>6</b>+BLE5.3<b class='flag-5'>模組</b>Ai-M62-M2-I

    雷達(dá)模組Rd-01燒錄操作說(shuō)明

    Rd-01是科技開(kāi)發(fā)的雷達(dá)模組,該模組支持 Wi-Fi&;BLE ,以及雷達(dá)檢測(cè)功能
    的頭像 發(fā)表于 03-17 15:52 ?909次閱讀
    <b class='flag-5'>安</b><b class='flag-5'>信</b><b class='flag-5'>可</b>雷達(dá)<b class='flag-5'>模組</b>Rd-01燒錄操作說(shuō)明

    Wi-Fi&;amp;BLE模組之WB2系列的特點(diǎn)概述

    Ai-WB2系列模組(下稱模組)是由科技開(kāi)發(fā)的Wi-Fi&BLE
    的頭像 發(fā)表于 05-11 11:49 ?1092次閱讀