("Tips: Att logga sensordata", http://www.telldus.com/forum/viewtopic.php?f=23&t=1528)
Gör så här:
1) Hämta nedanstående filer och lägg dom där NexaHome är installerad (C:\apps\nexhome).
http://nexahome.se/SensorChart.class
http://nexahome.se/SensorChart.java
2) Skapa filen mypage.bsh
Code: Select all
path = "C:/apps/nexahome/";
temp = false;
params = getData("mypage.params_");
if (params != null) {
//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 {
echo("mypage.params_ == null");
}
if (temp) {
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("C:/apps/nexahome/jcommon-1.0.17.jar");
addClassPath("C:/apps/nexahome/jfreechart-1.0.14.jar");
addClassPath("C:/apps/nexahome/.");
String[] labels = { "Värmepump", "Inne", "Ute" };
SensorChart.initGraph(labels.length, 1);
SensorChart.initSeries(0, labels[0], Color.red);
SensorChart.initSeries(1, labels[1], Color.black);
SensorChart.initSeries(2, labels[2], Color.blue);
Calendar cal = Calendar.getInstance();
int back = 1;
cal.add(Calendar.DAY_OF_YEAR, -back);
for (int ndx = 0; ndx <= back; ndx++) {
StringBuffer buf = new StringBuffer();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
File f = new File(path + "temp_" + 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("\t");
}
} 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 st = new StringTokenizer(buf.toString().replaceAll("\t\t", "\t?\t"), "\t");
while (st.hasMoreTokens()) {
String timestamp = st.nextToken();
String s1 = st.nextToken().replace(',', '.');
String s2 = st.nextToken().replace(',', '.');
String s3 = st.nextToken().replace(',', '.');
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);
try {
if (!s1.equals("?")) {
double d1 = Double.parseDouble(s1);
SensorChart.addValue(0, year, month, day, hour, minute, d1);
}
if (!s2.equals("?")) {
double d2 = Double.parseDouble(s2);
SensorChart.addValue(1, year, month, day, hour, minute, d2);
}
if (!s3.equals("?")) {
double d3 = Double.parseDouble(s3);
SensorChart.addValue(2, year, month, day, hour, minute, d3);
}
} catch(NumberFormatException nfe) {
// ignore
}
}
}
}
cal.add(Calendar.DAY_OF_YEAR, 1);
}
SensorChart.process("", "Temperatur", 640, 480, "C:/apps/nexahome/mySensorChart.png");
}
String[] labels = { "Värmepump", "Inne", "Ute" };
SensorChart.initGraph(labels.length, 1);
SensorChart.initSeries(0, labels[0], Color.red);
SensorChart.initSeries(1, labels[1], Color.black);
SensorChart.initSeries(2, labels[2], Color.blue);
String s1 = st.nextToken().replace(',', '.');
String s2 = st.nextToken().replace(',', '.');
String s3 = st.nextToken().replace(',', '.');
3) Hämta zip arkiv med JFreeChart filer (jfreechart-1.0.14.zip):if (!s1.equals("?")) {
double d1 = Double.parseDouble(s1);
SensorChart.addValue(0, year, month, day, hour, minute, d1);
}
if (!s2.equals("?")) {
double d2 = Double.parseDouble(s2);
SensorChart.addValue(1, year, month, day, hour, minute, d2);
}
if (!s3.equals("?")) {
double d3 = Double.parseDouble(s3);
SensorChart.addValue(2, year, month, day, hour, minute, d3);
}
http://sourceforge.net/projects/jfreechart/files/
4) Packa upp jfreechart-1.0.14.zip och kopiera filerna jfreechart-1.0.14.jar samt jcommon-1.0.17.jar (från lib biblioteket) till c:\apps\nexahome
5) Skriv in följande på "My Web Server Directory" raden i NexaHome ("Config" fliken):
6) Skapa filen temp.html i C:\apps\nexahome\mywebserver biblioteket.C:\apps\nexahome\mywebserver
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">
</head>
<!-- dynamic="temp" url="file:///c:/apps/nexahome/mySensorChart.png" -->
<body bgcolor="#ffffff" background="/nexahome/nexahome_bg.jpg">
<div style="position: absolute; top: 5px; left: 15x">
<img src="#DYNAMIC#temp#" border="1" />
</div>
<div style="position: absolute; top: 507px; left: 25px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="temp">
<input type=hidden name="return" value="fasad">
<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: 547px; left: 25px;">
<form action="nexahome" method="get">
<input type=hidden name="mypage" value="#RETURN#">
<input type=hidden name="psw" value="#PSW#">
<input type=hidden name="rnd" value="#RND#">
<input type=submit value="Gå tillbaka">
</form>
</div>
</body>
</html>
8) Surfa in på NexaHome web servern
http://<ip adress>:<port nummer>/nexahome?mypage=temp
Edit: 2013-03-23 Bugfix... SensorChart.java, SensorChart.class
Edit: 2012-11-24 mypage.bsh uppdaterad