Jump to content

Broadlink (without bridge)


Recommended Posts

Hi!

 

I needing your help :)

 

i am trying to develop / porting accessing to Broadlink IR devices.

1st step is - discovering devices,

if you have some Broadlink devices please import this VD and run button

after this action you should refresh (F5) UI and should see some new VD devices in Fibaro UI.

can you confint what it's works.

 

thnak you!

 

Edited by 10der
Link to post
Share on other sites

Discover and creation of VD work fine for RM mini3

[DEBUG] 16:19:20: Broadcasting discovery message
[DEBUG] 16:19:20: c8:f7:42:62:a0:c3
[DEBUG] 16:19:20: 192.168.1.72
[DEBUG] 16:19:20: BroadLink device type: 0x2737
[DEBUG] 16:19:20: RM Mini
[DEBUG] 16:19:25: Get virtual devices status: 200 Error code: 0
[DEBUG] 16:19:25: exists: 0
[DEBUG] 16:19:25: DEVICE NAME DOES NOT EXIST: c8:f7:42:62:a0:c3
[DEBUG] 16:19:26: Global VD create status: 201 Error code: 0
[DEBUG] 16:19:26: Response data create: {"id":1902,"name":"c8:f7:42:62:a0:c3","roomID":0,"type":"virtual_device","visible":true,"enabled":true,"properties":{"categories":["other"],"deviceIcon":0,"ip":"","port":0,"currentIcon":"0","log":"","logTemp":"","mainLoop":"","visible":"true","rows":[]},"actions":{"pressButton":1,"setSlider":2},"created":1570112366,"modified":1570112366,"sortOrder":714}
[DEBUG] 16:19:26: Created VD ID is 1902
[DEBUG] 16:19:26: Global VD mod status: 200 Error code: 0
[DEBUG] 16:19:26: Response data mod: {"id":1902,"name":"c8:f7:42:62:a0:c3","roomID":0,"type":"virtual_device","visible":true,"enabled":true,"properties":{"categories":["other"],"deviceIcon":0,"ip":"192.168.1.72","port":80,"currentIcon":"0","log":"","logTemp":"","mainLoop":"","ui.Label1.value":"","visible":"true","rows":[{"type":"label","elements":[{"id":1,"lua":false,"waitForResponse":false,"caption":"RM Mini","name":"Label1","favourite":false,"main":false}]}]},"actions":{"pressButton":1,"setSlider":2},"created":1570112366,"modified":1570112366,"sortOrder":714}
[DEBUG] 16:19:26: { ["blInternalId"] = ????,["blDeviceType"] = 10039,["blIp"] = 192.168.1.72,["blDesc"] = RM Mini,}

 

  • Thanks 1
Link to post
Share on other sites

So. some good news. and some bad news.

1) now I can gran all my bradlink devices in HC2

2) I can send any command to my devices via HC2 (command should be setuped via Broadlink.WinApp.exe  (windows)

image.png.b6e219c1fde12b3c1e840f27aabfe736.png

 

3) bad news. I can't  implement AES128 for HC2. at all.

If we have any guru like @jgab or @petergebruers please help me...

 

4) so I have publish VD's source code.

but one notice here. for encrypt / decrypt used external php application

please 

1) setup this application

2) patch lines for calling this service

 

    local url = "/crypt/aes.php?data=" .. toHex(inputStr).."&mode=" .. inOut .. "&key="..key
    fibaro:debug(url)
 
    -- connect to HC2 
    local HC2 = Net.FHttp("192.168.1.29"80); 
 

 

<?php

$iv = "562e17996d093d28ddb3ba695a2e6f58";
$key = $_GET["key"];
$mode = $_GET["mode"];
$method = 'aes-128-cbc';

$source = hex2bin($_GET["data"]);
file_put_contents ('/tmp/aes.in', $source);

exec("openssl enc -". $method. " ". $mode . " -nopad -in /tmp/aes.in -out /tmp/aes.out -K ". $key ." -iv " . $iv);
$contents = file_get_contents ('/tmp/aes.out');

$target =  bin2hex($contents);
echo($target);

?>

 

 

 

Edited by 10der
  • Like 1
Link to post
Share on other sites

socket is not accessible in HC2 (lines 574, 690)

I propose:

socket = function(ToSend, IP, Port)
local Response={}
socketudp = Net.FUdpSocket()
socketudp:setBroadcast(true)
socketudp:setReadTimeout(250)  
bytes, ErrorCode = socketudp:write (ToSend, IP, Port)
  if ErrorCode == 0 then
  local ResponseLength = 1
      while (ErrorCode==0 and ResponseLength>0 and ResponseLength~=22) do
      Response, ErrorCode = socketudp:read()
      ResponseLength = string.len(Response)
      end
  end
end

 

  • Like 1
Link to post
Share on other sites

or use in code

local udp = Net.FUdpSocket()

in place of

local udp = socket.udp()

and do correction to udp:setTimeout... to    udp:setReadTimeout(MSG_TIMEOUT)

Sorry but in this moment i haven't possibility to analyze and correct whole code, maybe after tomorrow when I return home.

Link to post
Share on other sites
  • 1 month later...

Good afternoon! Please tell me if there is news on the use of your code? How to force Broadlink to execute commands with HC2? The question is very important to me

If you use the recommendations from the post above:

 

or use in code

local UDP = net.Udpsocket()

instead

local UDP = socket.UDP()

and make an amendment to udp: setTimeout... for UDP: setReadTimeout(MSG_TIMEOUT)

 

then in HC2 an error comes out:

[DEBUG] 11:44:43: 2019-11-24 11:44:43.268600 [ fatal] Unknown exception: /opt/fibaro/scenes/300.lua:582: attempt to index global 'Net' (a nil value)

 

and one more question: can I describe in more detail how to get the keys for broadlink?

Link to post
Share on other sites

:(

 

AES crypt can't be implemented on Fibaro LUA.

that's al.

 

here is ugly VD for using RM3 mini

1) set Ip adress for broadlink device

2) change lines in code

 

--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==
local aesServer = "192.168.1.29"
local aesServerPort = 80
local aesServerUrl = "/crypt/aes.php" -- data mode key iv
--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==

aes.php is:

 

<?php

$iv = "562e17996d093d28ddb3ba695a2e6f58";
$key = $_GET["key"];
$mode = $_GET["mode"];
$method = 'aes-128-cbc';

$fileIn = tempnam("/tmp", "in_");
$fileOut = tempnam("/tmp", "out_");

$source = hex2bin($_GET["data"]);
file_put_contents ($fileIn, $source);

exec("openssl enc -". $method. " ". $mode . " -nopad -in $fileIn -out $fileOut -K ". $key ." -iv " . $iv);
$contents = file_get_contents ($fileOut);

$target =  bin2hex($contents);
echo($target);

unlink($fileIn);
unlink($fileOut);

?>

please do not change anuthing here if you do not know what i do.

 

3) change command

local command = "26006800C0FA1272137214711471132F1471142E1471132F132F1131132F1372142D1471123014711174142E1471117413721372132F132F132F1372132F132E142E12301471142E1471142E1471132F1372142E132F1174132F1372132F1371142F1371147114F513000D05"

 

image.png.8c727b7e4f071bb04ed7d693af6a6a86.png

 

 

 

Broadlink_RM3_Mini_241119.vfib

Edited by 10der
Link to post
Share on other sites

also. you can convert public database with codes  to broadlink codes with this LUA

 

function setGlobalValue(name, value)
    local xvalue = fibaro:getGlobalValue(name)
    if xvalue == nil then
      	local data = {name = name, value="0"}
      	api.post("/globalVariables", data)
    end
    fibaro:setGlobal(name, value)
end

function base64dec(data)
    local b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" -- You will need this for encoding/decoding
    data = string.gsub(data, "[^" .. b .. "=]", "")
    return (data:gsub(
        ".",
        function(x)
            if (x == "=") then
                return ""
            end
            local r, f = "", (b:find(x) - 1)
            for i = 6, 1, -1 do
                r = r .. (f % 2 ^ i - f % 2 ^ (i - 1) > 0 and "1" or "0")
            end
            return r
        end
    ):gsub(
        "%d%d%d?%d?%d?%d?%d?%d?",
        function(x)
            if (#x ~= 8) then
                return ""
            end
            local c = 0
            for i = 1, 8 do
                c = c + (x:sub(i, i) == "1" and 2 ^ (8 - i) or 0)
            end
            return string.char(c)
        end
    ))
end

function tohex(str)
    return (str:gsub(
        ".",
        function(c)
            return string.format("%02X", string.byte(c))
        end
    ))
end

local vdId = 1543;

local command = "JgBoAL/6EnYSdhN1EnYSMxF3EnYTdRMyETUSMhI0EXYSNBE0EjMSMxJ2EnYSdhF4ETMSdhMyEnYSMxI0ETQSMxF3EjMSdhIzEnYSMxJ2FDIRdxE0ETMSdhI0EXcSMxF3EjMTdRN1EvoSAA0F"
command = tohex(base64dec(command))
setGlobalValue("brdl_".. vdId, command)
fibaro:call(vdId, "pressButton", "1")

data base with codes attached,

 

 

codes.zip

Edited by 10der
Link to post
Share on other sites
5 hours ago, 10der said:

:(

 

AES crypt can't be implemented on Fibaro LUA.

that's al.

 

here is ugly VD for using RM3 mini

1) set Ip adress for broadlink device

2) change lines in code

 

--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==
local aesServer = "192.168.1.29"
local aesServerPort = 80
local aesServerUrl = "/crypt/aes.php" -- data mode key iv
--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==

aes.php is:

 

<?php

$iv = "562e17996d093d28ddb3ba695a2e6f58";
$key = $_GET["key"];
$mode = $_GET["mode"];
$method = 'aes-128-cbc';

$fileIn = tempnam("/tmp", "in_");
$fileOut = tempnam("/tmp", "out_");

$source = hex2bin($_GET["data"]);
file_put_contents ($fileIn, $source);

exec("openssl enc -". $method. " ". $mode . " -nopad -in $fileIn -out $fileOut -K ". $key ." -iv " . $iv);
$contents = file_get_contents ($fileOut);

$target =  bin2hex($contents);
echo($target);

unlink($fileIn);
unlink($fileOut);

?>

please do not change anuthing here if you do not know what i do.

 

3) change command

local command = "26006800C0FA1272137214711471132F1471142E1471132F132F1131132F1372142D1471123014711174142E1471117413721372132F132F132F1372132F132E142E12301471142E1471142E1471132F1372142E132F1174132F1372132F1371142F1371147114F513000D05"

 

image.png.8c727b7e4f071bb04ed7d693af6a6a86.png

 

 

 

Broadlink_RM3_Mini_241119.vfib 37.55 kB · 0 downloads

can you please describe what IP's i should fill?

 

local aesServer = "192.168.1.XX"?
local aesServerPort = 80
local aesServerUrl = "/crypt/aes.php" -- data mode key iv
--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==

local BROADLINK_AP_IP = "192.168.10.162"
local UDP_IP_PORT = 80

if require then
    require("fibaro")
end

local network = api.get("/settings/network")
local OUR_IP = network.ip

if require then
    OUR_IP = "192.168.1.XX"?

 

 

and where i can find the  line local command =?! 

 

thank u.

 

 

Link to post
Share on other sites
  • 4 months later...

Hello,
I am using home center lite at my home.
I also have broadlinkin rm pro + and rm mini3 at my house
Although I can only see the IP addresses, I cannot see the ports.
Also, when I query port 80 with the programs, it seems closed and I can't get a response.
Does anyone know what I have to do to open a port?

Link to post
Share on other sites

unfortunately HCL not suport LUA developing you can't

  • Like 1
Link to post
Share on other sites
6 hours ago, antoniopll said:

Anyone already add broadlink with HC3? 

Now I have a quiz question:

is HC3 has aes-128-cbc enc/dec on the board?

  • Like 1
Link to post
Share on other sites
2 hours ago, 10der said:

is HC3 has aes-128-cbc enc/dec on the board?

Yes, the ARM controller has hardware support for encryption but AFAIK we do not have access to (raw) functions or libraries.

 

@A.Socha any plans to add access to eg OpenSSL functions through a wrapper?

  • Like 1
Link to post
Share on other sites
  • 3 months later...

Hi again for all of you and thank you for yours support.
What would you say if I asked you about orvibo vs20rb?
Is it easy to introduce this product to Fibaro as a virtual device?

Link to post
Share on other sites
49 minutes ago, AKILLIGUVENLI said:

orvibo vs20rb

I do not know what is it :) 

  • Like 1
Link to post
Share on other sites
5 hours ago, AKILLIGUVENLI said:

What would you say if I asked you about orvibo vs20rb?
Is it easy to introduce this product to Fibaro as a virtual device?

 

orvibo has been already reversed and implemented on 3rd part hardware, however the implementation is using fake dns/paket forwarding, which in my opinion is good for "let's try if that work", but not for serious environment. Honestly, i don't like the idea of additional hardware middle of my network stream.
EDIT: some of these implementations are working only with older hardware etc., so don't waste time and look for "not working anymore" comments ...

There is however PoC of another way, written by Durand and insertjokehere (which actually act as real aws client), however it's not easy to get that working on HC3 without openssl bindings. I got MD5/HMAC/PKCS5/AES256 working as standalone version, fighting now with tls/x509, however not as real implementation but as (let's call it) emulation in raw format over sockets. Anyway, with openssl it would take maybe few hours only to get working QA ... There is additionally another "small" problem, i need first QuickApp encryption enabled, i can't post the aws private keys, it is required to encrypt them for app/3rd part use (and decrypt on the fly). So it will take some weeks/months, before i publish the QA, but definitely i will post.

 

Edited by tinman
  • Like 1
  • Thanks 1
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
Reply to this topic...

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