Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×

Question

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.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×