Script presence Xiaomi aide

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Script presence Xiaomi aide

Message par calouis »

C'est de cela dont tu parles ? http://192.168.31.1/cgi-bin/luci/;stok= ... devicelist
remplacé add mac par xx

Code : Tout sélectionner

{"mac":"xx","list":[{"mac":"xx","oname":"Unknown","isap":0,"parent":"","authority":{"wan":1,"pridisk":0,"admin":1,"lan":0},"push":0,"online":1,"name":"Unknown","times":0,"ip":[{"downspeed":"0","online":"17427","active":1,"upspeed":"0","ip":"192.168.31.181"}],"statistics":{"downspeed":"0","online":"17427","upspeed":"0"},"icon":"","type":2},{"mac":"xx","oname":"RedmiS2-axelle","isap":0,"parent":"","authority":{"wan":1,"pridisk":0,"admin":1,"lan":0},"push":0,"online":1,"name":"RedmiS2-axelle","times":0,"ip":[{"downspeed":"0","online":"24589","active":1,"upspeed":"0","ip":"192.168.31.137"}],"statistics":{"downspeed":"0","online":"24589","upspeed":"0"},"icon":"","type":1},{"mac":"xx","oname":"Unknown","isap":0,"parent":"","authority":{"wan":1,"pridisk":0,"admin":1,"lan":0},"push":0,"online":1,"name":"Unknown","times":0,"ip":[{"downspeed":"0","online":"840752","active":1,"upspeed":"0","ip":"192.168.31.148"}],"statistics":{"downspeed":"0","online":"840752","upspeed":"0"},"icon":"device_list_oneplus.png","type":2},{"mac":"xx","oname":"XiaoMiRepeater","isap":1,"parent":"","authority":{"wan":1,"pridisk":0,"admin":1,"lan":1},"push":0,"online":1,"name":"小米Wi-Fi放大器","times":0,"ip":[{"downspeed":"35","online":"272808","active":1,"upspeed":"55","ip":"192.168.31.58"}],"statistics":{"downspeed":"35","online":"272808","upspeed":"55"},"icon":"device_list_miwifi_repeater.png","type":1},{"mac":"xx","oname":"ProdePhongniart","isap":0,"parent":"","authority":{"wan":1,"pridisk":0,"admin":1,"lan":1},"push":0,"online":1,"name":"ProdePhongniart","times":0,"ip":[{"downspeed":"0","online":"17992","active":1,"upspeed":"0","ip":"192.168.31.82"}],"statistics":{"downspeed":"0","online":"17992","upspeed":"0"},"icon":"device_list_apple.png","type":2},{"mac":"xx","oname":"Unknown","isap":0,"parent":"","authority":{"wan":1,"pridisk":0,"admin":1,"lan":0},"push":0,"online":1,"name":"Unknown","times":0,"ip":[{"downspeed":"0","online":"7416","active":1,"upspeed":"0","ip":"192.168.31.115"}],"statistics":{"downspeed":"0","online":"7416","upspeed":"0"},"icon":"","type":2}],"code":0}
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Script presence Xiaomi aide

Message par papoo »

le script décode correctement le code que tu m'a envoyé
2019-01-27 21_50_43-Domoticz.png
2019-01-27 21_50_43-Domoticz.png (25.74 Kio) Consulté 3906 fois
il te faut je pense chercher du coté de curl
à tu essayer d'ajouter des print sur jsonValeur et blocjson?
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Script presence Xiaomi aide

Message par calouis »

à cela :

Code : Tout sélectionner

-- script_device_Xiaomi Network Status.lua
--------------------------------------------
dofile('/home/pi/domoticz/scripts/lua/fonctions/fonctions_perso.lua')
------------ Variables à éditer ------------
--------------------------------------------
local debugging = true  			                -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
local script_actif = true                           -- active (true) ou désactive (false) ce script simplement
local IP = "192.168.31.1"                           -- adresse IP du routeur XIAOMI sans le http
local password = "xx"                  -- mot de passe du routeur XIAOMI          

-- Test la présence d'un smartphone par son adress MAC

--------------------------------------------
----------- Fin variables à éditer ---------
--------------------------------------------
--------------------------------------------
------------- Autres Variables -------------
--------------------------------------------
local nom_script = 'Xiaomi Network Status test'
local version = '0.01'

local URL_login = "http://" .. IP .. "/cgi-bin/luci/api/xqsystem/login?username=admin&password="

local URL_token1 = "http://" .. IP .. "/cgi-bin/luci/;stok="
local URL_token2 = "/api/misystem/devicelist"
local url
local token
curl = '/usr/bin/curl -m 5 '		 	    -- pour linux, ne pas oublier l'espace à la fin
-- chemin vers le dossier lua
	if (package.config:sub(1,1) == '/') then
		 luaDir = debug.getinfo(1).source:match("@?(.*/)")
	else
		 luaDir = string.gsub(debug.getinfo(1).source:match("@?(.*\\)"),'\\','\\\\')
	end
json = assert(loadfile('/home/pi/domoticz/scripts/lua/JSON.lua'))() --Linux 
--json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Linux
--------------------------------------------
----------- Fin Autres Variables -----------
--------------------------------------------
--------------------------------------------
---------------- Fonctions -----------------

package.path = package.path..";/home/pi/domoticz/scripts/lua/fonctions/?.lua"   -- ligne à commenter en cas d'utilisation des fonctions directement dans ce script
require('fonctions_perso')                                                      -- ligne à commenter en cas d'utilisation des fonctions directement dans ce script

commandArray = {}
-- Boucle principale
if script_actif == true then
    voir_les_logs("========= ".. nom_script .." (v".. version ..") =========",debugging) 

        --=========== Lecture json ===============--

local config = assert(io.popen(curl..' "'.. URL_login .. password..'"')) 

voir_les_logs(curl..' "'.. URL_login .. password..'"',debugging)
local blocjson = config:read('*all')
config:close()
print (blocjson)
local jsonValeur = json:decode(blocjson)
print (jsonValeur)
if jsonValeur then
    url     = jsonValeur.url
    token   = jsonValeur.token
    voir_les_logs("========= URL du routeur XIAOMI MiWifi3=========",debugging)
    voir_les_logs(url,debugging)
    voir_les_logs("========= token du routeur XIAOMI MiWifi3 =========",debugging)
    voir_les_logs(token,debugging)
else
    voir_les_logs("========= aucune donnée json à décoder =========",debugging)
end
    
--local URL_token = "http://192.168.31.1/cgi-bin/luci/;stok=5b0a87eea2be461c9efa798e0cf1e69f/api/misystem/devicelist"
--     local URL_token = "http://" .. IP .. "cgi-bin/luci/;stok=" ..token .. "/api/misystem/devicelist"
       local URL_token = URL_token1 .. token .. URL_token2
 
local config = assert(io.popen(curl..' "'.. URL_token ..'"'))


voir_les_logs(curl..' "'.. URL_token ..'"',debugging)
local blocjson = config:read('*all')
config:close()
local jsonValeur = json:decode(blocjson)
    if jsonValeur then
        for I, Value in pairs( jsonValeur.list ) do
                voir_les_logs(Value.mac,debugging)  
                voir_les_logs(Value.online,debugging)
                for I, Value in pairs( Value.ip ) do  voir_les_logs(Value.ip,debugging) end 
       end
    else
        voir_les_logs("========= aucune donnée json à décoder =========",debugging)
    end    
  
voir_les_logs("======= Fin ".. nom_script .." (v".. version ..") =======",debugging)    
end
return commandArray
réponse :

Code : Tout sélectionner

2019-01-27 22:07:19.345 Status: LUA: ========= Xiaomi Network Status test (v0.01) =========
2019-01-27 22:07:19.349 Status: LUA: /usr/bin/curl -m 8 -u domoticzUSER:domoticzPSWD "http://192.168.31.1/cgi-bin/luci/api/xqsystem/login?username=admin&password=xx"
2019-01-27 22:07:19.387 Status: LUA:
2019-01-27 22:07:19.387 Status: LUA: ========= aucune donnée json à décoder =========
2019-01-27 22:07:19.387 Error: EventSystem: in script_device_Xiaomi Network Status2.lua: [string "-- script_device_Xiaomi Network Status.lua..."]:74: attempt to concatenate local 'token' (a nil value)
print ligne 58 et 60
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Script presence Xiaomi aide

Message par papoo »

pourquoi tes logs ont

Code : Tout sélectionner

/usr/bin/curl -m 8 -u domoticzUSER:domoticzPSWD
alors que le script as

Code : Tout sélectionner

'/usr/bin/curl -m 5 '
pas sur que le -u empeche ton code de fonctionner ni le domoticzUSER:domoticzPSWD mais on dirait que ton script n'utilises pas la meme commande curl
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Script presence Xiaomi aide

Message par calouis »

Certes mais pour moi, c'est du chinois...
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Script presence Xiaomi aide

Message par calouis »

Je ne sais plus pourquoi, mais j'ai un fichier JSON.lua dans /home/pi/domoticz/scripts/lua/fonctions et un autre dans /home/pi/domoticz/scripts/lua.
Il n'est pas là le problème?
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Script presence Xiaomi aide

Message par calouis »

J'ai corrigé ce chemin :

Code : Tout sélectionner

json = assert(loadfile('/home/pi/domoticz/scripts/lua/fonctions/JSON.lua'))() --Linux 
rien n'y fait :

Code : Tout sélectionner

2019-01-27 23:37:26.139 Status: LUA: ========= Xiaomi Network Status test (v0.01) =========
2019-01-27 23:37:26.144 Status: LUA: /usr/bin/curl -m 8 -u domoticzUSER:domoticzPSWD "http://192.168.31.1/cgi-bin/luci/api/xqsystem/login?username=admin&password=aavqxdmq"
2019-01-27 23:37:26.182 Status: LUA:
2019-01-27 23:37:26.182 Status: LUA: ========= aucune donnée json à décoder =========
2019-01-27 23:37:26.183 Error: EventSystem: in script_device_Xiaomi Network Status2.lua: [string "-- script_device_Xiaomi Network Status.lua..."]:76: attempt to concatenate local 'token' (a nil value)
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
Répondre