本帖最后由 7788 于 2024-5-11 13:48 编辑
修改下,本次问题主要原因在于
我配置了docker加速,用的阿里云的
但是阿里云的镜像 有问题
用docker hub的就没问题了
给大家参考下
按着莫哥得教程,
智能家居之旅,第三站:Ai-M61/M62 接入HomeAssistant 实现点灯 - 智能家居 - 物联网开发者社区-安信可论坛 - Powered by Discuz! (ai-thinker.com)
搭建好环境 连接好MQTT,但是,HA不行,没有设备
我按步骤,修改了
配置文件
WiFI
和 ha_device 结构体参数
成功连接了wifi 和 MQTT服务器
![image.png image.png](data/attachment/forum/202405/11/073445f6pc7222h2plpi76.png)
我后台HA配置界面
![image.png image.png](data/attachment/forum/202405/11/073733tgoln1sss1i6n8k6.png)
MQTT测试
![image.png image.png](data/attachment/forum/202405/11/073704mzsgj442s94m22jo.png)
但是HA设备列表里面没有设备
![image.png image.png](data/attachment/forum/202405/11/074009ro9iolgy5r5xo9l9.png)
我的HA是最新版
![image.png image.png](data/attachment/forum/202405/11/074241sqqrmrelrmlqgeqq.png)
main文件
/**
* @file main.c
* @author your name ([email]you@domain.com[/email])
* @brief
* @version 0.1
* @date 2024-01-23
*
* @copyright Copyright (c) 2024
*
*/
#include <FreeRTOS.h>
#include "task.h"
#include "queue.h"
#include "board.h"
#include "bluetooth.h"
#include "btble_lib_api.h"
#include "bl616_glb.h"
#include "rfparam_adapter.h"
#include "bflb_mtd.h"
#include "easyflash.h"
#include "wifi_event.h"
#include "log.h"
#include "aiio_os_port.h"
#include "homeAssistantMQTT.h"
extern
#define DBG_TAG "MAIN"
void ha_event_cb(ha_event_t event, homeAssisatnt_device_t* ha_dev)
{
switch (event)
{
case HA_EVENT_MQTT_CONNECED:
LOG_I("<<<<<<<<<< HA_EVENT_MQTT_CONNECED");
//一定要加static
static ha_sw_entity_t entity_sw1 = {
.name = "开关1",
.icon = "mdi:power",
.unique_id = "switch_v1",
};
homeAssistant_device_add_entity(CONFIG_HA_ENTITY_SWITCH, &entity_sw1);
homeAssistant_device_send_status(HOMEASSISTANT_STATUS_ONLINE);
homeAssistan_device_send_entity_state(CONFIG_HA_ENTITY_SWITCH, &entity_sw1, 0);
break;
case HA_EVENT_MQTT_DISCONNECT:
LOG_I("<<<<<<<<<< HA_EVENT_MQTT_DISCONNECT");
break;
case HA_EVENT_MQTT_COMMAND_SWITCH:
LOG_I("<<<<<<<<<< HA_EVENT_MQTT_COMMAND_SWITCH");
// LOG_I("switch addr =%p", ha_dev->entity_switch->command_switch);
LOG_I(" switch %s is %s", ha_dev->entity_switch->command_switch->name, ha_dev->entity_switch->command_switch->switch_state?"true":"flase");
int ret = homeAssistan_device_send_entity_state(CONFIG_HA_ENTITY_SWITCH, ha_dev->entity_switch->command_switch, ha_dev->entity_switch->command_switch->switch_state);
if (ret!=-1)LOG_I("%s send entity suceess,state=%s", ha_dev->entity_switch->command_switch->name, ha_dev->entity_switch->command_switch->switch_state?"true":"flase");
break;
default:
break;
}
}
int main(void)
{
board_init();
bflb_mtd_init();
easyflash_init();
// aiio_log_init();
if (0 != rfparam_init(0, NULL, 0)) {
LOG_E("PHY RF init failed!\r\n");
return 0;
}
staWiFiInit();
// homeassistant_blufi_init();
static homeAssisatnt_device_t ha_device;
ha_device.mqtt_info.mqtt_clientID="Ai-M6X_Kit_Switch";
ha_device.mqtt_info.mqtt_host="";
ha_device.mqtt_info.port=1883;
ha_device.mqtt_info.mqtt_username="";
ha_device.mqtt_info.mqtt_password="";
homeAssistant_device_init(&ha_device, ha_event_cb);
vTaskStartScheduler();
while (1) {
LOG_F("HomeAssistant free heap size=%d", aiio_os_get_free_heap_size());
vTaskDelay(pdMS_TO_TICKS(3000));
}
}
|