rgjefklgf
Dependencies: mbed ATParser MPL3115A2 TSL2561
Diff: main.cpp
- Revision:
- 2:10a9331f04e2
- Parent:
- 1:731cbdf8e672
- Child:
- 3:6494a5d6f2ba
diff -r 731cbdf8e672 -r 10a9331f04e2 main.cpp --- a/main.cpp Fri Apr 06 16:55:50 2018 +0000 +++ b/main.cpp Sat Apr 07 23:33:03 2018 +0000 @@ -28,40 +28,80 @@ // Set network name and passphrase if (at.send("AT+NI=1,MTCDT-19400691") && at.recv("OK")) - pc.printf("Network ID specified"); + pc.printf("Network ID specified\n\r"); 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!"); + pc.printf("Joined Network!\n\r"); // Set pressure sensor to read in units of mbar & celcius pressure_sensor.setCTRL_REG1(0xA1); char tempBuff[20]; char presBuff[20]; - + char sendcommand[50] = "AT+SEND="; + pc.printf("Awaiting Commands."); // Wait for "s" string from console serial input. - while(1) { + while(1) + { + char c = pc.getc(); + // Read temperature and pressure from MPL3115A2. - if (pc.getc() == 's') + if (c == 'j') { - //pc.printf("send pressure and temp\n\r"); + pc.printf("You entered: j\r\n"); + if (at.send("AT+JOIN") && at.recv("OK")) + { + pc.printf("Joined Network!\n\r"); + } + + } + + if (c == 'e') + { + at.flush(); + pc.printf("Exiting Program\r\n"); + return(0); + } + + if (c == 's') + { + pc.printf("You entered: s\r\n"); // Force XDot to send temperature and pressure to MQTT server - temp = pressure_sensor.getTemperature(); + + temp = pressure_sensor.getTemperature(); pres = pressure_sensor.getAltitude(); - wait(2); + pc.printf("temperature: %d\r\n", temp); + pc.printf("pressure: %\r\nd", pres); + pc.printf("Temperature and Pressure Read\n\r"); + //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"); + 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"); + + + //if (at.send("AT+SEND=20,200") && at.recv("OK")) + pc.printf("Temp & Pres Sent!\n\r"); + wait(2); + + //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"); }