Jump to content

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

Posted (edited)

Hello dear forum

 

Please help me

 

I'm trying to get a GoGogate interface up and running.
Everything seems to work, except for the answer;)
I've created a simplified scene that shows my problem.

My thought is that it is the format that is wrong, but can't figure out how to make it work.
data should contain ["2", "0", "0"]

 

local ip = "192.168.0.238";
local port = 80;
local user = "admin";
local pass = "password";
local door = "1";

 

 

GGG = net.HTTPClient();
function LoginURL() return "http://" .. ip; end
function LoginData() return "/index.php?login=" .. user .. "&pass=" .. pass .. "&send-login=Sign+In"; end
function OpenCloseData() return "/isg/opendoor.php?numdoor=" .. door; end   -- .. "&status=0"
function StatusData() return "/isg/statusDoorAll.php?status1=0&status2=10&status3=10&access=1&login=" .. user; end


function httpError(err)    fibaro:debug("HTTP call error: " .. err) end

function DoFunction(resp)
    fibaro:debug( "DoFunction called, url=" .. LoginURL() .. StatusData());

    cookie = resp.headers["Cookie"];
    fibaro:debug("Cookie:" .. cookie);

    GGG:request( LoginURL() .. StatusData(),
        { 
            options = 
            {
                method = "GET",
                requestContentType = "application/json; charset=UTF-8",
                headers =
                {
                    ["Accept"] = "text/html",
                    ["Accept-Encoding"] = "gzip, deflate",
                    ["Accept-Language"] = "da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7",
                    ["Connection"] = "keep-alive",
                    ["Cookie"] = cookie,
                    ["Host"] = ip
                }
             }, 
            success = function(resp) 
                fibaro:debug("Resp = " .. json.encode(resp));

                _GetDoorStatus(resp);
            end,
            error =  httpError 
        })
end

function _GetDoorStatus(resp)
    fibaro:debug("_GetDoorStatus Data:" .. resp.data);
    data = resp.data; -- json.encode(resp.data):sub(1);
    if (data:len() <= 0) then
        fibaro:debug("Data not valid");
        return "0";
    end
    Status = data:sub(1);
    Status = Status:sub(0, Status:len() - 1);
    whichdoor = door - 1;
    -- status = Status:split(",")[whichdoor];
    doorStatus = Status;
    
    if ( doorStatus:find("0") and currentState:find("0") == 0 ) then
          SetState(door, "closed");
        currentState = "0";
    elseif ( doorStatus:find("2") and currentState:find("2") == 0 ) then
          SetState(door, "open");
        currentState = "2";
    end
    
    return currentState;
end

function SetState(_door, state)
    fibaro:debug( "Door ${door} changed status to ${state}" );
    -- fibaro:call(_VDId,"setProperty","ui.lblDoor" .. _door .. ".value",state);
end


GGG:request( LoginURL() .. LoginData(),
    { 
        options = 
        {
            method = "POST",
            headers = 
            {
                ["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                ["Accept-Encoding"] = "gzip, deflate",
                ["Accept-Language"] = "da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7",
                ["Cache-Control"] = "max-age=0",
                ["Connection"] = "keep-alive",
                ["Content-Type"] = "application/x-www-form-urlencoded",
                ["Host"] = ip,
                ["Origin"] = LoginURL(),
                ["Referer"] = LoginURL() .. "index.php",
                ["Upgrade-Insecure-Requests"] = "1"
            }
        },
        success = function(resp) 
            fibaro:debug("success");
            fibaro:debug(json.encode(resp.headers));
            cookie = resp.headers["Set-Cookie"];
            cookie = cookie:sub(1,cookie:find(";")-1);
            resp.headers["Cookie"] = cookie;

            DoFunction(resp);
        end,
        error =  httpError
    })


 

Edited by [email protected]

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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...