1 Star 0 Fork 5

bgang / smartassistant

forked from zhiting-tech / smartassistant 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mac-development-start.md 3.69 KB
一键复制 编辑 原始数据 按行查看 历史
zhiting-tech 提交于 2022-08-08 14:34 . 2.6.3

Mac系统下开发环境搭建

前提

  1. 系统已经安装etcd。
  2. go 1.16。
  3. Goland IDE。
  4. Postman。

克隆项目

git clone http://gitlab.yctc.tech/zhiting/smartassistant.git

使用Goland运行项目

使用Goland打开项目,配置GOPROXY。

GOPROXY=https://goproxy.cn,direct

image

运行smartassistant

拷贝项目下的app.yaml.example到项目根目录,并重命名为app.yaml。

cp app.yaml.example app.yaml

打开终端创建程序数据存储目录。

mkdir -p data/zt-smartassistant/data/smartassistant

image

修改配置文件app.yaml中的runtime_path和host_runtime_path,将这个参数改为数据存储目录的绝对路径。 image

启动Etcd。 image

修改项目下modules/plugin/discovery.go文件中的etcd服务器地址。 image

在ide中打开cmd/smartassistant/main.go文件,编辑运行配置。 image image 其中,Program arguments配置使用-c=app.yaml来指定程序的配置文件。配置完成用点击运行即可。 如果成功运行后打开浏览器 http://localhost:37965/api/check 返回以下内容

{"status":0,"reason":"成功","data":{"is_bind":false,"revision":"","version":"latest"}}

说明smartassistant成功运行起来了。

运行plugin-demo

使用ide打开examples/plugin-demo/main.go文件,编辑运行配置。 image 其中,Environment配置一个LOCAL_IP的环境变量,如果不指定有可能会获取一个ipv6的ip地址导致smartassistant不能发现插件中的设备。配置完成后点击运行即可。

测试过程

根据上述步骤将smartassistant和plugin-demo运行起来后,可以使用postman进行测试。

初始化smartassistant账号

请求方法:POST 请求url: http://localhost:37965/api/sa 请求参数:

{
    "device": {
        "model": "MH-SA00DCLB001W",
        "area_type":1
    }
}

image

发现插件中的设备

在Postman中创建WebSocket Request image

请求url: http://localhost:37965/ws 请求头添加 smart-assistant-token,该值为初始化smartassistant返回的token。 image

连接成功后,发送以下请求

{
  "ID": 1,
  "Service": "discover"
}

即可发现插件中的设备。 image

常见问题

  • plugin-demo的依赖无法下载?

    修改项目下的examples/plugin-demo/go.mod文件 将 github.com/zhiting-tech/smartassistant replace 成../../

    replace github.com/zhiting-tech/smartassistant v1.5.0 => ../../

    然后在命令行中,cd到plugin-demo目录下执行go mod tidy

  • *smartassistant和plugin-demo都运行起来,但是使用websocket进行设备发现是没有返回数据。

    可以使用etcdctl get --prefix "/sa/plugins"命令检查插件是否成功注册到etcd中。如果没有数据,可能是etcd不是本地启动的,导致plugin-demo连不上etcd。检查运行plugin-demo的步骤配置LOCAL_IP环境变量。检查运行smartassistant是否修改了modules/plugin/discovery.go文件中的etcd地址。

  • 根据快速入门使用docker-compose启动smartassistant无法与本地运行的插件进行通讯?

    由于docker-compose启动的时候使用的host网络,但是host网络只能在linux系统使用docker host 网络,可以安装vritual box安装linux虚拟机进行测试。

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bgang/smartassistant.git
git@gitee.com:bgang/smartassistant.git
bgang
smartassistant
smartassistant
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891