1 Star 28 Fork 17

GetcharZp / iot-platform

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

iot-platform

基于 go-zero(微服务) 实现的物联网平台

B站视频地址:https://www.bilibili.com/video/BV13G4y1R71m

技术栈

  • 后端:go-zero、gorm
  • 前端:vue
  • 硬件:arduino、esp8266

安装

  1. 搭建 Golang 环境
  2. 安装 goctl
go get -u github.com/zeromicro/go-zero/tools/goctl@latest 
  1. 下载安装 arduino
  2. 搭建 ETCD 环境
# 参考如下,使用Docker安装ETCD
docker run -d --name Etcd-server \
    --network app-tier \
    --publish 2379:2379 \
    --publish 2380:2380 \
    --env ALLOW_NONE_AUTHENTICATION=yes \
    --env ETCD_ADVERTISE_CLIENT_URLS=http://etcd-server:2379 \
    bitnami/etcd:latest
  1. 搭建 EMQX 环境,参考地址:https://www.emqx.io/downloads
docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx:5.0.12 
  1. 开启 EMQX 认证,访问地址:http://192.168.1.8:18083/ ,默认的端口是 18083,根据自己的地址调整即可;默认用户名和密码为 admin/public
  2. 修改 define.go 中的EmqxAddr\EmqxKey\EmqxSecret为自己在EMQX后台生成的密钥对

命令

  • 创建API服务
goctl api new 服务名称
# 1. 创建 user 服务
goctl api new user
# 2. 创建 admin 服务
goctl api new admin
# 3. 创建 open 服务
goctl api new open
  • 生成服务代码
goctl api go -api 服务名称.api -dir . -style go_zero
# 1. 生成 user api 服务代码
goctl api go -api user.api -dir . -style go_zero
# 2. 生成 admin api 服务代码
goctl api go -api admin.api -dir . -style go_zero
# 3. 生成 user rpc 服务代码
goctl rpc protoc user.proto --go_out=./types --go-grpc_out=./types --zrpc_out=. --style go_zero
# 4. 生成 device rpc 服务代码
goctl rpc protoc device.proto --go_out=./types --go-grpc_out=./types --zrpc_out=. --style go_zero
# 5. 生成 open api 服务代码
goctl api go -api open.api -dir . -style go_zero
  • 启动服务
go run 服务名称.go -f 配置文件地址
# 1. 启动 user api 服务
go run user.go -f etc/user-api.yaml
# 2. 启动 admin api 服务
go run admin.go -f etc/admin-api.yaml
# 3. 启动 user rpc 服务
go run user.go -f etc/user.yaml
# 4. 启动 device rpc 服务
go run device.go -f etc/device.yaml
# 5. 启动 open api 服务
go run open.go -f etc/open-api.yaml

适用场景

共享单车、共享充电宝、外卖柜

Topic

  1. 心跳
/sys/产品key/设备key/ping
  1. 设备接受消息的订阅地址
/sys/产品key/设备key/receive

相关说明

设备连接

  1. 连接的客户端ID即为设备的Key,密码为md5(key+secret)

签名规则

对请求参数的key从小到大排序后,拼接key(不包括sign字段)所对应的参数值后求md5。

// 1. 例如发送的参数如下所示
map[string]interface{}{
    "app_key":     "app_key",
    "product_key": "1",
    "device_key":  "device_key",
    "data":        "hello world",
    "sign":        "4d62a91d0588320d314001828da9e1db",
}
// 2. 则签名为: app_key的值 + data的值 + device_key的值 + product_key的值
md5("app_keyhello worlddevice_key1") = "4d62a91d0588320d314001828da9e1db"

功能模块

  • 用户模块
    • 登录
  • 后台管理模块
    • 设备管理
      • 设备列表
      • 创建、修改、删除设备
    • 产品管理
      • 产品列表
      • 创建、修改、删除产品
  • 开放平台模块
    • 签名
    • 发送消息
  • 设备服务模块
    • 设备状态管理
    • 发送消息
MIT License Copyright (c) 2022 GetcharZp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于 go-zero(微服务)实现的物联网平台 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/getcharzp/iot-platform.git
git@gitee.com:getcharzp/iot-platform.git
getcharzp
iot-platform
iot-platform
master

搜索帮助