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:
- 3:51b128605eaa
- Parent:
- 2:2bdf15b94f18
- Child:
- 4:8c15903a5581
--- a/main.cpp Tue Jun 27 23:29:00 2017 +0000
+++ b/main.cpp Wed Jun 28 21:05:29 2017 +0000
@@ -1,24 +1,49 @@
+/*
+ Author: Jonathan Yost
+ Title: END_NODE_REQUEST_POC
+ Date: 6/28/17
+
+ Desc: Reads in data from the sensors and sends to the gateway.
+ yeah.
+*/
+
+// Libraries
#include "mbed.h"
-#include <string>
+#include "BME280.h"
+#include "SI1145.h"
+// Define Constants / Macros
#define node_id (0x01)
#define tx (PA_9)
#define rx (PA_10)
+
const char nodeID = '1';
+// I/O Delarations
+I2C i2c(I2C_SDA, I2C_SCL); // D14, D15
+BME280 *thp_sensor = new BME280(i2c);
+SI1145 *uiv_sensor = new SI1145(i2c);
+
+// Declare Serial Interfaces
Serial xb(tx, rx);
Serial pc(D1, D0);
//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 send_sensor_data(int t, int p, int h, int m, int u, int ir, int v, int n){
+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",nodeID,t,p,h,m,u,ir,v,n);
+ 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 send_pir_data(int pir){
- xb.printf("PIR:%d",pir);
+void SendPirData(int pir){
+ xb.printf("id:%c,mo:%d",nodeID,pir);
+}
+
+float GetTemp(){
+ // Returns the temp value read from the BME280 sensor board
+ return thp_sensor->getTemperature();
}
int main() {
@@ -42,33 +67,65 @@
int vis = 7;
int noise = 8;
+ bool pir_trigger = false;
bool send_enable = false;
while(true){
+ // Debug Controls Input
if(pc.readable()){
pc_data = pc.getc();
pc.printf("%c", pc_data);
xb.printf("%c", pc_data);
}
+ //Read in data from XBee
if(xb.readable()){
- xb.gets(buffer, 5);
- pc.printf("%s", buffer);
+ xb.gets(buffer, 6);
+ pc.printf("recv: %s\r", buffer);
- /*for(int i = 0; i < 5; i++){
- pc.printf("%c",buffer[i]);
- wait(0.1);
- }*/
+ /* TODO!!! SOMETIMES THE XBEE READS IN "i:1" instead of "id:1"...
+ No idea why. For now I will accept both, but that's gross.
+
+ */
- if(buffer[3] == nodeID){
+ if(buffer[3] == nodeID || buffer[2] == nodeID){
send_enable = true;
+ } else {
+ send_enable = false;
}
}
+
+ if(xb.writeable() && pir_trigger){
+ pc.printf("pir_trigger TRUE");
+ }
+
+
if(xb.writeable() && send_enable){
- send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise);
+ SendSensorData(temp, pressure, humidity, motion, uv, ir, vis, noise);
send_enable = false;
}
+
+ // Take in new measurements
+ // Read in values from the BME280 board
+ temp = thp_sensor->getTemperature();
+ pressure = thp_sensor->getPressure();
+ humidity = thp_sensor->getHumidity();
+
+ motion = 404; // TODO: Attach this to an interrupt...
+
+ //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;
}
}