Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: XBeeLib mbed-rtos mbed
Revision 10:29d5ca2beffb, committed 2017-12-05
- Comitter:
- ggs22
- Date:
- Tue Dec 05 20:47:03 2017 +0000
- Parent:
- 8:62898720a01d
- Parent:
- 9:68575180c7a7
- Child:
- 11:0847a914171e
- Commit message:
- commit with drain function;
Changed in this revision
--- a/Capteurs/EC/EC.cpp Tue Dec 05 19:36:25 2017 +0000
+++ b/Capteurs/EC/EC.cpp Tue Dec 05 20:47:03 2017 +0000
@@ -240,29 +240,18 @@
float getEC(){
- float res=0,tmp=0;
+ char bufTmp[DEFAULT_BUFFER_SIZE];
- if(fBuf[0]!=0){
- int i=0;
- int divider=0;
- do{
- i++;
- }while(fBuf[i]!=',');
- pc.printf("i:%i\n",i);
- for(int j=1;j<i;j++){
- tmp=0;
- tmp=(fBuf[j]>=48 && fBuf[j]<=57)?((fBuf[j] - 48)):0;
- if(fBuf[j]==46){
- i=i-1;
- divider=(fBuf[j]==46);
- }
- for(int k=0;k<(i-j-1);k++){
- tmp*=10;
- }
- res+=tmp;
- }
- }
- return res;
+ EC.start();
+ EC.write(EC_ADRESSE<<1);
+ EC.write('R');
+ EC.stop();
+
+ wait_ms(600);
+ EC.write(0x00);
+ EC.read(EC_ADRESSE<<1,bufTmp,DEFAULT_BUFFER_SIZE);
+
+ return atof(bufTmp+1);
}
float getTDS(){
--- a/Capteurs/RTD/RTD.cpp Tue Dec 05 19:36:25 2017 +0000
+++ b/Capteurs/RTD/RTD.cpp Tue Dec 05 20:47:03 2017 +0000
@@ -165,6 +165,22 @@
clearBuffer_RTD();
}
+float getRTD(){
+
+ char bufTmp[DEFAULT_BUFFER_SIZE];
+
+ RTD.start();
+ RTD.write(RTD_ADRESSE<<1);
+ RTD.write('R');
+ RTD.stop();
+
+ wait_ms(600);
+ RTD.write(0x00);
+ RTD.read(RTD_ADRESSE<<1,bufTmp,DEFAULT_BUFFER_SIZE);
+
+ return atof(bufTmp+1);
+}
+
void read_RTD(char * buffer){
RTD.start();
--- a/Capteurs/RTD/RTD.h Tue Dec 05 19:36:25 2017 +0000 +++ b/Capteurs/RTD/RTD.h Tue Dec 05 20:47:03 2017 +0000 @@ -14,6 +14,7 @@ void sleep_RTD(); void getInfo_RTD(); void read_RTD(); +float getRTD(); void read_RTD(char * buffer); void clearBuffer_RTD();
--- a/Capteurs/Sensors.cpp Tue Dec 05 19:36:25 2017 +0000
+++ b/Capteurs/Sensors.cpp Tue Dec 05 20:47:03 2017 +0000
@@ -1,5 +1,4 @@
#include "Sensors.h"
-#include "xbeeutils.h"
static Serial pc(USBTX,USBRX);
@@ -7,8 +6,8 @@
pc.printf("Calibrating sensors...\n");
- calibrate_EC();
- calibrate_RTD();
+ //calibrate_EC();
+ //calibrate_RTD();
//calibrate_PH();
pc.printf("Calibration completed!\n");
}
@@ -20,13 +19,11 @@
read_EC(ECBuf);
read_RTD(RTDBuf);
read_PH(phBuf);
-
- //sprintf(TxBuf,"%s;%s;%s",RTDBuf+1,phBuf+1,ECBuf+1);
- sprintf(TxBuf,"%s;%s;%s;\0","1.1","2.2","3.3");
+
+ sprintf(TxBuf,"%s;%s;%s",RTDBuf+1,phBuf+1,ECBuf+1);
+ //sprintf(TxBuf,"%s;%s;%s;\0","1.1","2.2","3.3");
pc.printf("%s\n",TxBuf);
RemoteXBeeZB xbzb = get_remote_node();
const RemoteXBeeZB& remoteDevice = xbzb;
-
xbee_send(remoteDevice, TxBuf, strlen(TxBuf));
- pc.printf("TxBuf strlen: %i\n",strlen(TxBuf));
}
\ No newline at end of file
--- a/Capteurs/Sensors.h Tue Dec 05 19:36:25 2017 +0000 +++ b/Capteurs/Sensors.h Tue Dec 05 20:47:03 2017 +0000 @@ -6,6 +6,7 @@ #include "EC.h" #include "pH.h" #include "RTD.h" +#include "xbeeutils.h" void calibrateSensors(); void getReadings();
--- a/Capteurs/pH/pH.cpp Tue Dec 05 19:36:25 2017 +0000
+++ b/Capteurs/pH/pH.cpp Tue Dec 05 20:47:03 2017 +0000
@@ -160,6 +160,22 @@
clearBuffer_PH();
}
+float getPH(){
+
+ char bufTmp[DEFAULT_BUFFER_SIZE];
+
+ PH.start();
+ PH.write(PH_ADRESSE<<1);
+ PH.write('R');
+ PH.stop();
+
+ wait_ms(900);
+ PH.write(0x00);
+ PH.read(PH_ADRESSE<<1,bufTmp,DEFAULT_BUFFER_SIZE);
+
+ return atof(bufTmp+1);
+}
+
void read_PH(char * buffer){
PH.start();
--- a/Capteurs/pH/pH.h Tue Dec 05 19:36:25 2017 +0000 +++ b/Capteurs/pH/pH.h Tue Dec 05 20:47:03 2017 +0000 @@ -14,6 +14,7 @@ void sleep_PH(); void getInfo_PH(); void read_PH(); +float getPH(); void read_PH(char * buffer); void clearBuffer_PH();
--- a/ProcessControl/ProcessControl.cpp Tue Dec 05 19:36:25 2017 +0000
+++ b/ProcessControl/ProcessControl.cpp Tue Dec 05 20:47:03 2017 +0000
@@ -3,6 +3,17 @@
static Config config;
static int updated = 0;
+static DigitalOut pKOH(p12); // pH -
+static DigitalOut pH2PO4(p13); // pH +
+static DigitalOut HydroBloom(p14); // Nutrients
+static DigitalOut solValve(p15); // Nutrients
+static DigitalOut drainPump(p16); // Nutrients
+static DigitalOut nutPump(p17); // Nutrients
+static DigitalOut waterPump(p18); // Nutrients
+static Serial pc(USBTX,USBRX);
+
+
+
int getConfig(Config *conf) {
if(updated) {
conf = &config;
@@ -12,19 +23,61 @@
}
}
+void initSystem(){
+ pKOH=1;
+ pH2PO4=1;
+ HydroBloom=1;
+ solValve=1;
+ drainPump=1;
+ nutPump=1;
+
+}
+
+
void setConfig(Config conf) {
config = conf;
updated = 1;
}
+void drainSystem(){
+ pc.printf("Drainage du systeme initie...\n");
+ pc.printf("Overture valve et pompe...\n");
+ solValve =0;
+ drainPump=0;
+
+
+ for(int i=120;i>=0;i--){
+ wait_ms(1000);
+ pc.printf("drainage complet dans %i secondes\n",i);
+ }
+ solValve =1;
+ drainPump=1;
+ pc.printf("Vidange complete\n");
+
+}
+
+
double getTargetTemperature() {
return (config.temperatureMin + config.temperatureMax)/2;
}
+void watering(){
+ waterPump =0;
+ wait(60);
+ waterPump =1;
+
+}
+
+
double getTargetPh() {
return (config.phMin + config.phMax)/2;
}
+void adjustePh(){
+
+}
+
double getTargetEc() {
return config.ec;
-}
\ No newline at end of file
+}
+
--- a/ProcessControl/ProcessControl.h Tue Dec 05 19:36:25 2017 +0000
+++ b/ProcessControl/ProcessControl.h Tue Dec 05 20:47:03 2017 +0000
@@ -1,6 +1,8 @@
#ifndef PROCESSCONTROL_H
#define PROCESSCONTROL_H
#include "Sensors.h"
+#include "mbed.h"
+
struct Config{
double temperatureMin;
@@ -13,6 +15,11 @@
int getConfig(Config *conf);
void setConfig(Config conf);
+void initSystem();
+void drainSystem();
+void watering();
+void setTargets();
+
double getTargetTemperature();
double getTargetPh();
double getTargetEc();
--- a/main.cpp Tue Dec 05 19:36:25 2017 +0000
+++ b/main.cpp Tue Dec 05 20:47:03 2017 +0000
@@ -2,6 +2,7 @@
#include "Sensors.h"
#include "rtos.h"
#include "xbeeutils.h"
+#include "ProcessControl.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
@@ -19,7 +20,7 @@
int main() {
int l1=0;
- char buf[] = "1;2;0.5";
+ //char buf[] = "1;2;0.5";
parameterToECOnly();
@@ -29,7 +30,7 @@
init_EC();
pc.printf("Probes initialized!\n\n");
- xbee_init();
+ //xbee_init();
//find_RTD();
@@ -47,25 +48,33 @@
//calibrateSensors();
+
+ initSystem();
+ wait(10);
+ drainSystem();
+
while(1) {
l1=!l1;
led1=l1;
+ /*
wait(1);
pc.printf("pH:\n");
-
read_PH();
+ pc.printf("pH float: %f\n", getPH());
wait(1);
pc.printf("temp:\n");
read_RTD();
+ pc.printf("temp float: %f\n", getRTD());
wait(1);
pc.printf("EC:\n");
- //pc.printf("EC float: %f\n",getEC());
read_EC();
-
+ pc.printf("EC float : %f\n", getEC());
+ */
+
//pc.printf("Sending test data...\n");
//send_data_to_coordinator(buf,strlen(buf));
//test();
@@ -75,5 +84,6 @@
getReadings();
process_rx_frames();
+
}
}
