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
roberto1965 5
Good morning,
I'm switching from HC2 to HC3, I have this VD on HC2 to turn on my QNAP NAS, I would like to transfer it to HC3, what should I do? sorry but
Everything seems different to me, I attach the program
Please login or register to see this image.
/monthly_2024_03/image.png.d9f2e3b6adedb87e3095045098a3016e.png" />Accendi:
--[[
%% properties
%% globals
--]]
-- Wake On Lan v 1.0.0 [02-2013]
-- Copyright © 2013 Jean-christophe Vermandé
-- convert MAC adress, every 2 Chars (7-bit ASCII), to one Byte Char (8-bits)
function convertMacAddress(address)
local s = string.gsub(address, ":", "");
local x = ""; -- will contain converted MAC
for i=1, 12, 2 do
x = x .. string.char(tonumber(string.sub(s, i, i+1), 16));
end
return x;
end
fibaro:log("Start process");
local _selfId = fibaro:getSelfId();
-- MAC adress
local _macAddress = convertMacAddress("00:08:9b:cd:66:d4");
-- Create Magic Packet 6 x FF
local _magicPacket = string.char(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
-- Broadcast Address
local _broadcastAddress = "255.255.255.255";
-- Default port used
local _wakeOnLanPort = 9;
fibaro:sleep(750);
for i = 1, 16 do
_magicPacket = _magicPacket .. _macAddress;
end
fibaro:log("Magic packet successfully created");
fibaro:sleep(1000);
socket = Net.FUdpSocket();
socket:setBroadcast(true);
local bytes, errorCode = socket:write(_magicPacket, _broadcastAddress, _wakeOnLanPort);
--check for error
if errorCode == 0 then
fibaro:log("Successfully sent");
else
fibaro:log("Transfer failed");
end
-- clean up memory
socket = nil;
fibaro:sleep(1000);
fibaro:log("Please wait for the server startup.");
Spegni:
if (not QNAP) then
QNAP = {}
QNAP.qnap_ip = fibaro:get(fibaro:getSelfId(), "IPAddress");
QNAP.port = fibaro:get(fibaro:getSelfId(), "TCPPort");
QNAP.globalvariable = ""
-- --------------------------------------------------------------------------------------------------------------
-- Obtient le XML et le retourne sous forme de table LUA
-- --------------------------------------------------------------------------------------------------------------
QNAP.getTokenFromXml = function()
local QNAP2URL = Net.FHttp(QNAP.qnap_ip,QNAP.port);
response = QNAP2URL:GET("/cgi-bin/authLogin.cgi?user=admin&plain_pwd=17Pa$$wOrd&remme=1");
xmlTable = QNAP.iif(response ~= nil, QNAP.newParser().ParseXmlText(response), "");
if (xmlTable.QDocRoot ~= nil) then
qsidstr = xmlTable.QDocRoot.authSid:value();
if (string.len(qsidstr)>0) then
fibaro:debug("Qtoken founded");
qsidstr = qsidstr:gsub("[".."<![CDATA[".."]", '');
qsidstr = qsidstr:gsub("[".."]".."]", '');
qsidstr = qsidstr:gsub("["..">".."]", '');
fibaro:debug(qsidstr);
response = QNAP2URL:GET("/cgi-bin/sys/sysRequest.cgi?subfunc=power_mgmt&count=0.1234&sid="..qsidstr.."&apply=shutdown");
if (string.find(response, "OK")) then
fibaro:log("Power Off Server")
else
fibaro:log("ERROR")
end
end
end
end
-- -------------------------------------------------------------------------------------------------------------
-- Teste la condition et retourne la valeur true ou false
-- -------------------------------------------------------------------------------------------------------------
QNAP.iif = function(condition, iftrue, iffalse)
if (condition) then
return iftrue
end
return iffalse
end
-- -------------------------------------------------------------------------------------------------------------
-- Ceci est une version modifiée par Steven de Corona-XML-Module par Jonathan Beebe qui a son tour
-- est basée sur Alexander Makeev's Lua-only XML parser .
-- see https://github.com/Cluain/Lua-Simple-XML-Parser
-- -------------------------------------------------------------------------------------------------------------
QNAP.newParser = function()
parseXml = {}
parseXml.FromXmlString = function(value)
value = string.gsub(value, "([%x]+)%;",
function(h)
return string.char(tonumber(h, 16))
end);
value = string.gsub(value, "([0-9]+)%;",
function(h)
return string.char(tonumber(h, 10))
end);
value = string.gsub(value, "'", "'");
value = string.gsub(value, ">", ">");
value = string.gsub(value, "<", "<");
value = string.gsub(value, "&", "&");
return value;
end
parseXml.ParseArgs = function(node, s)
string.gsub(s, "(%w+)=([\"'])(.-)%2", function(w, _, a)
node:addProperty(w, parseXml.FromXmlString(a))
end)
end
parseXml.ParseXmlText = function(xmlText)
local stack = {}
local top = parseXml.newNode()
table.insert(stack, top)
local ni, c, label, xarg, empty
local i, j = 1, 1
while true do
ni, j, c, label, xarg, empty = string.find(xmlText, "<(%/?)([%w_:]+)(.-)(%/?)>", i)
if not ni then break end
local text = string.sub(xmlText, i, ni - 1);
if not string.find(text, "^%s*$") then
local lVal = (top:value() or "") .. parseXml.FromXmlString(text)
stack[#stack]:setValue(lVal)
end
if empty == "/" then -- empty element tag
local lNode = parseXml.newNode(label)
parseXml.ParseArgs(lNode, xarg)
top:addChild(lNode)
elseif c == "" then -- start tag
local lNode = parseXml.newNode(label)
parseXml.ParseArgs(lNode, xarg)
table.insert(stack, lNode)
top = lNode
else -- end tag
local toclose = table.remove(stack) -- remove top
top = stack[#stack]
if #stack < 1 then
error("XmlParser: nothing to close with " .. label)
end
if toclose:name() ~= label then
error("XmlParser: trying to close " .. toclose.name .. " with " .. label)
end
top:addChild(toclose)
end
i = j + 1
end
local text = string.sub(xmlText, i);
if #stack > 1 then
error("XmlParser: unclosed " .. stack[#stack]:name())
end
return top
end
parseXml.newNode = function(name)
local node = {}
node.___value = nil
node.___name = name
node.___children = {}
node.___props = {}
function node:value() return self.___value end
function node:setValue(val) self.___value = val end
function node:name() return self.___name end
function node:setName(name) self.___name = name end
function node:children() return self.___children end
function node:numChildren() return #self.___children end
function node:addChild(child)
if self[child:name()] ~= nil then
if type(self[child:name()].name) == "function" then
local tempTable = {}
table.insert(tempTable, self[child:name()])
self[child:name()] = tempTable
end
table.insert(self[child:name()], child)
else
self[child:name()] = child
end
table.insert(self.___children, child)
end
function node:properties() return self.___props end
function node:numProperties() return #self.___props end
function node:addProperty(name, value)
local lName = "@" .. name
if self[lName] ~= nil then
if type(self[lName]) == "string" then
local tempTable = {}
table.insert(tempTable, self[lName])
self[lName] = tempTable
end
table.insert(self[lName], value)
else
self[lName] = value
end
table.insert(self.___props, { name = name, value = self[name] })
end
return node
end
return parseXml;
end
end
QNAP.getTokenFromXml();
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.