rgjefklgf
Dependencies: mbed ATParser MPL3115A2 TSL2561
Revision 6:e7d266de146a, committed 2018-04-20
- Comitter:
- dgutsch
- Date:
- Fri Apr 20 21:47:49 2018 +0000
- Parent:
- 5:447d7ad9810c
- Commit message:
- she works
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 447d7ad9810c -r e7d266de146a main.cpp --- a/main.cpp Wed Apr 11 20:16:27 2018 +0000 +++ b/main.cpp Fri Apr 20 21:47:49 2018 +0000 @@ -1,23 +1,27 @@ #include "mbed.h" #include "ATParser.h" +#include "TSL2561.h" #include "MPL3115A2.h" -#include "TSL2561.h" #include <string> +#include <algorithm> #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; - -int main() { - + +bool send_it(float * fArray, ATParser *at); + + +int main() { + double temp, pres; pc.baud(115200); dev.baud(115200); @@ -36,10 +40,10 @@ 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"); - + 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")) { @@ -51,91 +55,76 @@ } } - - - + // set big data rate + if(at.send("AT+TXDR=DR2\r\n") && at.recv("OK")) + pc.printf("data rate set.\r\n"); + wait(1); - // Set pressure sensor to read in units of mbar & celcius - //pressure_sensor.setCTRL_REG1(0xA1); - - char tempBuff[20]; - char presBuff[20]; char lightBuff[20]; - char sendcommand[50] = "AT+SEND="; + char sendcommand[5000] = "AT+SEND="; + float pressureCollections[24]; + float tempCollections[24]; - //pc.printf("Awaiting Commands.\r\n"); - // Wait for "s" string from console serial input. - while(1) - { - 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 (at.send(*command) && at.recv("OK")) { - pc.printf("light reading sent!\r\n"); - } - else { - pc.printf("send not successful\r\n"); - } - + int i = 0; + while(1) { + // wait + wait(3600); + if(i == 24) { + send_it(&pressureCollections[0], &at); + send_it(&tempCollections[0], &at); + i = 0; + } - //char c = pc.getc(); - /*if (c == 'e') - { - at.flush(); - pc.printf("Exiting Program\r\n"); - return(0); - }*/ - - /*if (c == 's') - { - - //temp = pressure_sensor.getTemperature(); - //pres = pressure_sensor.getAltitude(); - - - 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); + //float light_value = light_sensor.lux(); // read light sensor + temp = pressure_sensor.getTemperature(); + pres = pressure_sensor.getAltitude(); + //pc.printf("temp: %f, press: %f\r\n", temp, pres); + tempCollections[i] = temp; + pressureCollections[i++] = pres; + //pc.printf("%f\n\r", dataCollections[i - 1]); - //convert doubles to string - //sprintf(tempBuff, "%lf", temp); - //sprintf(presBuff, "%lf", pres); - - 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()); - //pc.printf("Temperature and Pressure Sent\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(); - } return(0); -} \ No newline at end of file +} + + + +bool send_it(float * fArray, ATParser *at) { + //pc.printf("it worked\r\n"); + + char send1[100]; + char send2[100]; + + sprintf(send1, "AT+SEND=%3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f\r\n", fArray[0], fArray[1], fArray[2], fArray[3], fArray[4], fArray[5], fArray[6], fArray[7], fArray[8], fArray[9], fArray[10], fArray[11]); + wait(2); + //pc.printf("%s\r\n", *send1); + + sprintf(send2, "AT+SEND=%3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f %3.2f\r\n", fArray[12], fArray[13], fArray[14], fArray[15], fArray[16], fArray[17], fArray[18], fArray[19], fArray[20], fArray[21], fArray[22], fArray[23]); + + //pc.printf("%s\r\n", *send2); + bool did_it_work = false; + //wait(2); + + + if ((*at).send(send1) && (*at).recv("OK")) { + pc.printf("light reading sent!\r\n"); + did_it_work = true; + } + else { + pc.printf("send not successful\r\n"); + did_it_work = false; + } + //////////////send2//////////////////// + + if ((*at).send(send2) && (*at).recv("OK")) { + pc.printf("light reading sent!\r\n"); + return did_it_work && true; + } + else { + pc.printf("send not successful\r\n"); + return false; + } +} + \ No newline at end of file