Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Issue #10 - Extracted update interval
Browse files Browse the repository at this point in the history
now there is a tp_ohm.cfg file with update Interval
also updated README with how to update it
  • Loading branch information
spdermn02 committed May 13, 2020
1 parent afdddc4 commit bbf0344
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ TouchPortal Plugin to Utilize Statistics from Open Hardware Monitor - for Window
- [Prerequisites](#prerequisites)
- [Installing](#installing)
- [Updating](#updating)
- [Configuration](#configuration)
- [**+NEW for v3+**](#new-for-v3)
- [Troubleshooting](#troubleshooting)
- [Notes](#notes)
- [Built With](#built-with)
Expand Down Expand Up @@ -271,6 +273,21 @@ When an update is put out, please follow these instructions to install

**Step 4** to to Step 3 of the install guide and load the plugin

## Configuration
#### **+NEW for v3+**
Currently only 1 configuration parameter is setup and that is update interval from the tp_ohm.exe back to Touch Portal. The config file is in the plugins\OpenHardwareMonitor folder and it is called tp_ohm.cfg. It is a JSON formatted file, and the only configuration item is `updateInterval`. The file looks like below, and the value is in milliseconds. So by default, the update Interval is every 2000 milliseconds, or 2 seconds.

```json
{
"updateInterval": "2000"
}
```
To edit the file just open in notepad or your favorite text editor and modify the number only. If you break the formatting it will kill the program. This has been tested with as fast as 500 ms but I do not recommend that as it consumes CPU and there really is no need to update THAT fast.

Once you are done editing save the file, and then close and reopen Touch Portal, as tp_ohm.exe does not re-read this file every execution cycle (*because that would be silly... or would it.. maybe another time*)

__*NOTE: Changing this is at your own risk. Your computer may not handle this as well as others, and it may cause higher than normal CPU usage if you are trying to update faster than every 2000 milliseconds.*__

## Troubleshooting

Touch Portal will log that it attempted to load the plugin in it's log file
Expand All @@ -290,7 +307,7 @@ and a little lower you should see something like this:
00:48:08 - [LOG] (Plugin System) Executing plugin service: "C:\Users\<USERNAME>\AppData\Roaming\TouchPortal\plugins\OpenHardwareMonitor\tp_ohm.exe"
```

There is also a logfile under the OpenHardwareMonitor plugin folder, %APPDATA%\TouchPortal\plugins\OpenHardwareMonitor\tpohm.log
There is also a logfile under the OpenHardwareMonitor plugin folder, %APPDATA%\TouchPortal\plugins\OpenHardwareMonitor\tp_ohm.log

```
[START] tp_ohm is starting up, and about to connect
Expand Down
Binary file modified installer/OpenHardwareMonitor.tpp
Binary file not shown.
2 changes: 1 addition & 1 deletion src/OpenHardwareMonitor/entry.tp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": 1,
"version": 2,
"version": 3,
"name": "Touch Portal Open Hardware Monitor Interface",
"id": "TPOpenHardwareMonitor",
"plugin_start_cmd": "\"%TP_PLUGIN_FOLDER%OpenHardwareMonitor\\tp_ohm.exe\"",
Expand Down
3 changes: 3 additions & 0 deletions src/OpenHardwareMonitor/tp_ohm.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"updateInterval": "2000"
}
Binary file modified src/OpenHardwareMonitor/tp_ohm.exe
Binary file not shown.
32 changes: 27 additions & 5 deletions src/perl/tp_ohm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use JSON;
use Cwd qw(abs_path);
use File::Basename qw(dirname);
use Time::HiRes qw( usleep );

# Auto appends /n on the end of message, alternate to print "msg \n";
use feature 'say';
Expand All @@ -17,15 +18,18 @@
our $dir = dirname( abs_path($0) );

our $debugLog = undef;
open $debugLog, '>', $dir . '\tpohm.log';

open $debugLog, '>', $dir . '\tp_ohm.log';
select $debugLog;
## Auto flush prints
$| = 1;

use constant {
SEC_OF_DAY => 60 * 60 * 24,

DEFAULT_INTERVAL => 2000, #Default of 2000 ms for loop interval

MILLI_to_MICRO => 1000,

ID => 'TPOpenHardwareMonitor',
HOST => 'localhost',
};
Expand All @@ -34,9 +38,27 @@
use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

our $configFile = $dir . '\tp_ohm.cfg';
our $cfg = {};
if ( open( my $jcfg, '<', $configFile ) ) {
my $json = '';
while(<$jcfg>) { $json .= $_; };
close $jcfg;
chomp $json;
eval { $cfg = decode_json($json); } or do {
logIt( 'FATAL', "Unable to parse json data from $configFile rc=" . $@ );
exit 9;
};
}
else {
logIt( 'ERROR', "unable to read $configFile will use defaults" );
}

our ( $socket, $WMI );
our $waitTime =
10; #default wait 10 seconds per sensor read and update - 2.1 release issue
our $updateInterval = $cfg->{updateInterval} // DEFAULT_INTERVAL;

#convert for use in usleep of microseconds
$updateInterval = $updateInterval * MILLI_to_MICRO;
our %sensor_config = load_sensor_config();
our $time = time;

Expand Down Expand Up @@ -77,7 +99,7 @@ sub main {
last;
}

sleep $waitTime;
usleep $updateInterval;
}

# If we get here and we are still connected,
Expand Down

0 comments on commit bbf0344

Please sign in to comment.