dht11/dht11.c

changeset 31
89dd2b691701
child 35
f3c5ae78b746
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dht11/dht11.c	Thu May 08 22:36:51 2014 +0200
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (C) 2014
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of the mbsePi-apps
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * mbsePi-apps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with EC-65K; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+#include "../lib/mbselib.h"
+#include "dht11.h"
+
+#ifdef HAVE_WIRINGPI_H
+
+extern int	dht11_valid;
+extern int	dht11_temperature;
+extern int	dht11_humidity;
+
+int main(int argc, char *argv[]) {
+  
+    int PIN = 3;
+     
+    if (wiringPiSetup() == -1)
+	return 0;
+
+    dht11Init(PIN, 0, 6);
+    dht11Read();
+    if (dht11_valid) {
+	fprintf(stdout, "DHT11: temperature %d degrees, humidity %d%%\n", dht11_temperature, dht11_humidity);
+    } else {
+	fprintf(stdout, "DHT11: no valid data or sensor not connected\n");
+    }
+
+    exit(0);
+}
+
+#else
+
+int main(int argc, char *argv[]) {
+    fprintf(stderr, "This program does nothing without the wiringPi library\n");
+    return 0;
+}
+
+#endif
+

mercurial