View Single Post
Old 12-11-10, 04:04 AM   #17
strider3700
Master EcoRenovator
 
Join Date: Dec 2008
Location: Vancouver Island BC
Posts: 745
Thanks: 23
Thanked 37 Times in 30 Posts
Default

Ok I spent some time wiring up a second temp sensor and installing it in my rec room which has the woodstove. It was an easy/quiet wiring job to do in the middle of the night and it should be interesting to see how the temps work out in my office vs in there.

Then I decided to get down to work on the java side to get logging that in a nice easy to use method. I don't want to datalog every second or two's data but I don't want the inaccuracy associated with only collecting data every 1,2,5... whatever minutes. So I figured I'll collect data every second and average it for whatever time period becomes useful in the future.

So I decided first of all I need a new java class to create a sensor object for each sensor. it gives me the basics, set the name, id, get the name, id. also it has a Value stored in it. I can reset that, and add to it. each time I add to it I add one to the count and when I ask for the average I just take the value/count and return that. Pretty simple.
Code:
package datalogger;

public class Sensor {
	
	private String sensorID;
    private String sensorName;
    private float value;
    private int averageCount;
    
    Sensor(String inID,String inName)
    {
     sensorID = inID;
     sensorName = inName;
     value =0;
     averageCount = 0;
    }
    
    public String getID(){
    	return sensorID;
    }
    public String getID(String inName){
    	return sensorID;
    }
    
    public String getName(){
    	return sensorName;
    }
    
    public String getName(String inID){
    	return sensorName;
    }
        
    public void setName(String inName)
    {
    	sensorName = inName;
    }
    
    public void setID(String inID){
    	sensorID = inID;
    }
    public void resetValue()
    {
    	value =0;
    	averageCount =0;
    }
    
    public void addValueToAverage(float inValue)
    {
     value += inValue;
     averageCount++;
    }
    
    public String returnAverage()
    {
      float average = value/averageCount;
      return (String.valueOf(average));
    }       
    
}
The other class got some more functions calling and using the sensor class but nothing special. I'm thinking I should really create a new class to handle the data manipulation that will just call the serialtest and let it handle getting the data from the serial port then hand it over to this other class to deal with. I won't be working on this much if at all tomorrow though. I also somewhere need to add a timer that when the timer goes off will walk through the list of sensors and get their averages then output them to the CSV as 1 line to make for easy comparison graphs.

I was also thinking that long term I should make the program look at a simple configuration file to get the sensor ID's and names to make it easier for non programmers to use. As if I don't have enough to do...
strider3700 is offline