Implemented reporting and storing of raw data
Former-commit-id: db8352f02b4a703698c69618a8af6036d78f5b1d
This commit is contained in:
parent
2c59ae5693
commit
d117e344c2
25 changed files with 271 additions and 141 deletions
|
|
@ -27,7 +27,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
System.out.println("Up and Running");
|
||||
while(true) {
|
||||
Thread.sleep(2000);
|
||||
nexa.setEnable(true);
|
||||
nexa.turnOn();
|
||||
nexa.setUnit(0);
|
||||
comm.write(nexa);
|
||||
Thread.sleep(2000);
|
||||
|
|
@ -36,7 +36,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
Thread.sleep(2000);
|
||||
|
||||
|
||||
nexa.setEnable(false);
|
||||
nexa.turnOff();
|
||||
nexa.setUnit(0);
|
||||
comm.write(nexa);
|
||||
Thread.sleep(2000);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
package se.koc.hal.plugin.tellstick;
|
||||
|
||||
import se.koc.hal.intf.HalSensor;
|
||||
import se.koc.hal.intf.HalSensorController;
|
||||
import se.koc.hal.intf.HalSensorReportListener;
|
||||
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -25,17 +29,18 @@ public class TelstickSerialCommTest {
|
|||
|
||||
logger.info("Setting up Tellstick listeners...");
|
||||
TellstickSerialComm comm = new TellstickSerialComm();
|
||||
comm.setListener(new TellstickChangeListener() {
|
||||
comm.setListener(new HalSensorReportListener() {
|
||||
@Override
|
||||
public void stateChange(TellstickProtocol protocol) {
|
||||
if(protocol instanceof Oregon0x1A2D){
|
||||
logger.info("Power used: "+ ((Oregon0x1A2D)protocol).getTemperature() +" pulses");
|
||||
public void reportReceived(HalSensor s) {
|
||||
if(s instanceof Oregon0x1A2D){
|
||||
logger.info("Power used: "+ ((Oregon0x1A2D)s).getTemperature() +" pulses");
|
||||
try {
|
||||
db.exec("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES("+
|
||||
System.currentTimeMillis() + "," +
|
||||
"1," +
|
||||
(int)((Oregon0x1A2D)protocol).getTemperature()
|
||||
+")");
|
||||
PreparedStatement stmt =
|
||||
db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, event_id, data) VALUES(?, ?, ?)");
|
||||
stmt.setLong(1, s.getTimestamp());
|
||||
stmt.setLong(2, 1);
|
||||
stmt.setDouble(3, ((Oregon0x1A2D)s).getTemperature());
|
||||
db.exec(stmt);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class NexaSelfLearningTest {
|
|||
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||
nexa.setHouse(11772006);
|
||||
nexa.setUnit(3);
|
||||
nexa.setEnable(true);
|
||||
nexa.turnOn();
|
||||
|
||||
assertArrayEquals(
|
||||
new char[]{
|
||||
|
|
@ -53,7 +53,7 @@ public class NexaSelfLearningTest {
|
|||
|
||||
assertEquals("House Code", 11772006, nexa.getHouse());
|
||||
assertEquals("Unit Code", 1, nexa.getUnit());
|
||||
assertTrue("Enabled", nexa.isEnabled());
|
||||
assertTrue("Enabled", nexa.isOn());
|
||||
}
|
||||
@org.junit.Test
|
||||
public void decode_OFF() throws Exception {
|
||||
|
|
@ -62,6 +62,6 @@ public class NexaSelfLearningTest {
|
|||
|
||||
assertEquals("House Code", 11772006, nexa.getHouse());
|
||||
assertEquals("Unit Code", 1, nexa.getUnit());
|
||||
assertFalse("Enabled", nexa.isEnabled());
|
||||
assertFalse("Enabled", nexa.isOn());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue