-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrisetek.lua
56 lines (47 loc) · 1.4 KB
/
risetek.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- download a file from website and load and call.
local io = require("io")
local http = require("socket.http")
local ltn12 = require("ltn12")
local iot = require("iot")
local fileh = io.open("/luapath/test.lua", "w")
socket.http.TIMEOUT = 5
io.write("\r\nstart risetek\r\n")
-- local body, statusCode, headers, statusText = http.request{url = 'http://firmware.risetek.com/lua/', sink = ltn12.sink.file(io.stdout)}
local body, statusCode, headers, statusText = http.request{url = 'http://firmware.risetek.com/lua/test.lua', sink = ltn12.sink.file(fileh)}
mutex = mutex.new()
cond = cond.new(mutex)
function test()
io.write("testing... ", iot.id(), "\r\n")
-- local f, error = loadfile("/luapath/test.lua")
f = require("test")
-- f()
-- if nil == error then
-- f()
-- else
-- io.write("file load error\r\n")
-- end
mutex:lock()
cond:signal()
mutex:unlock()
end
print('statusCode ', statusCode, "\r\n")
print('statusText ', statusText, "\r\n")
print('headers\r\n')
if statusCode == 200 then
for index,value in pairs(headers) do
print(" ",index, value, "\r\n")
end
-- print('body\r\n',body)
for i = 1, 10, 1 do
tn=thread.new(15, test, {})
io.write("start risetek2\r\n")
mutex:lock()
tn:resume()
thread:yield()
io.write("start risetek3\r\n")
cond:wait()
mutex:unlock()
end
-- waiting for test thread destoryed.
thread.delay(50)
end