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: mbed BME280 SI1145
Diff: main.cpp
- Revision:
- 5:ad41288051e7
- Parent:
- 4:8c15903a5581
- Child:
- 6:4b1ecb3a95c5
diff -r 8c15903a5581 -r ad41288051e7 main.cpp
--- a/main.cpp Wed Jun 28 21:52:34 2017 +0000
+++ b/main.cpp Fri Jun 30 18:58:17 2017 +0000
@@ -23,6 +23,7 @@
#define rx (PA_10)
const char nodeID = '1';
+const int node_id_test = 1;
// I/O Delarations
I2C i2c(I2C_SDA, I2C_SCL); // D14, D15
@@ -39,10 +40,10 @@
// send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise);
// "id:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8"
-void SendSensorData(int t, int p, int h, int m, int u, int ir, int v, int n){
- //" id:2, te:%2,pr:%3,mo:%4,uv:%5,ir:%6,vi:%7,no:%8"
- xb.printf("id:%c,te:%d,pr:%d,hu:%d,mo:%d,uv:%d,ir:%d,vi:%d,no:%d\r\n",nodeID,t,p,h,m,u,ir,v,n);
- pc.printf("send: id:%c,te:%d,pr:%d,hu:%d,mo:%d,uv:%d,ir:%d,vi:%d,no:%d\r\n",nodeID,t,p,h,m,u,ir,v,n);
+void SendSensorData(int t, int p, int h, int u, int ir, int v, int n){
+ //" id:2, te:%2,pr:%3,uv:%5,ir:%6,vi:%7,no:%8"
+ xb.printf( ",ni:%d,te:%d,pr:%d,hu:%d,uv:%d,ir:%d,vi:%d,no:%d\n\r",node_id_test,t,p,h,u,ir,v,n);
+ pc.printf("send: id:%d,te:%d,pr:%d,hu:%d,uv:%d,ir:%d,vi:%d,no:%d\n\r",node_id_test,t,p,h,u,ir,v,n);
}
void SendPirFlag(){
@@ -65,15 +66,14 @@
pc.printf("echo!!\n\r");
// Attach the PIR function to interrupt
- MotionDetect.rise(&PIR);
+ //MotionDetect.rise(&PIR);
char pc_data = 'e';
- char buffer[128];
+ char buffer[6];
int temp = 1;
int pressure = 2;
int humidity = 3;
- int motion = 4;
int uv = 5;
int ir = 6;
int vis = 7;
@@ -86,57 +86,46 @@
if(pc.readable()){
pc_data = pc.getc();
pc.printf("%c", pc_data);
- xb.printf("%c", pc_data);
+ if(xb.writeable()){xb.printf("%c", pc_data);}
}
-
+ /*
if(pir_trigger){
- pc.printf("pir_trigger TRUE\r\n");
+ // DEBUG
+ //pc.printf("pir_trigger TRUE\r\n");
if(xb.writeable()){SendPirFlag();}
pir_trigger = false;
}
+ */
//Read in data from XBee
if(xb.readable()){
- xb.gets(buffer, 6);
- pc.printf("recv: %s\r", buffer);
+ xb.gets(buffer, 10);
+ pc.printf("recv: %s\n\r", buffer);
-
-
- if(buffer[3] == nodeID || buffer[2] == nodeID){
+ if((buffer[3] == nodeID) || (buffer[2] == nodeID) || (buffer[1] == nodeID) || (buffer[0] == nodeID)){
send_enable = true;
} else {
send_enable = false;
}
+ memset(buffer, '\0', sizeof(buffer));
}
if(xb.writeable() && send_enable){
- SendSensorData(temp, pressure, humidity, motion, uv, ir, vis, noise);
+ SendSensorData(temp, pressure, humidity, uv, ir, vis, noise);
send_enable = false;
}
// Take in new measurements
- // Read in values from the BME280 board
+ // Read in values from the BME280 board
temp = thp_sensor->getTemperature();
pressure = thp_sensor->getPressure();
humidity = thp_sensor->getHumidity();
- if(pir_trigger){
- motion = 1;
- } else {
- motion = 0;
- }
-
//Sensor data from the SI1145 board
uv = uiv_sensor->getUV(); // Reads from the SI1145
ir = uiv_sensor->getIR(); // Reads from the SI1145
vis = uiv_sensor->getVIS(); // Reads from the SI1145
- /*
- uv = 404;
- ir = 404;
- vis = 404;
- */
-
noise = 404;
}
}