Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ATParser MPL3115A2 TSL2561 mbed
main.cpp@7:bcd2b2b61d9a, 2018-04-28 (annotated)
- Committer:
- kmhatre
- Date:
- Sat Apr 28 00:42:00 2018 +0000
- Revision:
- 7:bcd2b2b61d9a
- Parent:
- 6:e7d266de146a
- Child:
- 8:dcd0c552a32d
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); |
dgutsch | 4:44e43da30b0e | 16 | TSL2561 light_sensor(PB_7, PB_6); // addr: 0x29 since addr is groundedx |
kmhatre | 7:bcd2b2b61d9a | 17 | MPL3115A2 pressure_sensor(PB_7,PB_6,0x60); |
jkrzesni | 0:53659b13e448 | 18 | |
dgutsch | 6:e7d266de146a | 19 | |
dgutsch | 6:e7d266de146a | 20 | |
dgutsch | 6:e7d266de146a | 21 | int main() { |
kmhatre | 7:bcd2b2b61d9a | 22 | char s; |
jkrzesni | 0:53659b13e448 | 23 | pc.baud(115200); |
jkrzesni | 0:53659b13e448 | 24 | dev.baud(115200); |
jkrzesni | 0:53659b13e448 | 25 | |
jkrzesni | 0:53659b13e448 | 26 | ATParser at = ATParser(dev, "\r\n"); |
jkrzesni | 0:53659b13e448 | 27 | |
kmhatre | 7:bcd2b2b61d9a | 28 | printf("Program Started\n\r"); |
dgutsch | 6:e7d266de146a | 29 | while(1) { |
kmhatre | 7:bcd2b2b61d9a | 30 | s = pc.getc(); |
kmhatre | 7:bcd2b2b61d9a | 31 | pc.putc(s); |
dgutsch | 3:6494a5d6f2ba | 32 | |
dgutsch | 6:e7d266de146a | 33 | |
kmhatre | 7:bcd2b2b61d9a | 34 | pc.printf("\n\rConnecting Lora\n\r"); |
kmhatre | 7:bcd2b2b61d9a | 35 | if (at.send("AT")) { |
kmhatre | 7:bcd2b2b61d9a | 36 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 37 | pc.printf("Lora Device Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 38 | } |
kmhatre | 7:bcd2b2b61d9a | 39 | else { |
kmhatre | 7:bcd2b2b61d9a | 40 | pc.printf("Lora Device NOT Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 41 | } |
kmhatre | 7:bcd2b2b61d9a | 42 | } |
kmhatre | 7:bcd2b2b61d9a | 43 | if (at.send("AT+NI=1,MTCDT-19400691")) { |
kmhatre | 7:bcd2b2b61d9a | 44 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 45 | pc.printf("Network ID Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 46 | } |
kmhatre | 7:bcd2b2b61d9a | 47 | else { |
kmhatre | 7:bcd2b2b61d9a | 48 | pc.printf("Network ID NOT Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 49 | } |
kmhatre | 7:bcd2b2b61d9a | 50 | } |
kmhatre | 7:bcd2b2b61d9a | 51 | if (at.send("AT+NK=1,MTCDT-19400691")) { |
kmhatre | 7:bcd2b2b61d9a | 52 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 53 | pc.printf("Network Key Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 54 | } |
kmhatre | 7:bcd2b2b61d9a | 55 | else { |
kmhatre | 7:bcd2b2b61d9a | 56 | pc.printf("Network Key NOT Working\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 57 | } |
kmhatre | 7:bcd2b2b61d9a | 58 | } |
kmhatre | 7:bcd2b2b61d9a | 59 | if (at.send("AT+FSB=1")) { |
kmhatre | 7:bcd2b2b61d9a | 60 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 61 | pc.printf("Frequency Sub Band set to 1\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 62 | } |
kmhatre | 7:bcd2b2b61d9a | 63 | else { |
kmhatre | 7:bcd2b2b61d9a | 64 | pc.printf("Frequency Sub Band NOT set\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 65 | } |
kmhatre | 7:bcd2b2b61d9a | 66 | } |
kmhatre | 7:bcd2b2b61d9a | 67 | if (at.send("AT+JOIN")) { |
kmhatre | 7:bcd2b2b61d9a | 68 | if(at.recv("OK")){ |
kmhatre | 7:bcd2b2b61d9a | 69 | pc.printf("Successfully joined network\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 70 | } |
kmhatre | 7:bcd2b2b61d9a | 71 | else { |
kmhatre | 7:bcd2b2b61d9a | 72 | pc.printf("ERROR Unable to join Network\r\n"); |
kmhatre | 7:bcd2b2b61d9a | 73 | } |
kmhatre | 7:bcd2b2b61d9a | 74 | } |
kmhatre | 7:bcd2b2b61d9a | 75 | if (s == 's') { |
kmhatre | 7:bcd2b2b61d9a | 76 | float temp = pressure_sensor.getTemperature(); |
kmhatre | 7:bcd2b2b61d9a | 77 | float pres = pressure_sensor.getAltitude(); |
kmhatre | 7:bcd2b2b61d9a | 78 | pc.printf("%f %f\n\r", temp, pres); |
kmhatre | 7:bcd2b2b61d9a | 79 | at.send("AT+SEND=%3.2f %3.2f"); |
kmhatre | 7:bcd2b2b61d9a | 80 | } |
kmhatre | 7:bcd2b2b61d9a | 81 | |
kmhatre | 7:bcd2b2b61d9a | 82 | while(1) { |
kmhatre | 7:bcd2b2b61d9a | 83 | float temp = pressure_sensor.getTemperature(); |
kmhatre | 7:bcd2b2b61d9a | 84 | float pres = pressure_sensor.getAltitude(); |
kmhatre | 7:bcd2b2b61d9a | 85 | pc.printf("%f %f\n\r", temp, pres); |
kmhatre | 7:bcd2b2b61d9a | 86 | at.send("AT+SEND=%3.2f %3.2f"); |
kmhatre | 7:bcd2b2b61d9a | 87 | wait(1); |
dgutsch | 6:e7d266de146a | 88 | } |
dgutsch | 6:e7d266de146a | 89 | } |
kmhatre | 7:bcd2b2b61d9a | 90 | } |