parip69 Posté(e) le 15 janvier 2017 Signaler Posté(e) le 15 janvier 2017 (modifié) Hi I need it in a script not in VD. Please help with the scrip. My response is always nil. thank you function statusVU(); local http = net.HTTPClient(); http:request('http://192.168.11.11:80/web/powerstate', {success = function(resp) local vuStatusAus = (string.match (resp.data, "true")); if vuStatusAus == "true" then; return true; else; VuEinAus = "aus"; return false; end; end}) end print(statusVU()) Modifié le 15 janvier 2017 par parip69
parip69 Posté(e) le 16 janvier 2017 Auteur Signaler Posté(e) le 16 janvier 2017 Hello I need a tip ... please
Lazer Posté(e) le 16 janvier 2017 Signaler Posté(e) le 16 janvier 2017 Sorry, it won't work. The net.HTTPClient is an asynchronous function, so the content is executed after the end of your main LUA script. So you will never be able to get the return value, that is why you always get nil. If you use the net.HTTPClient() fonction, you have to put the remaining LUA instructions inside your success() function. There are many net.HTTPClient in this forum (have a look at my Watchdog script) and on the official Fibaro forum.
parip69 Posté(e) le 17 janvier 2017 Auteur Signaler Posté(e) le 17 janvier 2017 Hi Where I have to enter the return so my function returns true. I need help. My print (statusVU ()) is always nill i need the return or vareanle with response.status. function statusVU() local vuStatusAus getURL = 'http://192.168.11.33:80/web/powerstate' putURL = 'http://192.168.11.33:80/web/powerstate' local httpClient = net.HTTPClient() httpClient:request(getURL, { success = function(response) if response.status == 200 then httpClient:request(putURL, { success = function(response) if response.status == 200 then return true end end, error = function(err) end, options = { method = 'PUT', data = response.data } }) else end end, error = function(err) end, options = { method = 'GET' } }) end print(statusVU())
Lazer Posté(e) le 17 janvier 2017 Signaler Posté(e) le 17 janvier 2017 Your code can't work. I told you that it is impossible to get the return value of an asynchronous function. I'm sorry I have neither the time, neither the possibility to write and test a LUA code for now, so you have to search using the given examples on the forum. To summarize, your code must be within the success() function, not outside.
parip69 Posté(e) le 29 janvier 2017 Auteur Signaler Posté(e) le 29 janvier 2017 Hello Unfortunately, I can not find a solution for my problem. I've read weeks ago. Is there a "get" or "request" option as below for scene only, but without fonction as below for only one scene. Hello Lazer I can think that you have no time, but others many. Thank you local selfId = fibaro:getSelfId(); local ip = fibaro:get(selfId, "IPAddress") local url = "/web/powerstate" local ws = Net.FHttp(ip, 80) local resp = ws:GET(url) --fibaro:debug(resp) if (string.find(resp, "true") == NIL) then fibaro:debug('AN') else fibaro:debug('AUS') end
Lazer Posté(e) le 30 janvier 2017 Signaler Posté(e) le 30 janvier 2017 you should try in a virtual device, not in a scene In a Virtual device, you can use the classic Net.FHttp()
Messages recommandés