th03lnx on Linux: Need feedback on hardware status

Having problems ? let us know the details here
Post Reply
dybdahl

th03lnx on Linux: Need feedback on hardware status

Post by dybdahl »

We will use the TH-03 to monitor temperatures in our server rooms, and for this purpose, it is extremely important to know, whether there actually is a temperature measurement going on.

As it is now, the th03lnx program only writes the temperatures to the shared memory, but it doesn't provide any information about the age of these measurements. This means, that the temperatures in the shared memory can be very old measurements, which are no longer valid.

There is a field named "active", but it seems to be stuck on 1 if you kill the th03lnx program.

I would strongly suggest to put a Linux timestamp into the shared memory every time the temperatures are updated - this would solve this problem, and should be quite easy to make.

I am more than willing to be a beta tester on this one :-)

Lars Dybdahl.

User avatar
markspencer
Site Admin
Site Admin
Posts: 598
Joined: Wed May 07, 2003 9:45 am

Post by markspencer »

Hi,

It does dound like a good idea, I will place this as a wishlist item for the next software release.

Best regards,
Regards,

Mark Spencer

dybdahl

We solved the problem

Post by dybdahl »

I solved the problem this way:

I modified the th03shm.c program, so that it:

- Takes a parameter (0, 1 or 2), that specifies what temperature we want to read
- Exits with an error code and an error message if temperature is zero.
- Otherwise, it reads the temperature and writes it to stdout
- At last it zeroes the temperature.

Our network monitoring application (http://www.sysorb.com/) then queries the temperature once each minute. This is enough to ensure that the temperature is rewritten by th03lnx before the next measurement, and if th03lnx should fail to write new temperature measurements into share memory, then sysorb will issue an alert. Works perfectly... :-)

Here is the modified source-code of th03shm.c:

Code: Select all

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "th03lnx.h"

#define FALSE           0
#define TRUE            1

int main (int argc, char * const * argv)
  {
  int           i;
  int           c;
  int           sm;
  int           found;
  int           idx;
  TH03_SHARED * sm_ptr;

  sm = shmget (TH03_DEFAULT_KEY, sizeof (TH03_SHARED), 0);
  if (sm < 0)
    {
    printf ("th03shm: Unable to find shared memory\n");
    exit (1);
    }
  sm_ptr = (TH03_SHARED *) shmat (sm, (void *) 0, 0);
  if (sm_ptr == (void *) -1)
    {
    printf ("th03shm: Unable to attach shared memory %d %X\n", sm, sm_ptr);
    exit (2);
    }

  if (!sm_ptr->active)
    {
    printf ("th03shm: Th03 not active\n");
    shmdt (sm_ptr);
    exit (3);
    }

  // Check parameters
  if (argc!=2) {
    printf ("th03shm: No parameter specified. Specify 0, 1 or 2.\n");
    shmdt (sm_ptr);
    exit (4);
  }
  if (strcmp(argv[1],"0")==0) idx=0; else
  if (strcmp(argv[1],"1")==0) idx=1; else
  if (strcmp(argv[1],"2")==0) idx=2; else {
    printf ("th03shm: Invalid parameter specified. Specify 0, 1 or 2.\n");
    shmdt (sm_ptr);
    exit (5);
  }

  // Wait until all of the temperatures goes non-zero
  if (sm_ptr->channel_values[idx]==0) {
    printf("FAILED - no measurement, yet\n");
    shmdt (sm_ptr);
    exit (6);
  } else {
    printf ("T%d=%.2f\n", idx, (float) sm_ptr->channel_values [idx] / 100);
    sm_ptr->channel_values[idx]=0;
  }

  /* Use this line to kill the th03lnx driver
  sm_ptr->active = FALSE;
   */

  shmdt (sm_ptr);

}

Guest

Make file th03shm

Post by Guest »

Dear Linux Users,

I have successfully connected a TH03 unit using the th03lnx driver and have been able to obtain the 'tracking' information together with the temperature readout. The crunch comes when I cancel the driver and try to use the make file for the next stage of the set up. When I use the make th03shm.c command i get a reply saying that the commands cannot be found for lines 1 through 16. I also get a syntax error for line 36.
Does anyone have any suggestions as to what I might be doing wrong?

Thanks.

Iain.

Post Reply