Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add some ci #2

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/commit_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: commit lint
on:
pull_request:
branches:
- main

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wagoid/commitlint-github-action@v5
22 changes: 22 additions & 0 deletions .github/workflows/go_mod_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: go mod check

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
go_mod_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Run Go Mod Check Action
uses: shoothzj/go-mod-check-action@main
with:
prohibitIndirectDepUpdate: 'true'
13 changes: 13 additions & 0 deletions .github/workflows/line_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: line lint
on:
pull_request:
branches:
- main
jobs:
line_lint:
name: line lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: linelint
uses: shoothzj/linelint@main
16 changes: 13 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# file system
.DS_Store

# ide
.idea/**
.vscode/**
!.idea/icon.svg
!.idea/vcs.xml

target/*

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.idea

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/
# Go workspace file
go.work
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ English | [简体中文](./README_CN.md)
# 0. Version update instructions
| Version | Change Type | Description |
|:-------|:-|:-------------------------------------------------|
| v1.0.0 | New features | Provides the ability to connect to the Huawei Cloud IoT platform to facilitate users to implement business scenarios such as secure access, device management, data collection, command issuance, device provisioning, and client-side rules |
| v1.0.0 | New features | Provides the ability to connect to the Huawei Cloud IoT platform to facilitate users to implement business scenarios such as secure access, device management, data collection, command issuance, device provisioning, and client-side rules |

# 1. Preface
huaweicloud-iot-device-sdk-go provides a Go version of the SDK for devices to access the Huawei Cloud IoT platform. It provides communication capabilities between devices and platforms, as well as advanced services such as device services, gateway services, and OTA. It also provides various The scene provides rich demo codes. IoT device developers can use the SDK to greatly simplify development complexity and quickly access the platform.
Expand Down Expand Up @@ -145,15 +145,15 @@ Take the smoke sensor as an example to experience functions such as message repo

* Click "Access Information" to view the MQTT device access address and save the address.

![](.\doc\figure_en\get_access_address_en.png)
![](.\doc\figure_en\get_access_address_en.png)


* Select "Product" in the device access console, click "Create Product" in the upper right corner, and in the pop-up page, fill in the "Product Name", "Protocol Type", "Data Format", "Manufacturer Name", " Industry", "Equipment Type" and other information, and then click "Create Now" in the lower right corner.

- Select "MQTT" as the protocol type;

- Select "JSON" as the data format.

![](.\doc\figure_en\upload_profile_2_en.png)

* After the product is successfully created, click "Details" to enter the product details. On the function definition page, click "Upload Model File" to upload the smoke detector product model [smokeDetector](https://iot-developer.obs.cn-north -4.myhuaweicloud.com/smokeDetector.zip).
Expand Down Expand Up @@ -199,7 +199,7 @@ The page has command issuing and message tracking functions.

* If you use port 8883 to access the platform through key authentication (recommended, all SDK demos access the platform through this method), you need to write the obtained device ID, key and preset CA certificate.
Preset certificate:/samples/resources/root.pem

```go
authConfig := &config.ConnectAuthConfig{
Id: "{your device id}",
Expand All @@ -211,7 +211,7 @@ The page has command issuing and message tracking functions.
```
* If you use port 8883 and access the platform through X509 certificate authentication, you need to write the obtained device ID, certificate information and pre-made CA certificate. For more X509 certificate access, please refer to [X509 Certificate Access](https://support.huaweicloud.com/bestpractice-iothub/iot_bp_0077.html)
Preset certificate:/samples/resources/root.pem

```go
authConfig := &config.ConnectAuthConfig{
Id: "{your device id}",
Expand Down Expand Up @@ -402,7 +402,7 @@ The example prints the content of the property settings in the PropertiesSetHand

def run():
< create device code here ... >

//Register platform setting attribute callback. When the application sets device attributes through the API, this callback will be called. It supports registering multiple callbacks.
device.Client.AddPropertiesSetHandler(func(propertiesSetRequest model.DevicePropertyDownRequest) bool {
glog.Infof("I get property set command")
Expand Down Expand Up @@ -505,7 +505,7 @@ An example of file upload/download is implemented in /samples/file/upload_file.g

```go
< create device code here ... >

fileName := "test_upload.txt"
uploadFilePath := currentPath + "\\download\\test_upload.txt"
//Upload file
Expand All @@ -520,14 +520,14 @@ An example of file upload/download is implemented in /samples/file/upload_file.g
File upload/download process reference [File Upload](https://support.huaweicloud.com/usermanual-iothub/iot_01_0033.html)

* Configure OBS storage in the console.

![](.\doc\figure_en\obs_config_en.png)

* Preset upload files. The file to be uploaded in the above example is /iot_device_demo/filemanage/download/upload_test.txt.
In the file download part, download the uploaded upload_test.txt and save it to /iot_device_demo/filemanage/download/download.txt.

* Execute the above example to see the storage results on OBS.

![](.\doc\figure_en\obs_object_en.png)

## 4.10 Device time synchronization
Expand Down Expand Up @@ -754,9 +754,9 @@ The example prints the content of the command in the CommandHandler method. Cust

```python
def run():

< create device code here ... >

# Set up listener
device.Client.CommandHandler = func(command model.Command) (bool, interface{}) {
glog.Infof("command device id is %s", command.ObjectDeviceId)
Expand All @@ -767,7 +767,7 @@ def run():
"cost_time": 12,
}
}

connect := device.Connect()
glog.Infof("connect result : %v", connect)

Expand Down Expand Up @@ -919,4 +919,3 @@ Refer to [Device Access Interface Documentation](./IoT-Device-SDK-Python-API Doc

# 7.0 More documentation
Refer to [Device Access More Documentation](https://support.huaweicloud.com/devg-iothub/iot_02_0178.html)

26 changes: 13 additions & 13 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# 0.版本更新说明
| 版本 |变更类型| 说明 |
|:-------|:-|:-------------------------------------------------|
| v1.0.0 |新增功能| 提供对接华为云IoT物联网平台能力,方便用户实现安全接入、设备管理、数据采集、命令下发、设备发放、端侧规则等业务场景 |
| v1.0.0 |新增功能| 提供对接华为云IoT物联网平台能力,方便用户实现安全接入、设备管理、数据采集、命令下发、设备发放、端侧规则等业务场景 |

# 1.前言
huaweicloud-iot-device-sdk-go提供设备接入华为云IoT物联网平台的Go版本的SDK,提供设备和平台之间通讯能力,以及设备服务、网关服务、OTA等高级服务,并且针对各种场景提供了丰富的demo代码。IoT设备开发者使用SDK可以大大简化开发复杂度,快速的接入平台。
Expand Down Expand Up @@ -153,7 +153,7 @@ SDK面向运算、存储能力较强的嵌入式终端设备,开发者通过
- 协议类型选择“MQTT”;

- 数据格式选择“JSON”。

![upload_profile_2.png](.\doc\figure_cn\upload_profile_2.png)

* 产品创建成功后,单击“详情”进入产品详情,在功能定义页面,单击“上传模型文件”,上传烟感产品模型[smokeDetector](https://iot-developer.obs.cn-north-4.myhuaweicloud.com/smokeDetector.zip) 。
Expand Down Expand Up @@ -199,7 +199,7 @@ SDK面向运算、存储能力较强的嵌入式终端设备,开发者通过

* 如果您使用8883端口通过密钥鉴权接入平台(推荐使用,SDK的demo均通过此方法接入平台),需要写入获取的设备ID、密钥以及预置CA证书。
预置的证书:/samples/resources/root.pem

```go
authConfig := &config.ConnectAuthConfig{
Id: "{your device id}",
Expand All @@ -211,7 +211,7 @@ SDK面向运算、存储能力较强的嵌入式终端设备,开发者通过
```
* 如果您使用8883端口并通过X509证书鉴权接入平台,则需要写入获取的设备ID,证书信息以及预制CA证书。更多X509证书接入请参考[X509证书接入](https://support.huaweicloud.com/bestpractice-iothub/iot_bp_0077.html)
预置的证书:/samples/resources/root.pem

```go
authConfig := &config.ConnectAuthConfig{
Id: "{your device id}",
Expand Down Expand Up @@ -402,7 +402,7 @@ SDK面向运算、存储能力较强的嵌入式终端设备,开发者通过

def run():
< create device code here ... >

// 注册平台设置属性callback,当应用通过API设置设备属性时,会调用此callback,支持注册多个callback
device.Client.AddPropertiesSetHandler(func(propertiesSetRequest model.DevicePropertyDownRequest) bool {
glog.Infof("I get property set command")
Expand Down Expand Up @@ -505,7 +505,7 @@ def run():

```go
< create device code here ... >

fileName := "test_upload.txt"
uploadFilePath := currentPath + "\\download\\test_upload.txt"
// 上传文件
Expand All @@ -520,14 +520,14 @@ def run():
文件上传/下载流程参考[文件上传](https://support.huaweicloud.com/usermanual-iothub/iot_01_0033.html)

* 在控制台中配置OBS存储。

![](.\doc\figure_cn\obs_config.png)

* 预置好上传文件。上面例子的待上传文件为/iot_device_demo/filemanage/download/upload_test.txt。
文件下载部分将已上传的upload_test.txt下载下来保存到/iot_device_demo/filemanage/download/download.txt。

* 执行上面例子可到OBS上看到存储结果。

![](.\doc\figure_cn\obs_object.png)

## 4.10 设备时间同步
Expand All @@ -536,7 +536,7 @@ def run():
```go
< create device code here ... >

// 设置时间同步服务
// 设置时间同步服务
device.Client.SyncTimeResponseHandler = func(deviceSendTime, serverRecvTime, serverSendTime int64) {
deviceRecvTime := time.Now().UnixNano() / int64(time.Millisecond)
now := (serverRecvTime + serverSendTime + deviceRecvTime + deviceSendTime) / 2
Expand Down Expand Up @@ -754,9 +754,9 @@ device.Client.CommandHandler = func(command model.Command) (bool, interface{}) {

```python
def run():

< create device code here ... >

# 设置监听器
device.Client.CommandHandler = func(command model.Command) (bool, interface{}) {
glog.Infof("command device id is %s", command.ObjectDeviceId)
Expand All @@ -767,7 +767,7 @@ def run():
"cost_time": 12,
}
}

connect := device.Connect()
glog.Infof("connect result : %v", connect)

Expand Down Expand Up @@ -918,4 +918,4 @@ authConfig.MaxBufferMessage = 100
参考[设备接入接口文档](./IoT-Device-SDK-Python-API文档.pdf)

# 7.0更多文档
参考[设备接入更多文档](https://support.huaweicloud.com/devg-iothub/iot_02_0178.html)
参考[设备接入更多文档](https://support.huaweicloud.com/devg-iothub/iot_02_0178.html)
2 changes: 1 addition & 1 deletion download/test_upload.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test upload file.
test upload file.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.18

require (
github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/go-co-op/gocron v1.35.2
github.com/golang/glog v1.1.2
github.com/panjf2000/ants/v2 v2.9.0
github.com/go-co-op/gocron v1.37.0
github.com/golang/glog v1.2.3
github.com/panjf2000/ants/v2 v2.10.0
github.com/satori/go.uuid v1.2.0
)

require (
github.com/google/uuid v1.6.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand Down
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk=
github.com/go-co-op/gocron v1.35.2 h1:lG3rdA9TqBBC/PtT2ukQqgLm6jEepnAzz3+OQetvPTE=
github.com/go-co-op/gocron v1.35.2/go.mod h1:NLi+bkm4rRSy1F8U7iacZOz0xPseMoIOnvabGoSe/no=
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0=
github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY=
github.com/golang/glog v1.2.3 h1:oDTdz9f5VGVVNGu/Q7UXKWYsD0873HXLHdJUNBsSEKM=
github.com/golang/glog v1.2.3/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -21,8 +21,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/panjf2000/ants/v2 v2.9.0 h1:SztCLkVxBRigbg+vt0S5QvF5vxAbxbKt09/YfAJ0tEo=
github.com/panjf2000/ants/v2 v2.9.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/panjf2000/ants/v2 v2.10.0 h1:zhRg1pQUtkyRiOFo2Sbqwjp0GfBNo9cUY2/Grpx1p+8=
github.com/panjf2000/ants/v2 v2.10.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
4 changes: 2 additions & 2 deletions samples/gateway/gateway_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func updateSubDeviceStats() {
gatewayDevice.Client.SubDeviceStatusRespHandler = func(response model.SubDeviceStatusResp) {
if len(response.SuccessfulDevices) > 0 {
glog.Infof("success update device status.")
for _, sucessDevice := range response.SuccessfulDevices {
glog.Infof("update device : %s status: %s", sucessDevice.DeviceId, sucessDevice.Status)
for _, successDevice := range response.SuccessfulDevices {
glog.Infof("update device : %s status: %s", successDevice.DeviceId, successDevice.Status)
}
}
if len(response.FailedDevices) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion samples/resource/root.pem
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ wY3WzvUy2MmeFe8nI+z1TIvWfspA9MRf/TuTAjB0yPEL+GltmZWrSZVxykzLsVi
VO6LAUP5MSeGbEYNNVMnbrt9x+vJJUEeKgDu+6B5dpffItKoZB0JaezPkvILFa9
x8jvOOJckvB595yEunQtYQEgfn7R8k8HWV+LLUNS60YMlOH1Zkd5d9VUWx+tJDf
LRVpOoERIyNiwmcUVhAn21klJwGW45hpxbqCo8YLoRT5s1gLXCmeDBVrJpBA=
-----END CERTIFICATE-----
-----END CERTIFICATE-----
2 changes: 0 additions & 2 deletions sdk_info

This file was deleted.

Loading