rgjefklgf
Dependencies: mbed ATParser MPL3115A2 TSL2561
Diff: main.cpp
- Revision:
- 1:731cbdf8e672
- Parent:
- 0:53659b13e448
- Child:
- 2:10a9331f04e2
--- a/main.cpp Thu Apr 05 14:55:49 2018 +0000 +++ b/main.cpp Fri Apr 06 16:55:50 2018 +0000 @@ -1,16 +1,21 @@ #include "mbed.h" #include "ATParser.h" #include "MPL3115A2.h" +#include <string> +#include <iostream> + +//#include <Serial.h> MPL3115A2 pressure_sensor(PB_7, PB_6, 0x60); BufferedSerial pc(SERIAL_TX, SERIAL_RX); BufferedSerial dev(PA_9, PA_10); DigitalOut myled(LED1); +using namespace std; + int main() { + double temp, pres; - char address[100]; - char len; pc.baud(115200); dev.baud(115200); @@ -21,17 +26,45 @@ if (at.send("AT") && at.recv("OK")) pc.printf("AT Communication Success\n\r"); - // Set pressure sensor to read in units of ??????? - pressure_sensor.setCTRL_REG1( 0xA1 ); + // Set network name and passphrase + if (at.send("AT+NI=1,MTCDT-19400691") && at.recv("OK")) + pc.printf("Network ID specified"); + 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!"); + + // Set pressure sensor to read in units of mbar & celcius + pressure_sensor.setCTRL_REG1(0xA1); + + char tempBuff[20]; + char presBuff[20]; + // Wait for "s" string from console serial input. while(1) { // Read temperature and pressure from MPL3115A2. - if (pc.getc() == "s") + if (pc.getc() == 's') { - // Force XDot to send to MQTT server + //pc.printf("send pressure and temp\n\r"); + // Force XDot to send temperature and pressure to MQTT server temp = pressure_sensor.getTemperature(); pres = pressure_sensor.getAltitude(); + wait(2); + + //convert doubles to string + sprintf(tempBuff, "%lf", temp); + sprintf(presBuff, "%lf", pres); + + //printf("%s %s\r\n", tempBuff,presBuff); + string command = strcat("AT+SEND=", strcat(tempBuff, strcat(strcat(",", presBuff), "\r\n"))); + pc.printf("%s\r\n", command); /*&& at.recv("OK"))*/ + //at.send("AT+SEND=" + tempBuff + "," + presBuff); /*&& at.recv("OK"))*/ + pc.printf("temp and pres sent\n\r"); + } - - \ No newline at end of file + + } + return(0); +} \ No newline at end of file