【已解决】莫哥 HomeAssistant 无法连接HA

[复制链接]
查看3760 | 回复17 | 2024-5-11 07:43:43 | 显示全部楼层 |阅读模式

本帖最后由 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

我后台HA配置界面

image.png

MQTT测试 image.png

但是HA设备列表里面没有设备

image.png

我的HA是最新版

image.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));
    }
}
回复

使用道具 举报

1084504793 | 2024-5-11 08:18:47 | 显示全部楼层
回复

使用道具 举报

WT_0213 | 2024-5-11 08:36:19 | 显示全部楼层
ha_device.mqtt_info.mqtt_host="";
ha_device.mqtt_info.port=1883;
ha_device.mqtt_info.mqtt_username="";
ha_device.mqtt_info.mqtt_password="";

topic 设置的对吗
回复 支持 反对

使用道具 举报

爱笑 | 2024-5-11 08:42:14 | 显示全部楼层
让莫哥给你回答一下!
用心做好保姆工作
回复 支持 反对

使用道具 举报

起个名字好难啊 | 2024-5-11 08:44:13 | 显示全部楼层
爱笑 发表于 2024-5-11 08:42
让莫哥给你回答一下!

你的host 没设置对,默认连接的是安信可官方的MQTT服务器,不是你的服务器。
回复 支持 反对

使用道具 举报

起个名字好难啊 | 2024-5-11 08:46:24 | 显示全部楼层
你的host 没设置对,默认连接的是安信可官方的MQTT服务器,不是你的服务器。你要给host 这个参数赋值成自己的MQTT服务器地址
回复 支持 反对

使用道具 举报

起个名字好难啊 | 2024-5-11 08:51:22 | 显示全部楼层
补一句,如果你是在配置文件里改了默认的参数,就不用在这赋值host了,会覆盖默认值的
回复 支持 反对

使用道具 举报

lazy | 2024-5-11 09:03:15 | 显示全部楼层
智能家居这块还得是莫哥
回复 支持 反对

使用道具 举报

7788 | 2024-5-11 09:05:24 | 显示全部楼层
起个名字好难啊 发表于 2024-5-11 08:51
补一句,如果你是在配置文件里改了默认的参数,就不用在这赋值host了,会覆盖默认值的 ...

莫哥,都改了,你看我MQTT截图,M61已经成功连接上了
回复 支持 反对

使用道具 举报

7788 | 2024-5-11 09:11:13 | 显示全部楼层
WT_0213 发表于 2024-5-11 08:36
ha_device.mqtt_info.mqtt_host="";
ha_device.mqtt_info.port=1883;
ha_device.mqtt_info.mqtt_username= ...

topic 没设置,这应该是 homeAssistant_device_init 函数配置的吧
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则