Aller au contenu

Recup Json Alarme / Lua / VD


yoim

Messages recommandés

Merci Mr @Steven & @pepite

 

Le gsub fonctionne correctement. :D ca fait du bien quand ca marche. Tout seul je n'aurais pas reussi.

 

Pour que tout soit impec, me reste l'authentification ... Ca passe pas :

 

Mon code :

 

local password = 'password Base64' 
local http = net.HTTPClient()
http:request(url, user, password, {
    
options = {
                method = 'POST',
                headers = {
        				["content-type"] = 'application/json',
                        ["Authorization"] = 'Basic '..password
                          },
    
    

 

Pour mon user:password j'ai fait ca : 

 

echo -n 'user:password' | base64

 

J'ai un debug comme ca :

 

[DEBUG] 00:24:07: [1;31m2018-01-05 00:24:07.933419 [ fatal] Runtime error: No matching overload found, candidates:
[DEBUG] 00:24:07: void request(HTTPClient&,std::string const&,custom [lua::OptionsGroup])
[DEBUG] 00:24:07: void request(HTTPClient&,std::string const&)

 

Par contre comment je peux savoir que mon alarme est codé en user:password en base64.

 

Je pense que c'est un htaccess classique... normalement c'est bien du base64. En rentrant mon user password dans l'url complete user:password@ip ca fonctionne avec chrome.

 

Pour le moment, je copie mon json sur un serveur exterieur et là tout fonctionne nickel. Si j'arrive a faire mon authentification depuis ma scene. Mon code sera autonome pour recuperer mes etats alarme egardia.

 

 Merci encore.

 

Lien vers le commentaire
Partager sur d’autres sites

@pepite

Merci pour le lien ;) Par contre je suis bien en Base64.

 

Je comprends pas, ca passe pas. Toujours 401 :

 

local url = 'http://192.168.42.125/action/sensorListGet'
local password = 'passwordenBase64'
   fibaro:debug("oki")
  
http = net.HTTPClient()
http:request(url, {
                 options = { method = 'POST' },
			     headers = { authentication = 'Basic '..password },
					
    				

  			success = function(p)
                            fibaro:debug(p.status)
                            fibaro:debug(p.data)
                 end,
                 error = function(err)
                            fibaro:debug(err)
                 end
  
  })

 

En debug

 

DEBUG] 23:52:29: oki
[DEBUG] 23:52:29: 401
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
Access Error: Unauthorized

[DEBUG] 23:52:29:
Access to this document requires a User ID


[DEBUG] 23:52:29:
Go to home

[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:
[DEBUG] 23:52:29:

J'ai tout essayé, je n'arrive pas a me connecter en direct sur l'alarme.

 

J'ai remis dans le code user, password,

 

local url = 'http://192.168.42.125/action/sensorListGet'
local password = 'passwordBase64'
   fibaro:debug("oki")
  
http = net.HTTPClient()
http:request(url, user, password,{
                 options = { method = 'POST' },
			     headers = { authentication = 'Basic '..password },
					
    				

  			success = function(p)
                            fibaro:debug(p.status)
                            fibaro:debug(p.data)
                 end,
                 error = function(err)
                            fibaro:debug(err)
                 end
  
  })

en debug

 

[DEBUG] 23:57:30: oki
[DEBUG] 23:57:30: [1;31m2018-01-05 23:57:30.223483 [ fatal] Runtime error: No matching overload found, candidates:
[DEBUG] 23:57:30: void request(HTTPClient&,std::string const&,custom [lua::OptionsGroup])
[DEBUG] 23:57:30: void request(HTTPClient&,std::string const&)

Je ne vois pas d'erreur dans mon code.

 

Est ce que ca pourrait venir de l'IP dans l'url ...

 

 

Lien vers le commentaire
Partager sur d’autres sites

Je tenterais plutôt avec Authorization au lieu de authentication


headers = { Authorization = 'Basic '..password },

 

Et si ça ne passe pas, je mettrais le couple USER:PASSWORD en base64 au lieu de juste password

Lien vers le commentaire
Partager sur d’autres sites

Merci @Steven

 

J'ai le même probleme, peux tu me confirmer ce code :

 

local url = 'http://192.168.42.125/action/sensorListGet'
local password = 'user:password en base64'
   fibaro:debug("oki")
  
http = net.HTTPClient()
http:request(url, user, password,{
                 options = { method = 'POST' },
			     headers = { Authorization = 'Basic '..password },
					
    				

  			success = function(p)
                            fibaro:debug(p.status)
                            fibaro:debug(p.data)
                 end,
                 error = function(err)
                            fibaro:debug(err)
                 end
  
  })

Il y a bien ici url, user, password ? :

 

http:request(url, user, password,{
                 options = { method = 'POST' },

 

J'ai essayé les 2 methodes. Même probleme.

 

[DEBUG] 14:56:20: oki
[DEBUG] 14:56:20: [1;31m2018-01-08 14:56:20.222043 [ fatal] Runtime error: No matching overload found, candidates:
[DEBUG] 14:56:20: void request(HTTPClient&,std::string const&,custom [lua::OptionsGroup])
[DEBUG] 14:56:20: void request(HTTPClient&,std::string const&)

 

 

Lien vers le commentaire
Partager sur d’autres sites

Bonjour,

 

C'est bon tout fonctionne, sauf mon authentification... Je vais essayé de passer par un VD pour recuperer mon Json.

 

Je vous partage le code qui fonctionne parfaitement. Merci à tous ! @pepite @Steven

 

--[[
%% autostart
%% properties
%% events
%% globals
--]]

local idTelUser = 555
local delay = 60 --en secondes

local Source = fibaro:getSourceTrigger()

function Run()

local url = "http://url.json"
local http = net.HTTPClient()
fibaro:debug("Prog Launch")
http:request(url,  {
                 options = { method = 'GET' },
    
					success = function(p)
                            --fibaro:debug(p.status)
                     		--fibaro:debug(p.data)      
            local open = false
				p.data:gsub("(.-)Door Contact(.-)name : \"(.-)\"(.-)cond : \"(.-)\"", function(a,b,c,d,e) 
   				 if (e == "Open") then
      				open = true
      				print(c .. " est ouvert")
              		fibaro:call(idTelUser,"sendPush", c .." est ouvert")
   					 end
						end)

                 end,
                 error = function(err)
                            fibaro:debug(err)
                 end
   })

     setTimeout(Run,delay*1000)
  end

     if Source["type"] == "autostart" or  Source ["type"] == "other" then
  Run()
  end

 

Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...