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!



Smart Home Forum by FIBARO Team

  • 0

Changing http request from HC2 VD to HC3 QuickApp ("Robonect"- modul for Husqvarner Automower)



Hello guys,


for the first: english ist not my first language - sorry!


I have on HC2 a running VD to integrate a ROBONECT-modul (www.robonect.de) on HC2. Now, i am a owner of a HC3 (5.110.15) and i will change the request to HC3 Quickapp.
The running code on VD  for get a http request for status looks like this:


-- Setze Verbindungsdaten
-- hole ip adresse aus virtuellem modul
local selfId = fibaro:getSelfId()
local mowerIP = fibaro:get(selfId, "IPAddress")
local mowerPort = fibaro:get(selfId, "TCPPort")
local versuche = 3
-- setze variable MOWER aus IP und Logindaten
MOWER = Net.FHttp(mowerIP)
--check Onlinestatus
local function _ping(retry)
    fibaro:call(selfId, "setProperty", "ui.OLStatus.value", "Starte Online-Check")
    retry = retry or 0
    local tcpSocket = Net.FTcpSocket(mowerIP, mowerPort)
    --fibaro:debug('Suche..., versuche #' .. retry .. ' bitte warten...')
    local bytes, errorCode = tcpSocket:write('ping')

    if errorCode == 0 then
        return true
        if retry < versuche then
        --fibaro:debug('Nicht gefunden, erneut versuchen, bitte warten...')
    return _ping(retry + 1)
    return false

local f, result = pcall(_ping)

if (f) then
    if (result == true) 

        fibaro:debug(mowerIP.. ':' .. mowerPort .. ' wurde gefunden,')
        fibaro:call(selfId, "setProperty", "ui.OLStatus.value", "Mower ist Online");
        fibaro:debug("Status wird abgefragt");

        fibaro:debug("Status online - starte Abfragen");
        fibaro:debug(mowerIP.. ':' .. mowerPort .. ' wurde nicht gefunden.')
        fibaro:call(selfId, "setProperty", "ui.OLStatus.value", "Mower ist Offline")
        fibaro:debug("Status des Automower wird aufgrund mangelnder Erreichbarkeit nicht abgefragt")
        fibaro:debug("Status wurde nicht abgefragt, warte für 5 Minuten)");

    fibaro:debug('Error: ' .. f)

-- geting info about specific device
  response = MOWER:GET("/json?cmd=status")
-- decoding json string to table
  extractedjson = json.decode(response)

-- "status/battery": "Battery Status"
-- "status/duration": "Mode Duration"
-- "status/hours": "Hours"
-- "status/mode": "Mode"
-- "status/status": "Status"
-- "timer/status": "Timer Status"

  battery = extractedjson.status.battery
  duration = extractedjson.status.duration
  hours = extractedjson.status.hours
  AM_Status = extractedjson.status.status
  AM_Mode = extractedjson.status.mode
  AM_Timer = extractedjson.timer.status
 -- Error_ = extractedjson.error.status


  fibaro:call(selfId, "setProperty", "ui.LabelBatterystatus.value",(battery).." %");
  fibaro:call(selfId, "setProperty", "ui.LabelModeDuration.value",(duration).." s");
  fibaro:call(selfId, "setProperty", "ui.LabelHours.value",(hours).."h");
  --fibaro:call(selfId, "setProperty", "ui.LabelMode.value",(AM_Mode));

  --fibaro:call(selfId, "setProperty", "ui.LabelStatus.value",(AM_Status));

  --fibaro:call(selfId, "setProperty", "ui.LabelTimer.value",(AM_Timer));

--fibaro:debug("Status Auswertung gestartet") 
--fibaro:debug("Autmowerstatus = "..AM_Status)
fibaro:call(selfId, "setProperty", "ui.LabelStatus.value","Check Mowerstatus");
if (AM_Status == 17) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Automower schläft");
  fibaro:call(selfId, "setProperty", "currentIcon","1013");
  fibaro:log("Status: Automower schläft")
  fibaro:setGlobal("MowerStatus", "sleeping")
  --fibaro:debug("Automower schläft")
elseif (AM_Status == 1) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Automower parkt/hat gestoppt");
   fibaro:call(selfId, "setProperty", "currentIcon","1017");
  fibaro:log("Status: Automower parkt")
  --fibaro:debug("Automower parkt")
  fibaro:setGlobal("MowerStatus", "parking")
elseif (AM_Status == 2) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Automower mäht");
   fibaro:call(selfId, "setProperty", "currentIcon","1010");
  fibaro:log("Status: Automower mäht")
  --fibaro:debug("Automower mäht")
  fibaro:setGlobal("MowerStatus", "mowing")
elseif (AM_Status == 3) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Automower sucht die Ladestation");
   fibaro:call(selfId, "setProperty", "currentIcon","1014");
  fibaro:log("Status: Automower sucht die Ladestation")
  --fibaro:debug("Automower sucht die Ladestation")
  fibaro:setGlobal("MowerStatus", "searching")
elseif (AM_Status == 4) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Automower lädt");
   fibaro:call(selfId, "setProperty", "currentIcon","1016");
  fibaro:log("Status: Automower lädt")
  --fibaro:debug("Automower lädt")
  fibaro:setGlobal("MowerStatus", "charging")
elseif (AM_Status == 5) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Automower sucht (manuell umsetzen)");
  fibaro:call(selfId, "setProperty", "currentIcon","1015");
  fibaro:log("Status: Automower sucht (manuell umsetzen)")
  --fibaro:debug("Automower sucht (manuell umsetzen)")
elseif (AM_Status == 7) then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Fehlerstatus");
  fibaro:log("Status: Fehlerstatus")
elseif (AM_Status == ? then
  fibaro:call(selfId, "setProperty", "ui.LabelStatus.value"," Schleifensignal verloren");
   fibaro:call(selfId, "setProperty", "currentIcon","1012");
  fibaro:log("Status: Automower Schleifensignal verloren")
  --fibaro:debug("Automower Schleifensignal verloren")
  fibaro:setGlobal("MowerStatus", "lost_signal")
  fibaro:call(selfId, "setProperty", "ui.LabelState.value"," Error");
  fibaro:log("Status: Ladefehler")
fibaro:setGlobal("AM_Status", AM_Status);
fibaro:call(selfId, "setProperty", "ui.LabelMode.value","Check Mowermodus");


--fibaro:debug("Modus Auswertung gestartet")

if (AM_Mode == 0) then
  fibaro:call(selfId, "setProperty", "ui.LabelMode.value"," Auto");
  fibaro:log("Mode: Auto")
    fibaro:setGlobal("MowerMode", "Auto")
elseif (AM_Mode == 1) then
  fibaro:call(selfId, "setProperty", "ui.LabelMode.value"," Manuell");
  fibaro:log("Mode: Manuell")
  fibaro:setGlobal("MowerMode", "Man")
elseif (AM_Mode == 2) then
  fibaro:call(selfId, "setProperty", "ui.LabelMode.value"," Home");
  fibaro:log("Mode: Home")
  fibaro:setGlobal("MowerMode", "Home")
  fibaro:call(selfId, "setProperty", "ui.LabelMode.value"," Error");
  fibaro:log("Mode: Fehler")

  fibaro:setGlobal("AM_Mode", AM_Mode);
fibaro:call(selfId, "setProperty", "ui.LabelTimer.value","Check Timermodus");


--fibaro:debug("Timer Auswertung gestartet")

if (AM_Timer == 0) then
  fibaro:call(selfId, "setProperty", "ui.LabelTimer.value"," Deaktiviert");
  fibaro:log("Timer: Deaktiviert")
elseif (AM_Timer == 1) then
  fibaro:call(selfId, "setProperty", "ui.LabelTimer.value"," Auto");
  fibaro:log("Timer: Auto")
elseif (AM_Timer == 2) then
  fibaro:call(selfId, "setProperty", "ui.LabelTimer.value"," Standby");
  fibaro:log("Timer: Standby")
  fibaro:call(selfId, "setProperty", "ui.LabelTimer.value"," Error");
  fibaro:log("Timer: Fehler")


  fibaro:setGlobal("AM_Timer", AM_Timer);


on a webbrowser i get a complete status with this:


{"name": "MowerReiche", "id": "10AD57", "status": {"status": 17, "distance": 0, "stopped": false, "duration": 42067, "mode": 2, "battery": 100, "hours": 2604}, "timer": {"status": 0, "next": {"date": "2022-07-07", "time": "10:00:00", "unix": 1657188000}}, "blades": {"quality": 84, "hours": 22, "days": 15}, "wlan": {"signal": -89}, "health": {"temperature": 24, "humidity": 28}, "clock": {"date": "2022-07-07", "time": "08:20:55", "unix": 1657182055}, "successful": true}


My code for HC3 QuickApp to get a status-info:


local self
local function setSelf(qa) self = qa end
function Base64(data)
    local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    return ((data:gsub('.'function(x) 
        local r,b='',x:byte()
        for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0'end
        return r;
        if (#x < 6then return '' end
        local c=0
        for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0end
        return b:sub(c+1,c+1)
    end)..({ '''==''=' })[#data%3+1])
function QuickApp:onInit()
    ip = self:getVariable("ip")
    port = tonumber(self:getVariable("port"))
    self.sock = net.TCPSocket()
    usr = Base64(self:getVariable("user"))
    pwd = Base64(self:getVariable("pwd"))
    address = "http://"..usr..":"..pwd.."@"..ip..":"..port.."/json?cmd=status"
function QuickApp:command(address)
self.http = net.HTTPClient({timeout=3000})
    self.http:request(address, {
            headers = { 
                Accept = "application/json"
            checkCertificate = false,
            method = 'GET'
        success = function(response)
            self:debug("response status:", response.status) 
            --self:debug("headers:", response.headers["Content-Type"]) 
            local data = json.decode(response.data)
        error = function(error)
            self:debug('error: ' .. json.encode(error))

I try for hours, but every time i get a "401" response.

What notation can solve this?
Link to comment
Share on other sites

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.

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