Is there a way to check if my windows 10 media computer is on or off. i would like to create a polling function to see if the computer is on or off and report back status.
parsing a reply to an ICMP command would normally be the way to do it, but I donât know if thatâs possible with THR. There is a way to send magic packets to WOL, but thatâs not what you want.
What Iâd probably do is write a simple python script that opens up a socket, you could use THR to get the status that way (if it responds with the expected âackâ whatever that may be, itâs on. Otherwise, itâs off.
Even easier (but more overhead)âŚinstall a HTTP server and just serve up a page. Depending on your capabilities, you could report on the status of individual services too. There might be already a 3rd party tool that allows web monitoring of windows servicesâŚmight be worth googling,
I used a ping sensor on my Vera Hub that tied into HR. It would ping once a minute and if ping was successful PC was on, and a ping failure triggered an off condition.
Thank you for the suggestion. I created a simple python server scrip that send back and ack when pinged.
I created a plugin. everything works when the computer is on. However if the computer is off I do not get a status. It seems like the HRP gets stuck since it is not receving anything. Can you please take a look at my code. i am attaching the code and HRP file.
plugin.Name = âPingâ;
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval =10000;
var socket = new TCPClient();
function onChangeRequest() {
}
function onConnect() {
var port=9999;
var host = â192.168.1.60â
socket.connect(host, parseInt(port));
}
function onDisconnect() {
socket.close();
}
function onPoll() {
computerStatus();
}
function onSynchronizeDevices() {
var device = new Device();
device.Id = plugin.Name;
device.DisplayName = âPingâ
device.Icon = âComputerâ;
device.Capabilities = [âSwitchâ];
device.Attributes = [ âSignalâ];
plugin.Devices[plugin.Name] = device;
}
function computerStatus() {
var device = plugin.Devices[plugin.name];
socket.send(âHelloâ);
sleep(250);
if(device) {
var response = ââ;
var Signal = ââ;
var response = socket.receive();
switch(response) {
case "ACK!": //Sending Signal
powerState = "Computer On";
break;
case null: //Not Sending Signal
case "":
powerState = "Computr Off";
break;
default:
//this case should never happen
powerState = "Error";
break;
}
device["Signal"] = powerState;
}
}
Ping.hrp (9.2 KB)
Nice workâŚI took some liberties to bring it across the finish line.
âOnâ will be registered with a response (any response) from the server. âOffâ will be registered if a connection cannot be established at all.
There might be some redundant code, but it works
Ping-revised.hrp (9.2 KB)
Still canât get the status of âComputer Offâ. Works beautifully when the computer is On.
OddâŚworks for me.
I used the Hercules Setup Utility [1] to simulate a TCP server. When the util was started and sent a response back, Computer OK would appear. As soon as I shutdown the server, Computer Off was returned.
I can record and share a video if necessary.
I just ran the HRP file you posted. Did not change a thing, not even ip or port. Ideally the status would be computer off since you are trying to connect to a random port. However the status is blank
Donât know what to say. Runs perfectly in the designer for me.
I noticed in the script above, powerstate is âcomputr offâ. Is that a typo (no e)? Are you expecting âcomputer offâ?
It must be a user error on my part. I am pretty new to this stuff. I was able to fix everything using Multidatatrigger. Thank you again for your support. And More importantly thank you for the JVC plugin, it is amazing.
My pleasure. I find this to be a fun diversion from life :).