Bonjour,
Avis aux possesseurs d'alarmes Myfox, je viens de trouver cela:
http://gurau-audibert.hd.free.fr/josdblog/2015/03/communication-en-lua-avec-la-centrale-myfox/#more-6458
Ce qui nous ferait ...
--[[
%% properties
%% globals
–]]
local https = require("ssl.https")
local identifiant = '<identifiant>'
local motDePasse = '<mot de passe>'
local clientID = '<Client ID>'
local clientSecret = '<Client Secret>'
local siteId = '<Site Id>'
local access_token = nil
local refresh_token = nil
local echeance = nil
-- Request access token
function acquerirJeton()
local url = 'https://api.myfox.me/oauth2/token'
local post = string.format('grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s', clientID, clientSecret, identifiant, motDePasse)
local body, code = https.request(url, post)
assert(code == 200)
access_token, refresh_token = string.match(body, '"access_token":"([^"]*)".*"refresh_token":"([^"]*)"')
end
-- Refreshing an expired access_token
function renouvelerJeton()
local url = 'https://api.myfox.me/oauth2/token'
local post = string.format('grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s', refresh_token, clientID, clientSecret)
local body, code = https.request(url, post)
assert(code == 200)
access_token, refresh_token = string.match(body, '"access_token":"([^"]*)".*"refresh_token":"([^"]*)"')
end
-- Statut de l'alarme : 'disarmed', 'partial' ou 'armed'
function statut()
local url = string.format('https://api.myfox.me:443/v2/site/%s/security?access_token=%s', tostring(siteId), access_token)
local body, code = https.request(url)
assert(code == 200)
local statut = string.match(body, '"statusLabel":"([^"]*)"')
return statut
end
Je le testerai ce WE ... avis aux intéressés ...
Bonjour,
Avis aux possesseurs d'alarmes Myfox, je viens de trouver cela:
http://gurau-audibert.hd.free.fr/josdblog/2015/03/communication-en-lua-avec-la-centrale-myfox/#more-6458
Ce qui nous ferait ...
--[[
%% properties
%% globals
–]]
local https = require("ssl.https")
local identifiant = '<identifiant>'
local motDePasse = '<mot de passe>'
local clientID = '<Client ID>'
local clientSecret = '<Client Secret>'
local siteId = '<Site Id>'
local access_token = nil
local refresh_token = nil
local echeance = nil
-- Request access token
function acquerirJeton()
local url = 'https://api.myfox.me/oauth2/token'
local post = string.format('grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s', clientID, clientSecret, identifiant, motDePasse)
local body, code = https.request(url, post)
assert(code == 200)
access_token, refresh_token = string.match(body, '"access_token":"([^"]*)".*"refresh_token":"([^"]*)"')
end
-- Refreshing an expired access_token
function renouvelerJeton()
local url = 'https://api.myfox.me/oauth2/token'
local post = string.format('grant_type=refresh_token&refresh_token=%s&client_id=%s&client_secret=%s', refresh_token, clientID, clientSecret)
local body, code = https.request(url, post)
assert(code == 200)
access_token, refresh_token = string.match(body, '"access_token":"([^"]*)".*"refresh_token":"([^"]*)"')
end
-- Statut de l'alarme : 'disarmed', 'partial' ou 'armed'
function statut()
local url = string.format('https://api.myfox.me:443/v2/site/%s/security?access_token=%s', tostring(siteId), access_token)
local body, code = https.request(url)
assert(code == 200)
local statut = string.match(body, '"statusLabel":"([^"]*)"')
return statut
end
Je le testerai ce WE ... avis aux intéressés ...