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
main.cpp
- Committer:
- jonathanyost
- Date:
- 2017-06-28
- Revision:
- 3:51b128605eaa
- Parent:
- 2:2bdf15b94f18
- Child:
- 4:8c15903a5581
File content as of revision 3:51b128605eaa:
/*
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 "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 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 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() {
pc.printf("echo!!\n\r");
// initialize read data chars
char pc_data = 'e';
char buffer[128];
/* Sensor Data
format: "ID:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8"
*/
int temp = 1;
int pressure = 2;
int humidity = 3;
int motion = 4;
int uv = 5;
int ir = 6;
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, 6);
pc.printf("recv: %s\r", buffer);
/* 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 || 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){
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;
}
}