Jump to content
  • 0

VD reading json data Link bezpośredni w VD


Question

Posiadam miernik energii firmy ZAMEL z zainstalowaną Supla. Przy wykorzystaniu linku bezpośredniego: https://svr24.supla.org/direct/642/VUNZmkZTGJD/read otrzymuję odpowiedź w formacie HTML z informacją żeby odczytać w formacie JSON trzeba dodać odpowiedni nagłówek. 

image.thumb.png.5f5869c5901efdacfa70ada2123736b0.png

 

 

Kiedy wpisuję jako scenę poniższy skrypt:

 

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


local http = net.HTTPClient()
    local url="https://svr24.supla.org/direct/642/VUNZmkZTGJD/read"

    http:request(url, { 
        options = {
          method='GET'
        },
           success =  function (response) fibaro:debug (response.data)  end,
           error  =  function (err) fibaro: debug ("Error:"  .. err)  end
      });

 

otrzymuję niezrozumiały DEBUG:

 

[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: content="width=device-width, initial-scale=1">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: content="#00732C">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: href="/assets/img/icons/favicon.ico"
[DEBUG] 15:02:15: type="image/x-icon"/>
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: href="/assets/img/icons/favicon.ico"
[DEBUG] 15:02:15: type="image/x-icon"/>
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: type="image/png"
[DEBUG] 15:02:15: href="/assets/img/icons/supla16.png"
[DEBUG] 15:02:15: sizes="16x16">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: type="image/png"
[DEBUG] 15:02:15: href="/assets/img/icons/supla32.png"
[DEBUG] 15:02:15: sizes="32x32">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: type="image/png"
[DEBUG] 15:02:15: href="/assets/img/icons/supla96.png"
[DEBUG] 15:02:15: sizes="96x96">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: type="image/png"
[DEBUG] 15:02:15: href="/assets/img/icons/supla160.png"
[DEBUG] 15:02:15: sizes="160x160">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: type="image/png"
[DEBUG] 15:02:15: href="/assets/img/icons/supla196.png"
[DEBUG] 15:02:15: sizes="196x196">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="57x57"
[DEBUG] 15:02:15: href="/assets/img/icons/supla57.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="60x60"
[DEBUG] 15:02:15: href="/assets/img/icons/supla60.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="72x72"
[DEBUG] 15:02:15: href="/assets/img/icons/supla72.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="76x76"
[DEBUG] 15:02:15: href="/assets/img/icons/supla76.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="114x114"
[DEBUG] 15:02:15: href="/assets/img/icons/supla114.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="120x120"
[DEBUG] 15:02:15: href="/assets/img/icons/supla120.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="144x144"
[DEBUG] 15:02:15: href="/assets/img/icons/supla144.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15: sizes="152x152"
[DEBUG] 15:02:15: href="/assets/img/icons/supla152.png">
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:

[DEBUG] 15:02:15:

[DEBUG] 15:02:15:
[DEBUG] 15:02:15:

[DEBUG] 15:02:15:
[DEBUG] 15:02:15:

[DEBUG] 15:02:15:

[DEBUG] 15:02:15: 
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:

[DEBUG] 15:02:15: if it takes too long, check if the JS scripts are loaded correctly
[DEBUG] 15:02:15:


[DEBUG] 15:02:15:

[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:
[DEBUG] 15:02:15:

 

Wysyłając ten sam link z aplikacji ARC otrzymuję właściwe dane nawet bez odpowiedniego nagłówka.

 

image.thumb.png.3843615a1fa6a4b82c5f9c27d1caba8f.png

 

 

Może ktoś pomoże dodać odpowiedni nagłówek tak żeby otrzymać odpowiednie dane?

 

 

Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

MEW-01 i Home Center 3

 

Taki kod działa u mnie. Jest to rzecz jasna przykład.

Jako początkujący szukam informacji w jaki sposób dodać więcej "kafelków" do jednego QA do Dashboardu. Jakieś pomysły? Coś mi się kojarzy "child devices", ale być może ktoś z Was ma gotowy przepis, lub link gdzie o tym poczytać.

 

 

-- Energy meter type have no actions to handle
-- To update energy consumption, update property "value" and "energy" with the same floating point number
-- Eg. 
-- self:updateProperty("value", 226.137) 
-- self:updateProperty("energy", 226.137)
-- To update controls you can use method self:updateView(<component ID>, <component property>, <desired value>). Eg:  
-- self:updateView("slider", "value", "55") 
-- self:updateView("button1", "text", "MUTE") 
-- self:updateView("label", "text", "TURNED ON") 

-- This is QuickApp inital method. It is called right after your QuickApp starts (after each save or on gateway startup). 
-- Here you can set some default values, setup http connection or get QuickApp variables.
-- To learn more, please visit: 
--    * https://manuals.fibaro.com/home-center-3/
--    * https://manuals.fibaro.com/home-center-3-quick-apps/

function QuickApp:onInit()
    self:debug("onInit")
    self:debug("-------------- SUPLA ---------------")
    self.http = net.HTTPClient({timeout=5000})

local url="https://svr30.supla.org/xxxxxxxxxxxxxxxxxxxxxxxxx" -- Paste here Your key from Supla

self.http:request(url, { 
                        options = {
                                    headers = {Accept = "application/json"}, method = 'GET'
                                    },
                        success = function(response)
        -- self:debug("response status:", response.status)
        -- self:debug("headers:", response.headers["Content-Type"]) 
           
        local apiResult = response.data
        --self:debug("apiResult",apiResult) -- To see in debug if there is something in apiResult     
        local jsonTable = json.decode(apiResult) -- Decode the json string from api to lua-table
        --self:debug("jsonTable",jsonTable) -- To see in debug if there is something in jsonTable
            
         -- Get the values
local VoltagePhase1 = jsonTable.phases[1].voltage
self:debug("Voltage Phase 1: ",VoltagePhase1," V")   
local VoltagePhase2 = jsonTable.phases[2].voltage
self:debug("Voltage Phase 2: ",VoltagePhase2," V")  
local VoltagePhase3 = jsonTable.phases[3].voltage
self:debug("Voltage Phase 3: ",VoltagePhase3," V")           
            
local PowerActivePhase1 = jsonTable.phases[1].powerActive
self:debug("Active Power Phase 1: ",PowerActivePhase1," Watt")   
local PowerActivePhase2 = jsonTable.phases[2].powerActive
self:debug("Active Power Phase 2: ",PowerActivePhase2," Watt")  
local PowerActivePhase3 = jsonTable.phases[3].powerActive
self:debug("Active Power Phase 3: ",PowerActivePhase3," Watt")               

HomeActivePower = PowerActivePhase1 + PowerActivePhase2 + PowerActivePhase3
self:debug("Forward Power: ",HomeActivePower," Watt")        

self:updateProperty("value", HomeActivePower)
self:updateProperty("energy", HomeActivePower)
self:updateProperty("log", "Forward Energy")

            end,

      })

end

 

Edited by Enriquez
Link to post
Share on other sites
  • 0

Dodałem etykiety do Twojego kodu i zmienną do wpisania linku bezpośredniego z SUPLA i wszystkie parametry są widoczne.

 

 

 

SUPLA_MEW01.fqa

Edited by ptekien
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...