IoT_watering project - watering unit

Dependencies:   DHT11 mbed-rtos mbed ssWi

Revision:
2:0b51e6d879df
Parent:
1:7f4af0d73836
--- 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;
     }
 }