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:
- 1:423c669d0306
- Parent:
- 0:4354437a1033
- Child:
- 2:2bdf15b94f18
--- a/main.cpp Tue Jun 27 22:31:32 2017 +0000
+++ b/main.cpp Tue Jun 27 23:01:23 2017 +0000
@@ -2,37 +2,46 @@
#include <string>
#define node_id (0x01)
-#define gateway_id (0xAA)
#define tx (PA_9)
#define rx (PA_10)
+const int nodeID = 1;
+
Serial xb(tx, rx);
Serial pc(D1, D0);
-//string node_id = "01";
-//string gateway_id = "AA"
-
-// function declarations
-void read_data(char* message);
+//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){
+ //" id:2, te:%2,pr:%3,mo:%4,uv:%5,ir:%6,vi:%7,no:%8"
+ xb.printf("id:%d,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);
+}
-/*
-void readString(std::string& result, std::size_t& size) {
- results.clear();
- char data_in;
- while(xb.readable()){
- result.append(xb.getc());
-
- }
+void send_pir_data(int pir){
+ xb.printf("PIR:%d",pir);
}
-*/
+
int main() {
- pc.printf("echo!!\n");
+ pc.printf("echo!!\n\r");
// initialize read data chars
char pc_data = 'e';
+ char buffer[128];
- char buffer[128];
- char message[16];
+ /* Sensor Data
+ format: "id:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8"
+
+
+ */
+ int temp = 0;
+ int pressure = 0;
+ int humidity = 0;
+ int motion = 0;
+ int uv = 0;
+ int ir = 0;
+ int vis = 0;
+ int noise = 0;
+
while(true){
if(pc.readable()){
pc_data = pc.getc();
@@ -42,20 +51,12 @@
if(xb.readable()){
xb.gets(buffer, 4);
- pc.printf("%s", buffer);
-
+ pc.printf("%s", buffer);
+ }
+
+ if(xb.writeable()){
+ send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise);
}
}
}
-void read_data(char* message){
- int i = 0;
-
- while(xb.readable()){
- message[i] = xb.getc();
- pc.printf("%c", message[i]);
- wait(0.1);
- }
-
- pc.printf("%s", message);
-}
\ No newline at end of file