92

Dependencies:   ADXL362 ATParser MPL3115A2 TSL2561 mbed

Fork of Lab91 by Fanbo Sun

Revision:
6:074cf15af4a2
Parent:
5:4a5b8c114486
Child:
7:0f8f06ef71dd
Child:
8:a3f81e46a122
--- a/main.cpp	Fri Apr 06 20:22:02 2018 +0000
+++ b/main.cpp	Fri Apr 20 16:01:07 2018 +0000
@@ -4,52 +4,55 @@
 #include <math.h>
 #include <ATParser.h>
 #include "BufferedSerial.h"
+#include "TSL2561.h"
  
 //Serial pc(SERIAL_TX, SERIAL_RX);
 DigitalOut myled(LED1);
 DigitalOut powerpin(PA_8); // GPIO pin
-BufferedSerial pc(SERIAL_TX, SERIAL_RX);
+//BufferedSerial pc(SERIAL_TX, SERIAL_RX);
 BufferedSerial device(PA_9, PA_10);
  
 // Selects SDA as I2C1_SDA on pin PB_7
 // Selects SCL on I2C1_SCL on pin PB_6
 // The I2C address of the pressure sensor is fixed at 0x60. 
 MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
+TSL2561 lightsensor(PB_4,PA_7);
+
  
 int main() {
     uint8_t id;
-    double p, t;
+    double p, t, l;
     myled = 0;
     powerpin = 0;
     ATParser at = ATParser(device, "\r\n", 256, 2000, false);
     char buffer[30];
-    pc.baud(115200);
+    char buffer1[30];
+//    pc.baud(115200);
     device.baud(115200);
     
-    pc.printf("Hello");
+  //  pc.printf("Hello");
     
-    at.send("AT+NI=1,MTCDT-19400691\n\r");
-    wait(1);
-    printf("Hello");
-    at.send("AT+NK=1,MTCDT-19400691\n\r");
-    wait(1);
-    at.send("AT+FSB=1\n\r");
-    wait(1);
-    at.send("AT+JOIN\n\r");
-    
+    at.send("AT+NI=1,MTCDT-19400691\n\r") && at.recv("OK");
+    at.send("AT+NK=1,MTCDT-19400691\n\r") && at.recv("OK");
+    at.send("AT+FSB=1\n\r") && at.recv("OK");
+    at.send("AT+JOIN\n\r") && at.recv("OK");
+
     while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
     {
         wait(1);
     }
     
-    while(1)
+    while(1) 
     {
-        wait(3600);
+        l=lightsensor.lux();  
         p=pressure_sensor.getPressure();
         t=pressure_sensor.getTemperature();
-        sprintf(buffer, "AT+SEND=%.1f,%.1f", p, t);
-        buffer[18] = '\0';
-        pc.printf(buffer);
-        at.send(buffer);
+        sprintf(buffer1, "AT+SEND=%.4f\n\r", l);
+        sprintf(buffer, "AT+SEND=%.1f,%.1f\n\r", p, t);
+        buffer[20] = '\0';
+    //    pc.printf(buffer);
+        at.send(buffer) && at.recv("OK"); 
+        at.send(buffer1) && at.recv("OK"); 
+        wait(10);
     }
 }
\ No newline at end of file