
IoT_watering project - supervisor
Dependencies: mbed-rtos mbed ssWi
Revision 1:dcfe7e79a45c, committed 2017-01-19
- Comitter:
- mariob
- Date:
- Thu Jan 19 23:31:18 2017 +0000
- Parent:
- 0:cc364516d433
- Child:
- 2:69d2d4c76f02
- Commit message:
- fix
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.h Thu Jan 19 23:31:18 2017 +0000 @@ -0,0 +1,55 @@ +#ifndef __SUPERVISOR_CONFIG__ +#define __SUPERVISOR_CONFIG__ + +// TIME +#define TIMEOUT_READ 10.0 +#define INTERVAL_SAMPLING 40.0 +#define INTERVAL_SYNC 6.0 +#define INTERVAL_1_SECOND 1.0 +#define INTERVAL_60_SECONDS 60 + +// COMM VALUES +#define COMM_NO_VALUE 0x0000 +#define COMM_START_SAMPLING 0xAAAA +#define COMM_STOP_SAMPLING 0x1111 +#define COMM_START_WATERING_OFFSET 0xFF00 +#define COMM_SHUTDOWN 0x00FF +#define COMM_EXIT 0x2244 +#define COMM_SAMPLING_KO 0x2222 +#define COMM_SAMPLING_OUT 0x5555 +#define COMM_SAMPLING_OK 0xBBBB +#define COMM_WATERING_KO 0x3333 +#define COMM_WATERING_OK 0xCCCC +#define COMM_LOW_WATER_LEVEL 0x7777 + +// PORTS +#define PORT_COMMANDS 0x00 +#define PORT_HUMIDITY_OFFSET 0x01 +#define PORT_TEMPERATURE_OFFSET 0x02 +#define PORT_MOISTURE_OFFSET 0x03 +#define PORT_WATER_OFFSET 0x04 +#define PORT_RESPONSE_OFFSET 0x05 + +#define MAX_NUM_NODES 10 + +// FILES +#define FILE_CNT "/local/CNT.txt" +#define FILE_CFG "/local/cfg.txt" +#define FILE_SNS "/local/SNS.txt" +#define FILE_WTR "/local/WTR.txt" +#define FILE_BSY "/local/BSY.txt" + +struct watering_unit_node_t { + int address; + int watering_wait; + int watering_seconds; +}; + +struct global_confg_t { + int count; + int wait_minutes; + int num_units; + watering_unit_node_t nodes[MAX_NUM_NODES]; +}; + +#endif //__SUPERVISOR_CONFIG__
--- a/config.hpp Wed Jan 18 21:01:38 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -#ifndef __SUPERVISOR_CONFIG__ -#define __SUPERVISOR_CONFIG__ - -// TIME -#define TIMEOUT_READ 10.0 -#define INTERVAL_SAMPLING 40.0 -#define INTERVAL_SYNC 5.0 -#define INTERVAL_1_SECOND 1.0 -#define INTERVAL_60_SECONDS 60 - -// COMM VALUES -#define COMM_NO_VALUE 0x0000 -#define COMM_START_SAMPLING 0xAAAA -#define COMM_STOP_SAMPLING 0x1111 -#define COMM_START_WATERING_OFFSET 0xFF00 -#define COMM_SHUTDOWN 0x00FF -#define COMM_EXIT 0x2244 -#define COMM_SAMPLING_KO 0x2222 -#define COMM_SAMPLING_OUT 0x5555 -#define COMM_SAMPLING_OK 0xBBBB -#define COMM_WATERING_KO 0x3333 -#define COMM_WATERING_OK 0xCCCC -#define COMM_LOW_WATER_LEVEL 0x7777 - -// PORTS -#define PORT_COMMANDS 0x00 -#define PORT_HUMIDITY_OFFSET 0x01 -#define PORT_TEMPERATURE_OFFSET 0x02 -#define PORT_MOISTURE_OFFSET 0x03 -#define PORT_WATER_OFFSET 0x04 -#define PORT_RESPONSE_OFFSET 0x05 - -#define MAX_NUM_NODES 10 - -// FILES -#define FILE_CNT "/local/CNT.txt" -#define FILE_CFG "/local/cfg.txt" -#define FILE_SNS "/local/SNS.txt" -#define FILE_WTR "/local/WTR.txt" -#define FILE_BSY "/local/BSY.txt" - -struct watering_unit_node_t { - int address; - int watering_wait; - int watering_seconds; -}; - -struct global_confg_t { - int count; - int wait_minutes; - int num_units; - watering_unit_node_t nodes[MAX_NUM_NODES]; -} global_config; - -#endif //__SUPERVISOR_CONFIG__
--- a/main.cpp Wed Jan 18 21:01:38 2017 +0000 +++ b/main.cpp Thu Jan 19 23:31:18 2017 +0000 @@ -1,13 +1,15 @@ #include "mbed.h" #include "rtos.h" -#include "config.hpp" +#include "config.h" #include "xbee.hpp" #include "ssWiSocket.hpp" int last_watering[MAX_NUM_NODES]; +global_confg_t global_config; + ssWiSocket* socket_command; ssWiSocket* socket_moisture[MAX_NUM_NODES]; ssWiSocket* socket_temperature[MAX_NUM_NODES]; @@ -29,6 +31,7 @@ int main() { // supervisor configuration + printf("6\r\n"); #ifdef DEBUG printf("SUPERVISOR - config\r\n"); #endif @@ -60,6 +63,7 @@ #ifdef DEBUG printf("SUPERVISOR - start\r\n"); #endif + while(1) { int minute_counters = 0; read_counter(); @@ -72,6 +76,10 @@ minute_counters++; } while (minute_counters < global_config.wait_minutes); +#ifdef DEBUG + printf("SUPERVISOR - active\r\n"); +#endif + // mark as busy DigitalOut led_busy(LED4); led_busy = 1; @@ -86,7 +94,7 @@ printf("SUPERVISOR - watering\r\n"); #endif do_watering(); - + // increment counter global_config.count++; FILE* fp = fopen(FILE_CNT, "w"); @@ -97,12 +105,15 @@ #ifdef DEBUG printf("SUPERVISOR - shutdown\r\n"); #endif - wait(INTERVAL_SYNC); + + Timer t; + t.start(); + while(t.read() < INTERVAL_SYNC); socket_command->write(COMM_SHUTDOWN); - wait(INTERVAL_SYNC); - socket_command->write(COMM_NO_VALUE); - wait(INTERVAL_SYNC); - + + t.stop(); t.reset(); t.start(); + while(t.read() < INTERVAL_SYNC); + // mark as not busy led_busy = 0; fclose(fp_busy); @@ -118,7 +129,9 @@ while(t.read() < INTERVAL_SAMPLING); socket_command->write(COMM_STOP_SAMPLING); - t.reset(); + t.stop(); + t.reset(); + t.start(); while(t.read() < INTERVAL_SYNC); for (int i = 0; i < global_config.num_units; i++) { @@ -158,11 +171,16 @@ Timer t; t.start(); - wait(t.read() < INTERVAL_1_SECOND); + while (t.read() < (global_config.nodes[i].watering_seconds + + INTERVAL_SYNC)); + + t.stop(); t.reset(); t.start(); + while (t.read() < INTERVAL_1_SECOND); socket_command->write(COMM_START_WATERING_OFFSET + global_config.nodes[i].address); - t.reset(); + + t.stop(); t.reset(); t.start(); while (t.read() < (global_config.nodes[i].watering_seconds + INTERVAL_SYNC)); t.stop();
--- a/ssWi.lib Wed Jan 18 21:01:38 2017 +0000 +++ b/ssWi.lib Thu Jan 19 23:31:18 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mariob/code/ssWi/#8ba1b278b407 +http://mbed.org/users/mariob/code/ssWi/#133e42dc82b0