IoT_watering project - watering unit

Dependencies:   DHT11 mbed-rtos mbed ssWi

Files at this revision

API Documentation at this revision

Comitter:
mariob
Date:
Thu Feb 16 22:08:06 2017 +0000
Parent:
1:7f4af0d73836
Commit message:
release 1.0

Changed in this revision

config.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7f4af0d73836 -r 0b51e6d879df config.hpp
--- a/config.hpp	Mon Jan 23 20:36:52 2017 +0000
+++ b/config.hpp	Thu Feb 16 22:08:06 2017 +0000
@@ -4,7 +4,7 @@
 // Hardware pins
 #define HW_PIN_MOISTURE             p20
 #define HW_PIN_TEMPERATURE          p17
-#define HW_PIN_PUMP                 LED4
+#define HW_PIN_PUMP                 p25
 #define HW_PIN_LOW_WATER_LEVEL      p14
 
 // internal signals/events to synchronize threads
diff -r 7f4af0d73836 -r 0b51e6d879df main.cpp
--- a/main.cpp	Mon Jan 23 20:36:52 2017 +0000
+++ b/main.cpp	Thu Feb 16 22:08:06 2017 +0000
@@ -14,11 +14,10 @@
 
 LocalFileSystem local("local");
 
+// global configuration
 watering_unit_config_t global_config;
 
-void thread_sensing_fcn();
-void thread_watering_fcn();
-
+// ssWi sockets
 ssWiSocket* socket_moisture = NULL;
 ssWiSocket* socket_temperature = NULL;
 ssWiSocket* socket_humidity = NULL;
@@ -26,6 +25,11 @@
 ssWiSocket* socket_water = NULL;
 ssWiSocket* socket_command = NULL;
 
+// thread functions
+void thread_sensing_fcn();
+void thread_watering_fcn();
+
+// return true if a new message has been received, false otherwise
 bool read_from_port(ssWiSocket *socket, int *value);
 
 int main() {
@@ -33,7 +37,7 @@
     t.start();
     
     printf("MAIN - configuration\r\n");
-
+    
     // read configuration    
     FILE *fp = fopen("/local/cfg.txt", "r");
     if (fp == NULL)
@@ -47,7 +51,7 @@
     global_config.water_port = GET_WATER_PORT(global_config);
 
     // configure network
-    XBeeModule xbee(p9, p10, PAN_ID, CHANNEL_ID);
+    XBeeModule xbee(XBEE_PIN_TX, XBEE_PIN_RX, PAN_ID, CHANNEL_ID);
     xbee.init(XBEE_TX_PER_SECOND, XBEE_RX_PER_SECOND);
     socket_moisture = ssWiSocket::createSocket(global_config.moisture_port);
     socket_temperature = 
@@ -106,11 +110,6 @@
             socket_response->write(COMM_NO_VALUE);
             continue;
         }
-        if (msg == COMM_EXIT) {
-            // message not possible: to avoid the non-reachable code warning
-            printf("MAIN - exit command\r\n");
-            break;
-        }
     }
 
     printf("MAIN - join threads and end\r\n");
@@ -133,6 +132,9 @@
         Thread::signal_wait(SIGNAL_START_ARRIVED);
         printf("SAMP - start\r\n");
 
+        DigitalOut l(LED3);
+        l = 1;
+
         Timer t;
         t.start();
         // wait two seconds for HDT sensor
@@ -178,6 +180,8 @@
         socket_humidity->write(value == 0 ? 1 : value);
         socket_response->write(msg);
         printf("SAMP - end\r\n");
+        
+        l = 0;
     }
 }
 
@@ -195,6 +199,9 @@
         Timer t;
         t.start();
 
+        DigitalOut l(LED2);
+        l = 1;
+
         // read total second to water
         int seconds = COMM_NO_VALUE;
         while(!read_from_port(socket_water, &seconds) &&
@@ -229,6 +236,8 @@
         pump = 0;
         printf("WATR - elapsed time %fs\r\n", actual_seconds);
         socket_response->write(msg);
+        
+        l = 0;
     }
 }