initial

Dependencies:   ATParser mbed

Committer:
youngs2
Date:
Thu Apr 05 23:40:03 2018 +0000
Revision:
2:cc9dffa51350
Parent:
1:1c928ac1083f
Child:
3:b0a68b7daedb
initial #3

Who changed what in which revision?

UserRevisionLine numberNew 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 2:cc9dffa51350 12 //This program will be called when the python script tells it to
youngs2 0:d382db2d4a0f 13
youngs2 1:1c928ac1083f 14 int main()
youngs2 0:d382db2d4a0f 15 {
youngs2 1:1c928ac1083f 16 pc.baud(115200);
youngs2 1:1c928ac1083f 17 device.baud(115200);
youngs2 1:1c928ac1083f 18 pc.printf("Hola\n\r");
youngs2 1:1c928ac1083f 19 ATParser at = ATParser(device, "\n\r", 256, 2000, false);
youngs2 1:1c928ac1083f 20 if(at.send("AT") && at.recv("\n\r"))
youngs2 1:1c928ac1083f 21 {
youngs2 1:1c928ac1083f 22 pc.printf("Bueno#1\n\r");
youngs2 1:1c928ac1083f 23 myled = !myled;
youngs2 1:1c928ac1083f 24 }
youngs2 1:1c928ac1083f 25 else
youngs2 1:1c928ac1083f 26 pc.printf("Nope#1\n\r");
youngs2 1:1c928ac1083f 27 if(at.send("AT+NI=1,MTCDT-19400691")
youngs2 1:1c928ac1083f 28 && at.recv("Set Network Name: MTCDT-19400691")
youngs2 1:1c928ac1083f 29 /*&& at.recv("\n\r")*/
youngs2 1:1c928ac1083f 30 && at.recv("OK"))
youngs2 1:1c928ac1083f 31 pc.printf("Bueno#2\n\r");
youngs2 1:1c928ac1083f 32 else
youngs2 2:cc9dffa51350 33 pc.printf("Nope#2\n\r");
youngs2 2:cc9dffa51350 34 /*
youngs2 2:cc9dffa51350 35 if(at.send("AT+NK=1,MTCDT-19400691")
youngs2 2:cc9dffa51350 36 && at.recv("Set Network Passphrase: MTCDT-19400691")
youngs2 2:cc9dffa51350 37 && at.recv("\n\r")
youngs2 2:cc9dffa51350 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 2:cc9dffa51350 42 if(at.send("AT+FSB=1") && at.recv("\n\r")
youngs2 2:cc9dffa51350 43 && at.recv("OK"))
youngs2 2:cc9dffa51350 44 pc.printf("Bueno #4\n\r");
youngs2 2:cc9dffa51350 45 else
youngs2 2:cc9dffa51350 46 pc.printf("Nope #4\n\r");
youngs2 2:cc9dffa51350 47 //If in doubt try \r\n (found in library)
youngs2 2:cc9dffa51350 48 if(at.send("AT+JOIN")
youngs2 2:cc9dffa51350 49 && at.recv("Successfully joined network\n\rOK")
youngs2 2:cc9dffa51350 50 pc.printf("Bueno #5\n\r");
youngs2 2:cc9dffa51350 51 else
youngs2 2:cc9dffa51350 52 pc.printf("Nope #5\n\r");
youngs2 2:cc9dffa51350 53 char devID[23];
youngs2 2:cc9dffa51350 54 if(at.send("AT+DI") && at.recv("%s\n\rOK", devID))
youngs2 2:cc9dffa51350 55 pc.printf("Bueno#6\n\r");
youngs2 2:cc9dffa51350 56 else
youngs2 2:cc9dffa51350 57 pc.printf("Nope #6\n\r");
youngs2 2:cc9dffa51350 58 */
youngs2 2:cc9dffa51350 59
youngs2 2:cc9dffa51350 60 double pressure = pressure_sensor.getPressure();
youngs2 2:cc9dffa51350 61 double altitude = pressure_sensor.getAltitude();
youngs2 2:cc9dffa51350 62 double temperature = pressure_sensor.getTemperature();
youngs2 2:cc9dffa51350 63 //subscribe to
youngs2 2:cc9dffa51350 64 //Write these 3 numbers to device (xdot)
youngs2 2:cc9dffa51350 65 //have xdot publish these to the server
youngs2 1:1c928ac1083f 66 while(1);
youngs2 0:d382db2d4a0f 67 }
youngs2 0:d382db2d4a0f 68
youngs2 2:cc9dffa51350 69
youngs2 2:cc9dffa51350 70
youngs2 2:cc9dffa51350 71
youngs2 2:cc9dffa51350 72
youngs2 2:cc9dffa51350 73
youngs2 2:cc9dffa51350 74
youngs2 2:cc9dffa51350 75
youngs2 2:cc9dffa51350 76
youngs2 2:cc9dffa51350 77
youngs2 2:cc9dffa51350 78
youngs2 2:cc9dffa51350 79
youngs2 2:cc9dffa51350 80
youngs2 2:cc9dffa51350 81
youngs2 1:1c928ac1083f 82 /*
youngs2 2:cc9dffa51350 83 Bryce code for getting Device ID
youngs2 1:1c928ac1083f 84 memset(address, 0, 100);
youngs2 1:1c928ac1083f 85 len = at.read(address, 100)
youngs2 1:1c928ac1083f 86 for(i = 0; i < len; i++)
youngs2 1:1c928ac1083f 87 {
youngs2 1:1c928ac1083f 88 if(!address[i]);
youngs2 1:1c928ac1083f 89 else if(address[i] >= '0') printf("%c\n\r",address[i]);
youngs2 1:1c928ac1083f 90 else if(address[i]=='\n') printf("\\n\n\r", address[i]);
youngs2 1:1c928ac1083f 91 else if(address[i]=='\r') printf("\\r\n\r", address[i]);
youngs2 0:d382db2d4a0f 92 }
youngs2 1:1c928ac1083f 93 */