Sven Velt 12 years ago
parent
commit
c865faab98
4 changed files with 37 additions and 2 deletions
  1. 1 1
      Makefile
  2. 3 0
      TODO
  3. 32 0
      arexxd.c
  4. 1 1
      web/index.cgi

+ 1 - 1
Makefile

@@ -1,4 +1,4 @@
-VERSION=1.4
+VERSION=1.5
 ARCHIVE=arexxd-$(VERSION).tar.gz
 ARCHIVE=arexxd-$(VERSION).tar.gz
 
 
 CC=gcc
 CC=gcc

+ 3 - 0
TODO

@@ -1 +1,4 @@
 - Multiple receivers?
 - Multiple receivers?
+- Configuration files
+- CSV output
+- Rotation of debug logs

+ 32 - 0
arexxd.c

@@ -21,6 +21,20 @@
 
 
 #define DEFAULT_LOG_DIR "/var/log/arexxd"
 #define DEFAULT_LOG_DIR "/var/log/arexxd"
 
 
+/*
+ *  Data points received from the logger are sometimes corrupted by noise.
+ *  This effects not only the measured values, but also sensor IDs and timestamps.
+ *  Since rrdtool cannot skip back in time, a random timestamp in the future can
+ *  cause all further measurements to be dropped. To minimize impact of these
+ *  problems, we drop data points which are too far in the past or in the future.
+ *
+ *  Furthermore, you can ignore data from unrecognized sensors, i.e., those
+ *  which are not handled by correct_point().
+ */
+#define MAX_PAST_TIME 30*86400
+#define MAX_FUTURE_TIME 300
+#undef IGNORE_UNKNOWN_SENSORS
+
 typedef unsigned char byte;
 typedef unsigned char byte;
 static libusb_context *usb_ctxt;
 static libusb_context *usb_ctxt;
 static libusb_device_handle *devh;
 static libusb_device_handle *devh;
@@ -161,6 +175,7 @@ static void rrd_point(time_t t, const char *name, double val, char *unit)
 #define TIME_OFFSET 946681200		// Timestamp of 2000-01-01 00:00:00
 #define TIME_OFFSET 946681200		// Timestamp of 2000-01-01 00:00:00
 
 
 static int data_point_counter;		// Since last log message
 static int data_point_counter;		// Since last log message
+static time_t packet_rx_time;
 
 
 static double correct_point(int id, double val, const char **name)
 static double correct_point(int id, double val, const char **name)
 {
 {
@@ -185,6 +200,9 @@ static double correct_point(int id, double val, const char **name)
 			*name = "outside";
 			*name = "outside";
 			return val + 0.44;
 			return val + 0.44;
 		default:
 		default:
+#ifdef IGNORE_UNKNOWN_SENSORS
+			*name = NULL;
+#endif
 			return val;
 			return val;
 	}
 	}
 }
 }
@@ -205,6 +223,19 @@ static void cooked_point(time_t t, int id, double val, char *unit, int q)
 		printf("== %s id=%d name=%s val=%.3f val2=%.3f unit=%s q=%d\n", tbuf, id, name, val, val2, unit, q);
 		printf("== %s id=%d name=%s val=%.3f val2=%.3f unit=%s q=%d\n", tbuf, id, name, val, val2, unit, q);
 	}
 	}
 
 
+	if (!name) {
+		log_error("Ignored data from unknown sensor %d", id);
+		return;
+	}
+	if (t < packet_rx_time - MAX_PAST_TIME) {
+		log_error("Data point from sensor %d too far in the past (%d sec)", packet_rx_time - t);
+		return;
+	}
+	if (t > packet_rx_time + MAX_FUTURE_TIME) {
+		log_error("Data point from sensor %d too far in the future (%d sec)", t - packet_rx_time);
+		return;
+	}
+
 	data_point_counter++;
 	data_point_counter++;
 	rrd_point(t, name, val2, unit);
 	rrd_point(t, name, val2, unit);
 }
 }
@@ -452,6 +483,7 @@ static int send_and_receive(byte *req, byte *reply)
 		log_error("Receive error: %d", err);
 		log_error("Receive error: %d", err);
 		return err;
 		return err;
 	}
 	}
+	packet_rx_time = time(NULL);
 	if (debug_packets)
 	if (debug_packets)
 		log_pkt("<< recv %d bytes\n", transferred);
 		log_pkt("<< recv %d bytes\n", transferred);
 	while (transferred < 64)
 	while (transferred < 64)

+ 1 - 1
web/index.cgi

@@ -38,7 +38,7 @@ sub links(@) {
 
 
 print "<p>Temperature:", links("temp-", "quick", "12h", "48h", "month"), "\n";
 print "<p>Temperature:", links("temp-", "quick", "12h", "48h", "month"), "\n";
 print "<p>Humidity:", links("rh-", "12h", "48h", "month"), "\n";
 print "<p>Humidity:", links("rh-", "12h", "48h", "month"), "\n";
-print "<p>Power:", links("power-", "2h", "2h-detail", "day", "day-detail", "month"), "\n";
+print "<p>Power:", links("power-", "2h", "2h-detail", "day", "day-detail", "48h", "48h-detail", "week", "month"), "\n";
 
 
 if ($graph =~ /^power-/) {
 if ($graph =~ /^power-/) {
 	$graph = "http://micac.burrow.ucw.cz/cgi-bin/$graph";
 	$graph = "http://micac.burrow.ucw.cz/cgi-bin/$graph";