Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
Dako02 1
Witam
jest stworzony przez kolegę z Germani " Boomx " prosty kod aby uzyskać ip i url do Kamerki Netatmo Welcom.
A że dzisiaj zainstalowałem Netatmo Presence chciał bym wam ułatwić zadanie z dostępem do Presence.
trzeba podmienić poniższy kod w wirtualce dla welkom cam.
function oAuth(nextFunction)
local request_body = 'grant_type=password&client_id=' .. client_id .. '&client_secret=' .. client_secret .. '&username=' .. username .. '&password=' .. password .. '&scope=read_presence access_presence'
dla leniwych cały kod :
--[[
%% properties
%% globals
--]]
-- DIESE DATEN ANPASSEN wprowadzić swoje dane
local client_id = '55xxxxxxxxxxxxxxxxxxxxxx69'
local client_secret = 'quoLyxxxxxxxxxxxxxxxxxxxtuRlwnpNPbP5'
local username = 'dkonecko@xxxxxxxxx'
local password = 'xxxxxxxxxx'
local language = 'german' -- german/english
-- AB HIER NICHTS MEHR ANPASSEN
local token = ''
local request_body = ''
Debug = function ( color, message )
if (debug == 1) then
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
elseif (debug == 0) then
end
end
DebugChange = function ( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
end
DebugError = function ( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
end
fibaro:debug('netatmo welcome cam finder v1.0b')
if (language == 'german' or language == 'english') then
DebugError( "green", "Debug: " ..language)
else
DebugError( "red", "Please choose a language for debug")
fibaro:abort();
end
local sourceTrigger = fibaro:getSourceTrigger();
function oAuth(nextFunction)
local request_body = 'grant_type=password&client_id=' .. client_id .. '&client_secret=' .. client_secret .. '&username=' .. username .. '&password=' .. password .. '&scope=read_presence access_presence'
getResponseData('https://api.netatmo.net/oauth2/token', request_body,
function(data)
if (data.access_token ~= nil) then
token = data.access_token
gethomedata()
else
if (language == 'german') then
DebugError( "red", "oAuth-API-Call konnte nicht durchgeführt werden! oAuth 2.0 lieferte keinen Wert zurück")
elseif (language == 'english') then
DebugError( "red", "oAuth-API-Call Error. oAuth 2.0 returns nothing.")
end
end
end
)
end
function getResponseData(url, body, func)
local http = net.HTTPClient()
http:request(url, {
options = {
method = 'POST',
headers = {
['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
},
data = body
},
success = function(response)
func(json.decode(response.data))
end
})
end
function gethomedata()
request_body_cam = 'access_token=' ..token.. ''
getResponseData('https://api.netatmo.net/api/gethomedata', request_body_cam,
function(getData)
--fibaro:debug(request_body_cam)
if (getData.body ~= nil) then
if (language == 'german') then
DebugError( "green", "API-Call durchgeführt.")
elseif (language == 'english') then
DebugError( "green", "API-Call was done.")
end
for w, v in pairs(getData.body.homes) do
for a, b in pairs(v.cameras) do
if (b.is_local) then
if (language == 'german') then
DebugError( "green", "Lokale IP der Kamera gefunden.")
elseif (language == 'english') then
DebugError( "green", "Local IP of cam was found.")
end
findLocalPresence(b.vpn_url)
else
if (language == 'german') then
DebugError( "green", "Lokale IP der Kamera NICHT gefunden.")
elseif (language == 'english') then
DebugError( "green", "Local cam NOT found.")
end
end
end
end
else
if (language == 'german') then
DebugError( "red", "API-Call fehlgeschlagen")
elseif (language == 'english') then
DebugError( "red", "API-Call Error")
end
end
end
)
end
function findLocalPresence(url)
local selfhttp = net.HTTPClient({timeout=2000})
url = url..'/command/ping'
selfhttp:request(url, {
options={
headers = selfhttp.controlHeaders,
method = 'GET',
timeout = 5000
},
success = function(status)
if status.status == 200 then
if status.data ~= nil then
--print(json.decode(status.data))
for k,v in pairs(json.decode(status.data)) do
if (k == 'local_url') then
local cam_url = v
local url_new = string.sub(cam_url, 8, #cam_url)
one, two = url_new:match("([^,]+)/([^,]+)")
fibaro:debug('Cam-IP: '..one)
fibaro:debug('JPG-Stream: /'..two.. '/live/snapshot_720.jpg')
DebugError( "green", "coded 4 siio.de/siio.com")
end
end
end
else
print ("failed")
print(status.data)
end
end,
error = function(error)
print "ERROR"
print(error)
end
})
end
oAuth()
dane uzyskane w wirtualce jak IP I url do obrazu kopiujemy do zakładki kamera bez użytkownika i hasła.
miłej zabawy.
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.