CPS_Lab*
/
Lab9
initial
main.cpp@4:e0e55d90dbae, 2018-04-10 (annotated)
- Committer:
- youngs2
- Date:
- Tue Apr 10 20:08:34 2018 +0000
- Revision:
- 4:e0e55d90dbae
- Parent:
- 3:b0a68b7daedb
lab 9 final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
youngs2 | 0:d382db2d4a0f | 1 | #include "mbed.h" |
youngs2 | 0:d382db2d4a0f | 2 | #include "ATParser.h" |
youngs2 | 2:cc9dffa51350 | 3 | #include "MPL3115A2.h" |
youngs2 | 2:cc9dffa51350 | 4 | #include <string.h> |
youngs2 | 2:cc9dffa51350 | 5 | #include <stdlib.h> |
youngs2 | 0:d382db2d4a0f | 6 | |
youngs2 | 1:1c928ac1083f | 7 | BufferedSerial pc(SERIAL_TX, SERIAL_RX); |
youngs2 | 1:1c928ac1083f | 8 | BufferedSerial device(PA_9, PA_10); // tx, rx |
youngs2 | 0:d382db2d4a0f | 9 | DigitalOut myled(LED1); |
youngs2 | 2:cc9dffa51350 | 10 | MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); |
youngs2 | 2:cc9dffa51350 | 11 | |
youngs2 | 3:b0a68b7daedb | 12 | //This program will be called when an s is typed |
youngs2 | 3:b0a68b7daedb | 13 | //in screen |
youngs2 | 3:b0a68b7daedb | 14 | |
youngs2 | 3:b0a68b7daedb | 15 | //This program will ultimately call itself every hour |
youngs2 | 3:b0a68b7daedb | 16 | |
youngs2 | 0:d382db2d4a0f | 17 | |
youngs2 | 1:1c928ac1083f | 18 | int main() |
youngs2 | 0:d382db2d4a0f | 19 | { |
youngs2 | 1:1c928ac1083f | 20 | pc.baud(115200); |
youngs2 | 1:1c928ac1083f | 21 | device.baud(115200); |
youngs2 | 1:1c928ac1083f | 22 | pc.printf("Hola\n\r"); |
youngs2 | 1:1c928ac1083f | 23 | ATParser at = ATParser(device, "\n\r", 256, 2000, false); |
youngs2 | 1:1c928ac1083f | 24 | if(at.send("AT") && at.recv("\n\r")) |
youngs2 | 1:1c928ac1083f | 25 | { |
youngs2 | 1:1c928ac1083f | 26 | pc.printf("Bueno#1\n\r"); |
youngs2 | 1:1c928ac1083f | 27 | myled = !myled; |
youngs2 | 1:1c928ac1083f | 28 | } |
youngs2 | 1:1c928ac1083f | 29 | else |
youngs2 | 1:1c928ac1083f | 30 | pc.printf("Nope#1\n\r"); |
youngs2 | 3:b0a68b7daedb | 31 | if(at.send("AT+NI=1,MTCDT-19400691") && 1) |
youngs2 | 1:1c928ac1083f | 32 | pc.printf("Bueno#2\n\r"); |
youngs2 | 1:1c928ac1083f | 33 | else |
youngs2 | 3:b0a68b7daedb | 34 | pc.printf("Nope#2\n\r"); |
youngs2 | 3:b0a68b7daedb | 35 | if(at.send("AT+NK=1,MTCDT-19400691") && 1) |
youngs2 | 2:cc9dffa51350 | 36 | pc.printf("Bueno #3\n\r"); |
youngs2 | 2:cc9dffa51350 | 37 | else |
youngs2 | 2:cc9dffa51350 | 38 | pc.printf("Nope #3\n\r"); |
youngs2 | 3:b0a68b7daedb | 39 | if(at.send("AT+FSB=1") && 1) |
youngs2 | 2:cc9dffa51350 | 40 | pc.printf("Bueno #4\n\r"); |
youngs2 | 2:cc9dffa51350 | 41 | else |
youngs2 | 2:cc9dffa51350 | 42 | pc.printf("Nope #4\n\r"); |
youngs2 | 3:b0a68b7daedb | 43 | if(at.send("AT+JOIN")&& 1) |
youngs2 | 2:cc9dffa51350 | 44 | pc.printf("Bueno #5\n\r"); |
youngs2 | 2:cc9dffa51350 | 45 | else |
youngs2 | 2:cc9dffa51350 | 46 | pc.printf("Nope #5\n\r"); |
youngs2 | 3:b0a68b7daedb | 47 | |
youngs2 | 3:b0a68b7daedb | 48 | char devID[24]; |
youngs2 | 3:b0a68b7daedb | 49 | if(at.send("AT+DI") && at.recv("%s\r\n\r\nOK", &devID)) |
youngs2 | 2:cc9dffa51350 | 50 | pc.printf("Bueno#6\n\r"); |
youngs2 | 2:cc9dffa51350 | 51 | else |
youngs2 | 2:cc9dffa51350 | 52 | pc.printf("Nope #6\n\r"); |
youngs2 | 4:e0e55d90dbae | 53 | while(1) |
youngs2 | 4:e0e55d90dbae | 54 | { |
youngs2 | 4:e0e55d90dbae | 55 | double pressure = pressure_sensor.getPressure(); |
youngs2 | 4:e0e55d90dbae | 56 | double temperature = pressure_sensor.getTemperature(); |
youngs2 | 4:e0e55d90dbae | 57 | //pc.printf("temp = %lf\n\r", temperature); |
youngs2 | 4:e0e55d90dbae | 58 | //pc.printf("pressure = %lf\n\r", pressure); |
youngs2 | 4:e0e55d90dbae | 59 | char temp[5]; |
youngs2 | 4:e0e55d90dbae | 60 | char press[6]; |
youngs2 | 4:e0e55d90dbae | 61 | int n; |
youngs2 | 4:e0e55d90dbae | 62 | n = sprintf(temp, "%.2lf", temperature); |
youngs2 | 4:e0e55d90dbae | 63 | n = sprintf(press, "%.2lf", pressure); |
youngs2 | 4:e0e55d90dbae | 64 | //pc.printf("Transfer worked: %s\n\r", press); |
youngs2 | 4:e0e55d90dbae | 65 | if(at.send("AT+SEND=\"%s\"", temp) && 1) |
youngs2 | 4:e0e55d90dbae | 66 | pc.printf("sent temp\n\r"); |
youngs2 | 4:e0e55d90dbae | 67 | else |
youngs2 | 4:e0e55d90dbae | 68 | pc.printf("didn't send temp #7\n\r"); |
youngs2 | 4:e0e55d90dbae | 69 | if(at.send("AT+SEND=\"%s\"", press) && 1) |
youngs2 | 4:e0e55d90dbae | 70 | pc.printf("sent pressure\n\r"); |
youngs2 | 4:e0e55d90dbae | 71 | else |
youngs2 | 4:e0e55d90dbae | 72 | pc.printf("didn't send pressure\n\r"); |
youngs2 | 4:e0e55d90dbae | 73 | wait(3600); |
youngs2 | 4:e0e55d90dbae | 74 | } |
youngs2 | 0:d382db2d4a0f | 75 | } |
youngs2 | 0:d382db2d4a0f | 76 | |
youngs2 | 1:1c928ac1083f | 77 | /* |
youngs2 | 2:cc9dffa51350 | 78 | Bryce code for getting Device ID |
youngs2 | 1:1c928ac1083f | 79 | memset(address, 0, 100); |
youngs2 | 1:1c928ac1083f | 80 | len = at.read(address, 100) |
youngs2 | 1:1c928ac1083f | 81 | for(i = 0; i < len; i++) |
youngs2 | 1:1c928ac1083f | 82 | { |
youngs2 | 1:1c928ac1083f | 83 | if(!address[i]); |
youngs2 | 1:1c928ac1083f | 84 | else if(address[i] >= '0') printf("%c\n\r",address[i]); |
youngs2 | 1:1c928ac1083f | 85 | else if(address[i]=='\n') printf("\\n\n\r", address[i]); |
youngs2 | 1:1c928ac1083f | 86 | else if(address[i]=='\r') printf("\\r\n\r", address[i]); |
youngs2 | 0:d382db2d4a0f | 87 | } |
youngs2 | 1:1c928ac1083f | 88 | */ |