APP程序远程更新GITHUB RELEASE

要自己架设一个服务器来提供app更新,别说是配置服务器了,光是买个主机都很棘手。但是github提供了release功能,并有相关api支持。下面介绍如何使用github的release功能。

这里以DTU802 基于.net开发的iotgateway程序为例,硬件,软件界面如下:APP程序远程更新GITHUB RELEASE_第1张图片

APP程序远程更新GITHUB RELEASE_第2张图片 

在guthub上新建工程,创建release:

APP程序远程更新GITHUB RELEASE_第3张图片

 

出现如下界面,上传文件和填写信息:

APP程序远程更新GITHUB RELEASE_第4张图片

勾选了Pre-release,后API提示错误:

{
“message” : "Not Found",
"documentation_url" : "https://xxx"
}

Publish Release:

APP程序远程更新GITHUB RELEASE_第5张图片

通过github官方提供的api可访问我们的release信息:

/repos/:owner/:repo/releases/:id

例如:我的release的api是

https://api.github.com/repos/peixiuhui/IOTGate/releases/latest
获得最新版本号:
wget -qO- -t1 -T2 "https://api.github.com/repos/peixiuhui/IOTGate/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'

执行如下:

huiwei@hwserver:Code$ wget -qO- -t1 -T2 "https://api.github.com/repos/peixiuhui/IOTGate/releases/latest"
{
 "url": "https://api.github.com/repos/peixiuhui/IOTGate/releases/97256959",
 "assets_url": "https://api.github.com/repos/peixiuhui/IOTGate/releases/97256959/assets",
 "upload_url": "https://uploads.github.com/repos/peixiuhui/IOTGate/releases/97256959/assets{?name,label}",
 "html_url": "https://github.com/peixiuhui/IOTGate/releases/tag/V20",
 "id": 97256959,
 "author": {
   "login": "peixiuhui",
   "id": 10824875,
   "node_id": "MDQ6VXNlcjEwODI0ODc1",
   "avatar_url": "https://avatars.githubusercontent.com/u/10824875?v=4",
   "gravatar_id": "",
   "url": "https://api.github.com/users/peixiuhui",
   "html_url": "https://github.com/peixiuhui",
   "followers_url": "https://api.github.com/users/peixiuhui/followers",
   "following_url": "https://api.github.com/users/peixiuhui/following{/other_user}",
   "gists_url": "https://api.github.com/users/peixiuhui/gists{/gist_id}",
   "starred_url": "https://api.github.com/users/peixiuhui/starred{/owner}{/repo}",
   "subscriptions_url": "https://api.github.com/users/peixiuhui/subscriptions",
   "organizations_url": "https://api.github.com/users/peixiuhui/orgs",
   "repos_url": "https://api.github.com/users/peixiuhui/repos",
   "events_url": "https://api.github.com/users/peixiuhui/events{/privacy}",
   "received_events_url": "https://api.github.com/users/peixiuhui/received_events",
   "type": "User",
   "site_admin": false
},
 "node_id": "MDc6UmVsZWFzZTk3MjU2OTU5",
 "tag_name": "V20",
 "target_commitish": "master",
 "name": "IOTGate",
 "draft": false,
 "prerelease": false,
 "created_at": "2021-02-27T12:16:33Z",
 "published_at": "2023-03-29T01:41:40Z",
 "assets": [
  {
     "url": "https://api.github.com/repos/peixiuhui/IOTGate/releases/assets/101379606",
     "id": 101379606,
     "node_id": "RA_kwDOHMXgbs4GCu4W",
     "name": "iotgateway.tar",
     "label": null,
     "uploader": {
       "login": "peixiuhui",
       "id": 10824875,
       "node_id": "MDQ6VXNlcjEwODI0ODc1",
       "avatar_url": "https://avatars.githubusercontent.com/u/10824875?v=4",
       "gravatar_id": "",
       "url": "https://api.github.com/users/peixiuhui",
       "html_url": "https://github.com/peixiuhui",
       "followers_url": "https://api.github.com/users/peixiuhui/followers",
       "following_url": "https://api.github.com/users/peixiuhui/following{/other_user}",
       "gists_url": "https://api.github.com/users/peixiuhui/gists{/gist_id}",
       "starred_url": "https://api.github.com/users/peixiuhui/starred{/owner}{/repo}",
       "subscriptions_url": "https://api.github.com/users/peixiuhui/subscriptions",
       "organizations_url": "https://api.github.com/users/peixiuhui/orgs",
       "repos_url": "https://api.github.com/users/peixiuhui/repos",
       "events_url": "https://api.github.com/users/peixiuhui/events{/privacy}",
       "received_events_url": "https://api.github.com/users/peixiuhui/received_events",
       "type": "User",
       "site_admin": false
    },
     "content_type": "application/x-tar",
     "state": "uploaded",
     "size": 170455040,
     "download_count": 0,
     "created_at": "2023-03-29T01:37:43Z",
     "updated_at": "2023-03-29T01:38:47Z",
     "browser_download_url": "https://github.com/peixiuhui/IOTGate/releases/download/V20/iotgateway.tar"
  }
],
 "tarball_url": "https://api.github.com/repos/peixiuhui/IOTGate/tarball/V20",
 "zipball_url": "https://api.github.com/repos/peixiuhui/IOTGate/zipball/V20",
 "body": "DTU802 .NET IOT APP"
}
huiwei@hwserver:Code$wget -qO- -t1 -T2 "https://api.github.com/repos/peixiuhui/IOTGate/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'
V20
huiwei@hwserver:Code$

这样就获取到软件的版本号为V20了,也可通过解析这个Json数据获取版本信息,从而 实现 软件是否需要更新。

需要更新的话,将固件下载到本地==>  md5校验,校验硬件型号,替换,等等... Go ...

 

APP程序远程更新GITHUB RELEASE_第6张图片 

 

 

你可能感兴趣的:(Linux,OTA,IOT,网关,边缘计算)