Arrow Intern IoT / Mbed 2 deprecated ENV_NODE_REQUEST_POC

Dependencies:   mbed BME280 SI1145

Committer:
jonathanyost
Date:
Tue Jun 27 23:29:00 2017 +0000
Revision:
2:2bdf15b94f18
Parent:
1:423c669d0306
Child:
3:51b128605eaa
Transmitting;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jonathanyost 0:4354437a1033 1 #include "mbed.h"
jonathanyost 0:4354437a1033 2 #include <string>
jonathanyost 0:4354437a1033 3
jonathanyost 0:4354437a1033 4 #define node_id (0x01)
jonathanyost 0:4354437a1033 5 #define tx (PA_9)
jonathanyost 0:4354437a1033 6 #define rx (PA_10)
jonathanyost 0:4354437a1033 7
jonathanyost 2:2bdf15b94f18 8 const char nodeID = '1';
jonathanyost 1:423c669d0306 9
jonathanyost 0:4354437a1033 10 Serial xb(tx, rx);
jonathanyost 0:4354437a1033 11 Serial pc(D1, D0);
jonathanyost 0:4354437a1033 12
jonathanyost 1:423c669d0306 13 //send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise);
jonathanyost 1:423c669d0306 14 //"id:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8"
jonathanyost 1:423c669d0306 15 void send_sensor_data(int t, int p, int h, int m, int u, int ir, int v, int n){
jonathanyost 1:423c669d0306 16 //" id:2, te:%2,pr:%3,mo:%4,uv:%5,ir:%6,vi:%7,no:%8"
jonathanyost 2:2bdf15b94f18 17 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);
jonathanyost 1:423c669d0306 18 }
jonathanyost 0:4354437a1033 19
jonathanyost 1:423c669d0306 20 void send_pir_data(int pir){
jonathanyost 1:423c669d0306 21 xb.printf("PIR:%d",pir);
jonathanyost 0:4354437a1033 22 }
jonathanyost 1:423c669d0306 23
jonathanyost 0:4354437a1033 24 int main() {
jonathanyost 1:423c669d0306 25 pc.printf("echo!!\n\r");
jonathanyost 0:4354437a1033 26 // initialize read data chars
jonathanyost 0:4354437a1033 27 char pc_data = 'e';
jonathanyost 1:423c669d0306 28 char buffer[128];
jonathanyost 0:4354437a1033 29
jonathanyost 1:423c669d0306 30 /* Sensor Data
jonathanyost 2:2bdf15b94f18 31 format: "ID:2,te:2,pr:3,mo:4,uv:5,ir:6,vi:7,no:8"
jonathanyost 1:423c669d0306 32
jonathanyost 1:423c669d0306 33
jonathanyost 1:423c669d0306 34 */
jonathanyost 0:4354437a1033 35
jonathanyost 2:2bdf15b94f18 36 int temp = 1;
jonathanyost 2:2bdf15b94f18 37 int pressure = 2;
jonathanyost 2:2bdf15b94f18 38 int humidity = 3;
jonathanyost 2:2bdf15b94f18 39 int motion = 4;
jonathanyost 2:2bdf15b94f18 40 int uv = 5;
jonathanyost 2:2bdf15b94f18 41 int ir = 6;
jonathanyost 2:2bdf15b94f18 42 int vis = 7;
jonathanyost 2:2bdf15b94f18 43 int noise = 8;
jonathanyost 2:2bdf15b94f18 44
jonathanyost 2:2bdf15b94f18 45 bool send_enable = false;
jonathanyost 1:423c669d0306 46
jonathanyost 0:4354437a1033 47 while(true){
jonathanyost 0:4354437a1033 48 if(pc.readable()){
jonathanyost 0:4354437a1033 49 pc_data = pc.getc();
jonathanyost 0:4354437a1033 50 pc.printf("%c", pc_data);
jonathanyost 0:4354437a1033 51 xb.printf("%c", pc_data);
jonathanyost 0:4354437a1033 52 }
jonathanyost 0:4354437a1033 53
jonathanyost 0:4354437a1033 54 if(xb.readable()){
jonathanyost 2:2bdf15b94f18 55 xb.gets(buffer, 5);
jonathanyost 2:2bdf15b94f18 56 pc.printf("%s", buffer);
jonathanyost 2:2bdf15b94f18 57
jonathanyost 2:2bdf15b94f18 58 /*for(int i = 0; i < 5; i++){
jonathanyost 2:2bdf15b94f18 59 pc.printf("%c",buffer[i]);
jonathanyost 2:2bdf15b94f18 60 wait(0.1);
jonathanyost 2:2bdf15b94f18 61 }*/
jonathanyost 2:2bdf15b94f18 62
jonathanyost 2:2bdf15b94f18 63 if(buffer[3] == nodeID){
jonathanyost 2:2bdf15b94f18 64 send_enable = true;
jonathanyost 2:2bdf15b94f18 65 }
jonathanyost 1:423c669d0306 66 }
jonathanyost 1:423c669d0306 67
jonathanyost 2:2bdf15b94f18 68 if(xb.writeable() && send_enable){
jonathanyost 1:423c669d0306 69 send_sensor_data(temp, pressure, humidity, motion, uv, ir, vis, noise);
jonathanyost 2:2bdf15b94f18 70 send_enable = false;
jonathanyost 0:4354437a1033 71 }
jonathanyost 0:4354437a1033 72 }
jonathanyost 0:4354437a1033 73 }
jonathanyost 0:4354437a1033 74