rgjefklgf

Dependencies:   mbed ATParser MPL3115A2 TSL2561

Revision:
4:44e43da30b0e
Parent:
3:6494a5d6f2ba
Child:
6:e7d266de146a
--- a/main.cpp	Tue Apr 10 15:17:34 2018 +0000
+++ b/main.cpp	Wed Apr 11 20:13:59 2018 +0000
@@ -1,16 +1,18 @@
 #include "mbed.h"
 #include "ATParser.h"
 #include "MPL3115A2.h"
+#include "TSL2561.h"
 #include <string>
 #include <iostream>
 
 
 
 
-MPL3115A2 pressure_sensor(PB_7, PB_6, 0x60);
+//MPL3115A2 pressure_sensor(PB_7, PB_6, 0x60);
 BufferedSerial pc(SERIAL_TX, SERIAL_RX);
 BufferedSerial dev(PA_9, PA_10);
 DigitalOut myled(LED1);
+TSL2561 light_sensor(PB_7, PB_6); // addr: 0x29 since addr is groundedx
 
 using namespace std;
  
@@ -20,6 +22,8 @@
     pc.baud(115200);
     dev.baud(115200);
     
+    light_sensor.set_timing_reg(0x10); // nominal integration time: 402ms (max in datasheet)
+    
     pc.printf("Begin headaches\r\n");
     
     ATParser at = ATParser(dev, "\r\n");
@@ -32,74 +36,105 @@
         pc.printf("Network ID specified\r\n");
     if (at.send("AT+NK=1,MTCDT-19400691") && at.recv("OK"))
         pc.printf("Network Passphrase specified\r\n");
-    while() {  
-        if (at.send("AT+JOIN") && at.recv("OK"))
+        
+    if(at.send("AT+FSB=1") && at.recv("OK"))
+        pc.printf("band specified\r\n");
+     
+    bool joined = false;
+    while(!joined) {
+        if (at.send("AT+JOIN") && at.recv("OK")) {
             pc.printf("Joined Network!\r\n");
-        
+            joined = true;
+        }
+        else {
+            pc.printf("network not joined\r\n");
+        }
     }
     
+    
+    
+        
+    
+    
     // Set pressure sensor to read in units of mbar & celcius
-    pressure_sensor.setCTRL_REG1(0xA1); 
+    //pressure_sensor.setCTRL_REG1(0xA1); 
     
     char tempBuff[20];
     char presBuff[20];
+    char lightBuff[20];
     char sendcommand[50] = "AT+SEND=";
     
-    pc.printf("Awaiting Commands.\r\n");
+    //pc.printf("Awaiting Commands.\r\n");
     // Wait for "s" string from console serial input.
     while(1) 
     {
-        char c = pc.getc();
+        float light_value = light_sensor.lux(); // read light sensor
+        sprintf(lightBuff, "%3.2f", light_value);
+        //wait(1);
+            
+            
+        sprintf(sendcommand, "%s", "AT+SEND=");
+        char *command[60];
+        *command = strcat(sendcommand, lightBuff);
+        pc.printf("%s\r\n", *command);
         
-        if( c == 'j') {
-            printf("joining network\r\n");
-            if (at.send("AT+JOIN") && at.recv("OK"))
-                pc.printf("Joined Network!\r\n");
-        }
+        if (at.send(*command) && at.recv("OK")) {
+                pc.printf("light reading sent!\r\n");
+            }
+            else {
+                pc.printf("send not successful\r\n");
+            }
         
-        // Read temperature and pressure from MPL3115A2.
+        
         
-        if (c == 'e')
+        //char c = pc.getc();
+        /*if (c == 'e')
         {
           at.flush();
           pc.printf("Exiting Program\r\n");
           return(0);
-        }
+        }*/
         
-        if (c == 's') 
+        /*if (c == 's') 
         {
-            pc.printf("You entered: s\r\n");
-            // Force XDot to send temperature and pressure to MQTT server
             
            //temp = pressure_sensor.getTemperature();
             //pres = pressure_sensor.getAltitude();
-            //pc.printf("temperature: %d\r\n", temp);
-            //pc.printf("pressure: %\r\nd", pres);
-            pc.printf("Temperature and Pressure Read\r\n");
+          
             
+            float light_value = light_sensor.lux(); // read light sensor
+            sprintf(lightBuff, "%f", light_value);
+            wait(1);
+            pc.printf("%s\r\n", lightBuff);
+            wait(1);
+            pc.printf("%f\r\n", light_value);
         
             //convert doubles to string           
             //sprintf(tempBuff, "%lf", temp);
             //sprintf(presBuff, "%lf", pres);
-            //sprintf(sendcommand, "%s", "AT+SEND=");
             
+            sprintf(sendcommand, "%s", "AT+SEND=");
+            string *hold;
             string *command;
+            *hold = strcat(sendcommand, ",");
+            *command = strcat(((char *)hold), lightBuff);
             //*command = strcat(sendcommand, strcat(strcat(presBuff,","), tempBuff));
             //pc.printf("%s\r\n", (*command).c_str());
-            //at.send(((const char*)command));
             //pc.printf("Temperature and Pressure Sent\r\n");
             
             
-            if (at.send("AT+SEND=20200") && at.recv("OK"))
-                pc.printf("Temp & Pres Sent!\r\n");
-            else
-                pc.printf("didnt send\r\n");
+            if (at.send(((const char*)command)) && at.recv("OK")) {
+                pc.printf("light reading sent!\r\n");
+            }
+            else {
+                pc.printf("send not successful\r\n");
+            }
             
             wait(2);
                    
-        }
+        }*/
         
-        at.flush();
+        //at.flush();
     
     }
     return(0);