rgjefklgf
Dependencies: mbed ATParser MPL3115A2 TSL2561
Diff: main.cpp
- Revision:
- 3:6494a5d6f2ba
- Parent:
- 2:10a9331f04e2
- Child:
- 4:44e43da30b0e
diff -r 10a9331f04e2 -r 6494a5d6f2ba main.cpp --- a/main.cpp Sat Apr 07 23:33:03 2018 +0000 +++ b/main.cpp Tue Apr 10 15:17:34 2018 +0000 @@ -4,7 +4,8 @@ #include <string> #include <iostream> -//#include <Serial.h> + + MPL3115A2 pressure_sensor(PB_7, PB_6, 0x60); BufferedSerial pc(SERIAL_TX, SERIAL_RX); @@ -19,22 +20,24 @@ pc.baud(115200); dev.baud(115200); - pc.printf("Begin headaches\n\r"); + pc.printf("Begin headaches\r\n"); ATParser at = ATParser(dev, "\r\n"); if (at.send("AT") && at.recv("OK")) - pc.printf("AT Communication Success\n\r"); + pc.printf("AT Communication Success\r\n"); // Set network name and passphrase if (at.send("AT+NI=1,MTCDT-19400691") && at.recv("OK")) - pc.printf("Network ID specified\n\r"); + pc.printf("Network ID specified\r\n"); if (at.send("AT+NK=1,MTCDT-19400691") && at.recv("OK")) - pc.printf("Network Passphrase specified\n\r"); - - if (at.send("AT+JOIN") && at.recv("OK")) - pc.printf("Joined Network!\n\r"); + pc.printf("Network Passphrase specified\r\n"); + while() { + if (at.send("AT+JOIN") && at.recv("OK")) + pc.printf("Joined Network!\r\n"); + } + // Set pressure sensor to read in units of mbar & celcius pressure_sensor.setCTRL_REG1(0xA1); @@ -42,23 +45,20 @@ char presBuff[20]; char sendcommand[50] = "AT+SEND="; - pc.printf("Awaiting Commands."); + pc.printf("Awaiting Commands.\r\n"); // Wait for "s" string from console serial input. while(1) { char c = pc.getc(); - // Read temperature and pressure from MPL3115A2. - if (c == 'j') - { - pc.printf("You entered: j\r\n"); + if( c == 'j') { + printf("joining network\r\n"); if (at.send("AT+JOIN") && at.recv("OK")) - { - pc.printf("Joined Network!\n\r"); - } - + pc.printf("Joined Network!\r\n"); } + // Read temperature and pressure from MPL3115A2. + if (c == 'e') { at.flush(); @@ -71,39 +71,35 @@ 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\n\r"); + //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"); //convert doubles to string - sprintf(tempBuff, "%lf", temp); - sprintf(presBuff, "%lf", pres); - sprintf(sendcommand, "%s", "AT+SEND="); + //sprintf(tempBuff, "%lf", temp); + //sprintf(presBuff, "%lf", pres); + //sprintf(sendcommand, "%s", "AT+SEND="); string *command; - *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"); + //*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=20,200") && at.recv("OK")) - pc.printf("Temp & Pres Sent!\n\r"); - wait(2); + if (at.send("AT+SEND=20200") && at.recv("OK")) + pc.printf("Temp & Pres Sent!\r\n"); + else + pc.printf("didnt send\r\n"); - //free(tempBuff); - //free(presBuff); - //free(command); - at.flush(); - - //c.printf("%s\r\n", command); /*&& at.recv("OK"))*/ - - //pc.printf("temp and pres sent\n\r"); + wait(2); } + + at.flush(); } return(0);