Giter Club home page Giter Club logo

iot-platform's Introduction

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"

功能模块

  • 用户模块
    • 登录
  • 后台管理模块
    • 设备管理
      • 设备列表
      • 创建、修改、删除设备
    • 产品管理
      • 产品列表
      • 创建、修改、删除产品
  • 开放平台模块
    • 签名
    • 发送消息
  • 设备服务模块
    • 设备状态管理
    • 发送消息

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.