marieper wrote:Med en tilläggsfråga, hur mycket behöver anpassas för två motorvärmare?
Räcker det med att ha två instanser av car.html resp car.bsh som adresserar respektive car_check_device och car_heater_device?
mypage.bsh verkar också behöva en anpassning, men räcker det med att kopiera "exempelkoden" och lägga in car_check_device för den andra värmaren, samt uppdatera koden
if (param.equals("mypage=car"))
med namnet på den andra värmarens fil?
2013-09-24: Notering -
http://192.168.18.120:8080/nexahome?mypage=car_hb leder till samma sida som
http://192.168.18.120:8080/nexahome?mypage=car_vf, det verkar vara helt egalt vad jag ger för parameter efter mypage=, allt leder precis samma sida...
Ändra värdet på
car_check_device,
car2_check_device samt
car2_heater_device så att dom överensstämmer med dina egna device.
/home/pi/nexahome/mypage.bsh
Code: Select all
car_check_device = "5";
car2_check_device = "52";
car = false;
car2 = false;
car_on = null;
car_minutes = null;
path = "/home/pi/nexahome/";
temp = false;
temp2 = false;
params = getData("mypage.params_");
//echo(params);
var len = Integer.parseInt(params);
for (int ndx = 1; ndx <= len; ndx++) {
param = getData("mypage.param" + ndx + "_");
// echo(param);
if (param.equals("mypage=temp")) {
temp = true;
} else if (param.equals("mypage=temp2")) {
temp2 = true;
} else if (param.equals("mypage=car")) {
car = true;
} else if (param.equals("mypage=car2")) {
car2 = true;
} else if (param.startsWith("on=")) {
car_on = param.substring("on=".length());
} else if (param.startsWith("minutes=")) {
car_minutes = param.substring("minutes=".length());
}
}
if (car && car_on != null) {
setData("car_on", car_on);
setData("car_minutes", (car_minutes != null ? car_minutes : ""));
deviceOn(car_check_device);
}
if (car2 && car_on != null) {
setData("car2_on", car_on);
setData("car2_minutes", (car_minutes != null ? car_minutes : ""));
deviceOn(car2_check_device);
}
if (temp || temp2) {
import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;
addClassPath(path + "jcommon-1.0.17.jar");
addClassPath(path + "jfreechart-1.0.14.jar");
addClassPath(path + ".");
String[] temp_labels = { "In", "Out" };
String[] temp_colors = { "black", "blue" };
String[] temp2_labels = { "Sensor1", "Sensor2", "Sensor3" };
String[] temp2_colors = { "black", "blue", "yellow" };
int length = 640;
int height = 480;
String title = null;
String output= null;
String[] labels = null;
String[] colors = null;
special_name = null;
if (temp) {
title = "Temperature";
labels = temp_labels;
colors = temp_colors;
special_name = "temp";
} else if (temp2) {
title = "Temperature 2";
labels = temp2_labels;
colors = temp2_colors;
special_name = "temp2";
}
output = path + "mySensorChart_" + special_name + ".png";
SensorChart.initGraph(labels.length, 1);
for (int gNdx = 0; gNdx < labels.length; gNdx++) {
txt = colors[gNdx].toLowerCase();
if ("white".equals(txt)) {
color = Color.white;
} else if ("lightgray".equals(txt)) {
color = Color.lightGray;
} else if ("gray".equals(txt)) {
color = Color.gray;
} else if ("darkgray".equals(txt)) {
color = Color.darkGray;
} else if ("black".equals(txt)) {
color = Color.black;
} else if ("red".equals(txt)) {
color = Color.red;
} else if ("pink".equals(txt)) {
color = Color.pink;
} else if ("orange".equals(txt)) {
color = Color.orange;
} else if ("yellow".equals(txt)) {
color = Color.yellow;
} else if ("green".equals(txt)) {
color = Color.green;
} else if ("magenta".equals(txt)) {
color = Color.magenta;
} else if ("cyan".equals(txt)) {
color = Color.cyan;
} else{
color = Color.blue;
}
SensorChart.initSeries(gNdx, labels[gNdx], color);
}
Calendar cal = Calendar.getInstance();
int back = 1;
cal.add(Calendar.DAY_OF_YEAR, -back);
for (int dNdx = 0; dNdx <= back; dNdx++) {
StringBuffer buf = new StringBuffer();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
File f = new File(path + special_name + "_" + sdf.format(cal.getTime()) + ".txt");
if (f.exists()) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(f));
String line = null;
do {
line = br.readLine();
if (line != null) {
buf.append(line);
buf.append("\n");
}
} while(line != null);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
StringTokenizer st1 = new StringTokenizer(buf.toString(), "\n");
while (st1.hasMoreTokens()) {
StringTokenizer st2 = new StringTokenizer(st1.nextToken().replaceAll("\t\t", "\t?\t"), "\t");
if (st2.hasMoreTokens()) {
String timestamp = st2.nextToken();
Date date = sdf.parse(timestamp, new ParsePosition(0));
if (date != null) {
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int gNdx = 0;
while (st2.hasMoreTokens() && gNdx < labels.length) {
String value = st2.nextToken().replace(',', '.');
if (!value.equals("?")) {
try {
double d = Double.parseDouble(value);
SensorChart.addValue(gNdx, year, month, day, hour, minute, d);
dataAdded = true;
} catch(NumberFormatException nfe) {
// ignore
}
}
gNdx = gNdx + 1;
}
}
}
}
}
cal.add(Calendar.DAY_OF_YEAR, 1);
}
if (dataAdded) {
SensorChart.process("", title, length, height, output);
} else {
echo("No data added to graph!");
}
}
/home/pi/nexahome/car2.bsh
Code: Select all
car2_check_device = "52";
car2_heater_device = "42";
timer = "car2";
if (deviceIsOn(car2_check_device)) {
car_power_on = getData("car2_power_on");
car_power_off = getData("car2_power_off");
if (car_power_on != null && car_power_on.length() != 0
&& car_power_off != null && car_power_off.length() != 0) {
long power_on = Long.parseLong(car_power_on);
long power_off = Long.parseLong(car_power_off);
Calendar cal = Calendar.getInstance();
long now = cal.getTime().getTime();
if (now >= power_on && deviceIsOff(car2_heater_device)) {
deviceOn(car2_heater_device);
setData("#DATA#car2_text#", "(" + Math.round((power_off - now) / 60000) + ")");
startTimer(timer, 60);
} else if (now >= power_off && deviceIsOn(car2_heater_device)) {
deviceOff(car2_check_device);
} else if (deviceIsOn(car2_heater_device)) {
long left = Math.round((power_on - now) / 60000);
long right = Math.round((power_off - now) / 60000) + 1;
setData("#DATA#car2_text#", "(" + left + "/" + right + ")");
startTimer(timer, 60);
hideOutput();
} else {
startTimer(timer, 60);
hideOutput();
}
}
}
/home/pi/nexahome/mywebserver/car2.html
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>NexaHome - Life Made Easy With Home Automation</title>
<link rel="Shortcut Icon" href="http://nexahome.se/favicon32x32.ico">
<meta http-equiv="refresh" content="60;#URL#?mypage=car2&psw=#PSW#">
</head>
<!-- device="Engine pre-heater" on="car_on.png" off="car_off.png" onoff="car_onoff.png" -->
<!-- device="Engine pre-heater (timer)" on="time_glass_arrow_on.png" off="time_glass_arrow_off.png" onoff="time_glass_arrow_onoff.png" -->
<!-- dynamic="car_heater_log" url="file:////home/pi/nexahome/mywebserver/car2_heater.log" keep="15" -->
<!-- Images found at the following sites: -->
<!-- http://toons.artie.com/kennedy/arg-graphic-car-go-url.gif -->
<!-- http://www.iconfinder.com/search/?q=hourglass -->
<!-- http://momentumdesignlab.com/resources/downloads/ -->
<body bgcolor="#ffffff" background="/nexahome/nexahome_bg.jpg">
<div style="position: absolute; top: 13px; left: 11px">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="car2">
<input type=hidden name="device" value="Engine pre-heater">
<input type=hidden name="cmd" value="#CMD#Engine pre-heater#">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=image title="Engine pre-heater" alt="?" src="#IMAGE#Engine pre-heater#">
</form>
</div>
<div style="position: absolute; top: 210px; left: 20px;">
<form action="nexahome" method="get">
<select name="on">
<option value="" selected></option>
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="02:30">02:30</option>
<option value="03:00">03:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
<select name="minutes">
<option value="60" selected>60</option>
<option value="90">90</option>
<option value="120">120</option>
<option value="150">150</option>
<option value="180">180</option>
</select>
<input type=hidden name="mypage" value="car2">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=submit value="START">
</form>
</div>
<div style="position: absolute; top: 162px; left: 20px">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="car2">
<input type=hidden name="device" value="Engine pre-heater (timer)">
<input type=hidden name="cmd" value="#CMD#Engine pre-heater (timer)#">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=image title="Engine pre-heater (timer)" alt= "?" src="#IMAGE#Engine pre-heater (timer)#">
</form>
</div>
<div style="position: absolute; top: 170px; left: 60px">
#DATA#car2_text#
</div>
<div style="position: absolute; top: 170px; left: 155px">
Out: #SENSOR_VALUE#Temp Out# °C
</div>
<div style="position: absolute; top: 250px; left: 20px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="car2">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=hidden name="on" value="+01:00">
<input type=hidden name="minutes" value="60">
<input type=submit value="Start in 1 h">
</form>
</div>
<div style="position: absolute; top: 250px; left: 140px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="car2">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=hidden name="on" value="+02:00">
<input type=hidden name="minutes" value="60">
<input type=submit value="2 h">
</form>
</div>
<div style="position: absolute; top: 250px; left: 190px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="car2">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=hidden name="on" value="+03:00">
<input type=hidden name="minutes" value="60">
<input type=submit value="3 h">
</form>
</div>
<div style="position: absolute; top: 290px; left: 20px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="car2">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=submit value="#TIMESTAMP#">
</form>
</div>
<div style="position: absolute; top: 330px; left: 20px;">
<table border="1">
<tr><th>Log</th></tr>#DYNAMIC#car2_heater_log#
</table>
</div>
</body>
</html>
/home/pi/nexahome/mywebserver/car2_heater.log
Code: Select all
<tr><td>2013-10-07 17:40 :OFF:</tr></td>