Skip to content

Commit

Permalink
use http library for checking for new version
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisisnate committed Feb 1, 2018
1 parent 6c56832 commit 8512469
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion spec/device_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("device", function()
end)

it("has expected properties", function()
assert.equal(device.swVersion, "2.1.1")
assert.equal(device.swVersion, "2.1.2")
assert.equal(device.hwVersion, "2.0.5")
assert.equal(device.name, "Konnected")
end)
Expand Down
2 changes: 1 addition & 1 deletion src/device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local me = {
id = "uuid:8f655392-a778-4fee-97b9-4825918" .. string.format("%x", node.chipid()),
name = "Konnected",
hwVersion = "2.0.5",
swVersion = "2.1.1",
swVersion = "2.1.2",
http_port = math.floor(node.chipid()/1000) + 8000,
urn = "urn:schemas-konnected-io:device:Security:1"
}
Expand Down
8 changes: 4 additions & 4 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"src/actuators.lua":"47a1a50c0c8cfb547554ded22a8134eaed76c0a3",
"src/application.lua":"758d600770046868d054b7d54bf2144a9fc255e1",
"src/device.lua":"1ea639622b8d599207e7a64a1eeb84e791090f3a",
"src/device.lua":"2b962df6dfac2bf071a3f0b6946fb94fd7f2c441",
"src/enduser_setup.html.gz":"fbf730b33c309ceab15e88f162f43c232593f7da",
"src/http_favicon.ico.gz":"483f371c590b0407c380d019bcc6938cf1d62f0a",
"src/http_index.html.gz":"fd636bc1a6080c94949c77953598964493aec2b0",
"src/httpd_req.lua":"80053674f20f087e58e1cfd490fc71e6cdd92acf",
"src/httpd_res.lua":"7226f19699168e171970cda73b953a49450b7aa8",
"src/init.lua":"6f145587fef8616a5446a1e3f953789a0470278f",
"src/led_flip.lua":"590e7be1afe686f4213d097d0e9dba9e7a3910a0",
"src/manifest.json":"b4fa587e191cdf7a05813f0ce8b1190c59948260",
"src/manifest.json":"107b5e9a23e5720e0fd61333f5cc773479d623b2",
"src/sensors.lua":"d0d94fa73f713dcf2c517da9262f59f306b81d2b",
"src/server.lua":"8d23c80551120e6415689b0a08ef9f175bf727a6",
"src/server_device.lua":"21bdbc50f7ba48f2261af622edd8dfae724b9d60",
Expand All @@ -19,9 +19,9 @@
"src/ssdp.lua":"f2776ae2c333093e3d954950f13d77b3d880aee1",
"src/start.lua":"af90c766d9afa65c6cbcddacb7ab91124b3598c6",
"src/update.lua":"3d2f52af3873583b08e387759b9e32b4f659c357",
"src/update_manifest.lua":"f83d118142a4739d462d96ebbb750456a8351b93",
"src/update_manifest.lua":"51d4e6c1cd1f9332ecf315a9c104f2cf866e7620",
"src/update_process.lua":"b6ac63039a0edf5e816bcd17b44704f9deb6000d",
"src/variables_build.lua":"fce4b2ce56bef0f50b09e0341cdf5eb7b9be0241",
"src/variables_set.lua":"2c2d9c13c8acb577d80f40e4b513c7cd23ffdd1f",
"updated_at":"2018-02-01:04:07:30"
"updated_at":"2018-02-01:14:16:11"
}
25 changes: 11 additions & 14 deletions src/update_manifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,17 @@ local compare_github_release = function(tag_name)
end

local check_for_version_update = function()
local conn = net.createConnection(net.TCP, 1)
local latest_release_tag
conn:connect(443, "api.github.com")
conn:on("receive", function(sck, data)
local tag_name = data:match([["tag_name":"([%w%.%-]+)"]])
if tag_name then latest_release_tag = tag_name end
end)
conn:on("disconnection", function()
compare_github_release(latest_release_tag)
end)
conn:on("connection", function(sck)
sck:send("GET /repos/" .. repo .. "/releases/latest HTTP/1.1\r\nHost: api.github.com\r\nConnection: close\r\n"..
"Accept: */*\r\nUser-Agent: ESP8266\r\n\r\n")
end)
http.get(
"https://api.github.com/repos/" .. repo .. "/releases/latest",
"Accept-Encoding: deflate\r\n",
function(code, data)
local latest_release_tag
if code == 200 then
latest_release_tag = cjson.decode(data)["tag_name"]
end
compare_github_release(latest_release_tag)
end
)
end

if update.force then
Expand Down

0 comments on commit 8512469

Please sign in to comment.