Commit b46a7bea authored by Jan Wagemakers's avatar Jan Wagemakers

demo mode

parent 1a09d189
export DEMO=false
gradlew clean build
scp build/libs/controlthermostatbluetooth-0.0.1-SNAPSHOT.jar 192.168.1.244://home/jan/thermostat.jar
......@@ -29,7 +29,7 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
}
compile "org.springframework.boot:spring-boot-starter-security"
// compile "org.springframework.boot:spring-boot-starter-security"
compile "org.springframework.boot:spring-boot-starter-undertow"
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
// compile("org.springframework.boot:spring-boot-starter-data-rest")
......
......@@ -15,6 +15,7 @@ import java.text.DecimalFormat;
*/
class Serial {
private final SerialPort rfcomm;
private boolean demo = false;
private DataList data = new DataList();
public Serial() {
......@@ -23,7 +24,9 @@ class Serial {
SerialPort.TIMEOUT_WRITE_BLOCKING, 2000, 0);
}
public boolean open() {
public boolean open(boolean demo) {
this.demo = demo;
if (demo) return true;
rfcomm.closePort();
data.add("---------------");
data.add("open");
......@@ -92,7 +95,15 @@ class Serial {
Float rx;
data.add("---------------");
data.add("CMD : " + tx);
if (demo) {
if (tx.length() > 3) return Float.parseFloat(tx.substring(3));
if (tx.equals("OP?")) {
return (int)(Math.random()+.5);
}
return (int)(Math.random() * 14 + 16);
}
try {
byte[] in = new byte[10];
// read to clear any data that's left on the line
......
......@@ -17,6 +17,7 @@ import java.util.Calendar;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
......@@ -38,6 +39,8 @@ public class StartupRunner implements CommandLineRunner {
private int oldMonth = -1;
private int oldDay = -1;
private int oldHour = -1;
@Value("${demo}")
private boolean demo;
@Autowired
private ConfigurationRepository configurationRepository;
......@@ -62,6 +65,7 @@ public class StartupRunner implements CommandLineRunner {
config = configurationRepository.save(config);
}
System.out.println("CONFIG : " + config.getAirport() + " " + config.getLowTemp());
if (demo) System.out.println("DEMO");
}
@Scheduled(initialDelay = 5 * 1000, fixedDelay = 15 * 60 * 1000)
......@@ -125,7 +129,7 @@ public class StartupRunner implements CommandLineRunner {
int outsidePressure = outside.getPressure();
data.add("Outside Temperature = " + outsideTemp);
data.add("Outside Atmospheric Pressure = " + outsidePressure);
if (SERIAL.open()) {
if (SERIAL.open(demo)) {
// set current outside temp / YY / MM / DD / hh / mm
if (oldOA != outsidePressure) {
if (SERIAL.setOA(outsidePressure)) oldOA = outsidePressure;
......@@ -218,6 +222,7 @@ public class StartupRunner implements CommandLineRunner {
}
if (count-- < 0) break;
data.add("OK");
if (demo) break;
}
if (count >= 0) data.add("Control SP OK");
} else {
......
......@@ -10,6 +10,8 @@ spring.datasource.password =
# Do not create database - use schema.sql
spring.jpa.hibernate.ddl-auto=none
demo = ${DEMO}
# security set user/password
#spring.security.user.name=${user}
#spring.security.user.password=${password}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment