Hello again and I’m back from my trip since the beginning of February, but my new born are taking my time away and it is difficult to write on this blog, but I’ll keep it updated as much as I can.
Today I’ll discuss a little about one of controller’s software, called System Manager.
![System Manager screenshot]()
Normally, the System Manager is used inside the Composer, to get some useful info about the controller that you are working on. There you can find information like network parameters (IP address, MAC address, DNS, etc) and check the status of the running processes and also enable or disable services.
That’s it, you cannot do much more on Composer with the System Manager.
In the background, the System Manager is responsible for several tasks like managing the process, managing wireless connections, SSL certificates, updates, etc. A detailed inner investigation of System Manager deserves a new topic that I want to publish one day.
But, what if you can do more? Like for instance, reboot the system remotelly? Get the timezone information for your driver? Set time and date! Yes, all those things that I’ve just listed is possible.
Let’s start a simple example here, using a software like Hercules to create TCP connection to our controller and send commands.
Write the IP address on the IP textbox, and write 5800 as Port, click in Connect.
After the connection you should send the “help” command in order to list all the avaliable commands on SystemManager, followed by carriage return, or 0x0D0A. In the end the command should be like this “help/r/n”.
You can see all the commands listed
help Help (this command).
status Get enabled/disabled status.
quit Quit the session.
date Get/set date (MM/DD/YYYY).
time Get/set time (HH:MM:SS).
timezone Get/set timezone (zone name).
timezones Get list of timezones.
enable Enable daemon.
disable Disable daemon.
ntp NTP daemon (start|stop|restart|config_server|config_client).
ntpsync NTP Synchronize
oldupdate Update pre 1.3 release system
version Get package versions.
reboot Reboot machine.
suspend Stop daemon.
resume Start daemon.
nice Renice a daemon.
net Network configuration (see net help).
kill Kill daemon
shutdown Kill all daemons without restarting
restart Restart all enabled processes.
sysinfo Get system info (XML result).
procpoll Get process info (XML result).
syslog Configure logging.
tail Tail a file.
whoami Return IP of this connection.
cert Get certificate details.
OK
As you can see, there a lot of commands what we can use it.
Now, what about to have a driver to reboot the control4? I don’t think that this is useful on real life, but for example purposes is valid. Let’s create a driver that contains only one command, that is to reboot any control4 controller that we want.
filename: C4H_Reboot.c4i
<devicedata>
<copyright>Copyright 2013 Control4Hacks - All rights reserved.</copyright>
<name>Reboot</name>
<small>devices_sm/c4.gif</small>
<large>devices_lg/c4.gif</large>
<control>lua_gen</control>
<driver>DriverWorks</driver>
<proxy>C4H_Reboot</proxy>
<composer_categories>
<category>other</category>
</composer_categories>
<manufacturer>Control4Hacks</manufacturer>
<creator>Bruno Salvador</creator>
<created>10/29/2012 11:45 AM</created>
<modified>10/31/2012 10:00 PM</modified>
<version>100</version>
<model>Reboot 1.0</model>
<front/>
<back/>
<top/>
<bottom/>
<left/>
<right/>
<config>
<documentation>
Control4Hacks Reboot Driver 1.0
This driver allow the controller to reboot itself or another controller, by the IP Address.
This is a sample driver of the commands that you can get from the controller using this method.
</documentation><properties/>
<actions/>
<commands>
<command>
<name>REBOOT</name>
<description>Reboot Control4 Controllers</description>
<params>
<param>
<name>IP</name>
<type>STRING</type>
</param>
</params>
</command></commands>
<script><![CDATA[
function Reboot(IP)
local tcp = socket.tcp ()
tcp:connect (IP, 5800)
print('Connecting on ' .. IP)
tcp:settimeout (0.5)
print('Sending reboot command...')
tcp:send ('reboot\r\n')
tcp:close ()
return
end
function ExecuteCommand(Command, Parameters)
if (Command == 'REBOOT') then
Reboot(Parameters['IP'])
end
end
]]></script></config><states/><connections/><capabilities/></devicedata>
On the programming tab, make any event to execute the command according to the picture below, IP textbox is the controller that you want to reboot. The IP 127.0.0.1 means that the program will reboot the controller where the driver is installed (current Composer controller connection). Replace this with the IP of the controller that you want.
!! BE CAREFUL !! Don’t do the same mistake as I did. I’ve programmed to reboot every time that the controller boot, so the controller got stuck on an infinite loop of restart. To solve this I had to connect with Hercules and suspend the director service, then manually remove the driver.
![reboot_prog]()
You can also read useful info to use it on your driver with the sample bellow, which reads the network information of the controller.
local tcp = socket.tcp ()
tcp:connect ('127.0.0.1', 5800)
tcp:settimeout (0.5)
tcp:send ('net iface eth0 real\r\n')
local text = ''
repeat
local data = tcp:receive ()
text = text .. (value or '') .. '\r\n'
until (value == nil)
Then you can work with the data to do what you want.
I was wondering…this connection don’t ask for password and there is no security check to access this commands. This is critical because any piece of software with 3 lines of LUA can create problems for the users. Imagine write a software to randomly reboot the controllers on the network. What if a house with security door locks that are programmed to unlock at 08:00 am, and you change the time in order to unlock at 04:00am? Paranoic? Maybe…
See you soon!