CPS_Lab*
/
Lab9
initial
main.cpp@3:b0a68b7daedb, 2018-04-06 (annotated)
- Committer:
- youngs2
- Date:
- Fri Apr 06 16:55:48 2018 +0000
- Revision:
- 3:b0a68b7daedb
- Parent:
- 2:cc9dffa51350
- Child:
- 4:e0e55d90dbae
initial 4
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 | 3:b0a68b7daedb | 36 | //&& at.recv("Set Network Passphrase: MTCDT-19400691") |
youngs2 | 3:b0a68b7daedb | 37 | //&& at.recv("\n\r") |
youngs2 | 3:b0a68b7daedb | 38 | //&& at.recv("OK")) |
youngs2 | 2:cc9dffa51350 | 39 | pc.printf("Bueno #3\n\r"); |
youngs2 | 2:cc9dffa51350 | 40 | else |
youngs2 | 2:cc9dffa51350 | 41 | pc.printf("Nope #3\n\r"); |
youngs2 | 3:b0a68b7daedb | 42 | if(at.send("AT+FSB=1") && 1) |
youngs2 | 2:cc9dffa51350 | 43 | pc.printf("Bueno #4\n\r"); |
youngs2 | 2:cc9dffa51350 | 44 | else |
youngs2 | 2:cc9dffa51350 | 45 | pc.printf("Nope #4\n\r"); |
youngs2 | 3:b0a68b7daedb | 46 | if(at.send("AT+JOIN")&& 1) |
youngs2 | 2:cc9dffa51350 | 47 | pc.printf("Bueno #5\n\r"); |
youngs2 | 2:cc9dffa51350 | 48 | else |
youngs2 | 2:cc9dffa51350 | 49 | pc.printf("Nope #5\n\r"); |
youngs2 | 3:b0a68b7daedb | 50 | |
youngs2 | 3:b0a68b7daedb | 51 | char devID[24]; |
youngs2 | 3:b0a68b7daedb | 52 | if(at.send("AT+DI") && at.recv("%s\r\n\r\nOK", &devID)) |
youngs2 | 2:cc9dffa51350 | 53 | pc.printf("Bueno#6\n\r"); |
youngs2 | 2:cc9dffa51350 | 54 | else |
youngs2 | 2:cc9dffa51350 | 55 | pc.printf("Nope #6\n\r"); |
youngs2 | 3:b0a68b7daedb | 56 | |
youngs2 | 2:cc9dffa51350 | 57 | double pressure = pressure_sensor.getPressure(); |
youngs2 | 2:cc9dffa51350 | 58 | double temperature = pressure_sensor.getTemperature(); |
youngs2 | 3:b0a68b7daedb | 59 | |
youngs2 | 3:b0a68b7daedb | 60 | |
youngs2 | 3:b0a68b7daedb | 61 | pc.printf("temp = %lf\n\r", temperature); |
youngs2 | 3:b0a68b7daedb | 62 | pc.printf("pressure = %lf\n\r", pressure); |
youngs2 | 3:b0a68b7daedb | 63 | |
youngs2 | 3:b0a68b7daedb | 64 | char temp[9]; |
youngs2 | 3:b0a68b7daedb | 65 | char press[10]; |
youngs2 | 3:b0a68b7daedb | 66 | |
youngs2 | 3:b0a68b7daedb | 67 | int n; |
youngs2 | 3:b0a68b7daedb | 68 | |
youngs2 | 3:b0a68b7daedb | 69 | n = sprintf(temp, "%lf", temperature); |
youngs2 | 3:b0a68b7daedb | 70 | n = sprintf(press, "%lf", pressure); |
youngs2 | 3:b0a68b7daedb | 71 | pc.printf("It worked: %s\n\r", press); |
youngs2 | 3:b0a68b7daedb | 72 | /* |
youngs2 | 3:b0a68b7daedb | 73 | if(at.send("AT+SEND=\"%s\"", temp) && 1) |
youngs2 | 3:b0a68b7daedb | 74 | pc.printf("Bueno #7\n\r"); |
youngs2 | 3:b0a68b7daedb | 75 | else |
youngs2 | 3:b0a68b7daedb | 76 | pc.printf("Nope #7\n\r"); |
youngs2 | 3:b0a68b7daedb | 77 | */ |
youngs2 | 3:b0a68b7daedb | 78 | if(at.send("AT+SEND=\"%s\"",press) && 1) |
youngs2 | 3:b0a68b7daedb | 79 | pc.printf("Bueno #9\n\r"); |
youngs2 | 3:b0a68b7daedb | 80 | else |
youngs2 | 3:b0a68b7daedb | 81 | pc.printf("Nope #9\n\r"); |
youngs2 | 1:1c928ac1083f | 82 | while(1); |
youngs2 | 0:d382db2d4a0f | 83 | } |
youngs2 | 0:d382db2d4a0f | 84 | |
youngs2 | 2:cc9dffa51350 | 85 | |
youngs2 | 2:cc9dffa51350 | 86 | |
youngs2 | 2:cc9dffa51350 | 87 | |
youngs2 | 2:cc9dffa51350 | 88 | |
youngs2 | 2:cc9dffa51350 | 89 | |
youngs2 | 2:cc9dffa51350 | 90 | |
youngs2 | 2:cc9dffa51350 | 91 | |
youngs2 | 2:cc9dffa51350 | 92 | |
youngs2 | 2:cc9dffa51350 | 93 | |
youngs2 | 2:cc9dffa51350 | 94 | |
youngs2 | 2:cc9dffa51350 | 95 | |
youngs2 | 2:cc9dffa51350 | 96 | |
youngs2 | 2:cc9dffa51350 | 97 | |
youngs2 | 1:1c928ac1083f | 98 | /* |
youngs2 | 2:cc9dffa51350 | 99 | Bryce code for getting Device ID |
youngs2 | 1:1c928ac1083f | 100 | memset(address, 0, 100); |
youngs2 | 1:1c928ac1083f | 101 | len = at.read(address, 100) |
youngs2 | 1:1c928ac1083f | 102 | for(i = 0; i < len; i++) |
youngs2 | 1:1c928ac1083f | 103 | { |
youngs2 | 1:1c928ac1083f | 104 | if(!address[i]); |
youngs2 | 1:1c928ac1083f | 105 | else if(address[i] >= '0') printf("%c\n\r",address[i]); |
youngs2 | 1:1c928ac1083f | 106 | else if(address[i]=='\n') printf("\\n\n\r", address[i]); |
youngs2 | 1:1c928ac1083f | 107 | else if(address[i]=='\r') printf("\\r\n\r", address[i]); |
youngs2 | 0:d382db2d4a0f | 108 | } |
youngs2 | 1:1c928ac1083f | 109 | */ |