lab9
Dependencies: ATParser MPL3115A2 TSL2561 mbed
main.cpp@10:ce4aadfeeb7d, 2018-04-28 (annotated)
- Committer:
- kmhatre
- Date:
- Sat Apr 28 00:56:22 2018 +0000
- Revision:
- 10:ce4aadfeeb7d
- Parent:
- 9:c1416b2f865b
lab9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jkrzesni | 0:53659b13e448 | 1 | #include "mbed.h" |
jkrzesni | 0:53659b13e448 | 2 | #include "ATParser.h" |
dgutsch | 6:e7d266de146a | 3 | #include "TSL2561.h" |
jkrzesni | 0:53659b13e448 | 4 | #include "MPL3115A2.h" |
jkrzesni | 1:731cbdf8e672 | 5 | #include <string> |
dgutsch | 6:e7d266de146a | 6 | #include <algorithm> |
jkrzesni | 1:731cbdf8e672 | 7 | #include <iostream> |
jkrzesni | 1:731cbdf8e672 | 8 | |
dgutsch | 3:6494a5d6f2ba | 9 | |
dgutsch | 3:6494a5d6f2ba | 10 | |
jkrzesni | 0:53659b13e448 | 11 | |
kmhatre | 7:bcd2b2b61d9a | 12 | |
jkrzesni | 0:53659b13e448 | 13 | BufferedSerial pc(SERIAL_TX, SERIAL_RX); |
jkrzesni | 0:53659b13e448 | 14 | BufferedSerial dev(PA_9, PA_10); |
jkrzesni | 0:53659b13e448 | 15 | DigitalOut myled(LED1); |
kmhatre | 7:bcd2b2b61d9a | 16 | MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); |
jkrzesni | 0:53659b13e448 | 17 | |
dgutsch | 6:e7d266de146a | 18 | |
dgutsch | 6:e7d266de146a | 19 | |
dgutsch | 6:e7d266de146a | 20 | int main() { |
kmhatre | 7:bcd2b2b61d9a | 21 | char s; |
jkrzesni | 0:53659b13e448 | 22 | pc.baud(115200); |
jkrzesni | 0:53659b13e448 | 23 | dev.baud(115200); |
jkrzesni | 0:53659b13e448 | 24 | |
jkrzesni | 0:53659b13e448 | 25 | ATParser at = ATParser(dev, "\r\n"); |
jkrzesni | 0:53659b13e448 | 26 | |
kmhatre | 7:bcd2b2b61d9a | 27 | printf("Program Started\n\r"); |
dgutsch | 6:e7d266de146a | 28 | while(1) { |
kmhatre | 7:bcd2b2b61d9a | 29 | s = pc.getc(); |
kmhatre | 7:bcd2b2b61d9a | 30 | pc.putc(s); |
dgutsch | 3:6494a5d6f2ba | 31 | |
dgutsch | 6:e7d266de146a | 32 | |
kmhatre | 7:bcd2b2b61d9a | 33 | pc.printf("\n\rConnecting Lora\n\r"); |
kmhatre | 7:bcd2b2b61d9a | 34 | if (at.send("AT")) { |
kmhatre | 7:bcd2b2b61d9a | 35 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 36 | pc.printf("Lora Device Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 37 | } |
kmhatre | 7:bcd2b2b61d9a | 38 | else { |
kmhatre | 7:bcd2b2b61d9a | 39 | pc.printf("Lora Device NOT Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 40 | } |
kmhatre | 7:bcd2b2b61d9a | 41 | } |
kmhatre | 7:bcd2b2b61d9a | 42 | if (at.send("AT+NI=1,MTCDT-19400691")) { |
kmhatre | 7:bcd2b2b61d9a | 43 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 44 | pc.printf("Network ID Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 45 | } |
kmhatre | 7:bcd2b2b61d9a | 46 | else { |
kmhatre | 7:bcd2b2b61d9a | 47 | pc.printf("Network ID NOT Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 48 | } |
kmhatre | 7:bcd2b2b61d9a | 49 | } |
kmhatre | 7:bcd2b2b61d9a | 50 | if (at.send("AT+NK=1,MTCDT-19400691")) { |
kmhatre | 7:bcd2b2b61d9a | 51 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 52 | pc.printf("Network Key Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 53 | } |
kmhatre | 7:bcd2b2b61d9a | 54 | else { |
kmhatre | 7:bcd2b2b61d9a | 55 | pc.printf("Network Key NOT Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 56 | } |
kmhatre | 7:bcd2b2b61d9a | 57 | } |
kmhatre | 7:bcd2b2b61d9a | 58 | if (at.send("AT+FSB=1")) { |
kmhatre | 7:bcd2b2b61d9a | 59 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 60 | pc.printf("Frequency Sub Band set to 1\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 61 | } |
kmhatre | 7:bcd2b2b61d9a | 62 | else { |
kmhatre | 7:bcd2b2b61d9a | 63 | pc.printf("Frequency Sub Band NOT set\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 64 | } |
kmhatre | 7:bcd2b2b61d9a | 65 | } |
kmhatre | 7:bcd2b2b61d9a | 66 | if (at.send("AT+JOIN")) { |
kmhatre | 7:bcd2b2b61d9a | 67 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 68 | pc.printf("Successfully joined network\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 69 | } |
kmhatre | 7:bcd2b2b61d9a | 70 | else { |
kmhatre | 7:bcd2b2b61d9a | 71 | pc.printf("ERROR Unable to join Network\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 72 | } |
kmhatre | 7:bcd2b2b61d9a | 73 | } |
kmhatre | 7:bcd2b2b61d9a | 74 | if (s == 's') { |
kmhatre | 7:bcd2b2b61d9a | 75 | float temp = pressure_sensor.getTemperature(); |
kmhatre | 7:bcd2b2b61d9a | 76 | float pres = pressure_sensor.getAltitude(); |
kmhatre | 7:bcd2b2b61d9a | 77 | pc.printf("%f %f\n\r", temp, pres); |
kmhatre | 7:bcd2b2b61d9a | 78 | at.send("AT+SEND=%3.2f %3.2f"); |
kmhatre | 7:bcd2b2b61d9a | 79 | } |
kmhatre | 7:bcd2b2b61d9a | 80 | |
kmhatre | 7:bcd2b2b61d9a | 81 | while(1) { |
kmhatre | 7:bcd2b2b61d9a | 82 | float temp = pressure_sensor.getTemperature(); |
kmhatre | 7:bcd2b2b61d9a | 83 | float pres = pressure_sensor.getAltitude(); |
kmhatre | 7:bcd2b2b61d9a | 84 | pc.printf("%f %f\n\r", temp, pres); |
kmhatre | 10:ce4aadfeeb7d | 85 | at.send("AT+SEND=%3.2f %3.2f", temp, pres); |
kmhatre | 9:c1416b2f865b | 86 | wait(3600); |
dgutsch | 6:e7d266de146a | 87 | } |
dgutsch | 6:e7d266de146a | 88 | } |
kmhatre | 7:bcd2b2b61d9a | 89 | } |