Dependencies:   mbed

Committer:
dmjanke
Date:
Mon Nov 24 22:16:33 2014 +0000
Revision:
5:f453130cd6a7
Parent:
4:ad889da9578c
Child:
6:2ccd786cadd0
Demo working.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dmjanke 5:f453130cd6a7 1
Vanger 0:d9fd19c8ca39 2 #include "mbed.h"
Vanger 0:d9fd19c8ca39 3 #include "mtsas.h"
Vanger 0:d9fd19c8ca39 4
dmjanke 5:f453130cd6a7 5 DigitalOut heater(A1);
dmjanke 5:f453130cd6a7 6 AnalogIn sensor(A0);
dmjanke 5:f453130cd6a7 7 DigitalIn button(D5);
dmjanke 5:f453130cd6a7 8
dmjanke 5:f453130cd6a7 9 int main(void)
dmjanke 5:f453130cd6a7 10 {
dmjanke 5:f453130cd6a7 11 printf("Breathalizer Starting ...\n\r");
Vanger 3:7fac2f012338 12
Vanger 3:7fac2f012338 13 //Sets the log level to INFO, higher log levels produce more log output.
Vanger 3:7fac2f012338 14 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Vanger 1:1f5c9497a125 15 MTSLog::setLogLevel(MTSLog::INFO_LEVEL);
dmjanke 5:f453130cd6a7 16
Vanger 0:d9fd19c8ca39 17 //Modify to match your apn if you are using an HSPA radio with a SIM card
dmjanke 5:f453130cd6a7 18 const char APN[] = "dynamic.dcnm2m.com";
dmjanke 5:f453130cd6a7 19
Vanger 1:1f5c9497a125 20 //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx"
dmjanke 5:f453130cd6a7 21 string PHONE_NUMBER = "17632181696";
dmjanke 5:f453130cd6a7 22
Vanger 1:1f5c9497a125 23 Cellular::Sms txtmsg;
Vanger 1:1f5c9497a125 24 txtmsg.phoneNumber = PHONE_NUMBER;
dmjanke 5:f453130cd6a7 25 txtmsg.message = "HeyBoss, just sending SMS messages with my MTSAS. No Biggie.-Max";
Vanger 0:d9fd19c8ca39 26
Vanger 0:d9fd19c8ca39 27 /** STMicro Nucelo F401RE
Vanger 0:d9fd19c8ca39 28 * The supported jumper configurations of the MTSAS do not line up with
Vanger 0:d9fd19c8ca39 29 * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
Vanger 0:d9fd19c8ca39 30 * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
Vanger 0:d9fd19c8ca39 31 * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
Vanger 0:d9fd19c8ca39 32 * Serial1 TX (Shield pin D8).
Vanger 0:d9fd19c8ca39 33 * Uncomment the following line to use the STMicro Nuceleo F401RE
Vanger 0:d9fd19c8ca39 34 */
Vanger 0:d9fd19c8ca39 35 MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
dmjanke 5:f453130cd6a7 36
Vanger 0:d9fd19c8ca39 37 /** Freescale KL46Z
Vanger 4:ad889da9578c 38 * To configure the serial pins for the Freescale KL46Z board, use MTSAS jumper
Vanger 4:ad889da9578c 39 * configuration B. Uncomment the following line to use the Freescale KL46Z board
Vanger 0:d9fd19c8ca39 40 */
Vanger 0:d9fd19c8ca39 41 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
dmjanke 5:f453130cd6a7 42
Vanger 3:7fac2f012338 43 /** Freescale K64F
Vanger 4:ad889da9578c 44 * To configure the serial pins for the Freescale K64F board, use MTSAS jumper
Vanger 4:ad889da9578c 45 * configuration A. Uncomment the following line to use the Freescale K64F board
Vanger 0:d9fd19c8ca39 46 */
Vanger 0:d9fd19c8ca39 47 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
dmjanke 5:f453130cd6a7 48
dmjanke 5:f453130cd6a7 49
Vanger 4:ad889da9578c 50 //Sets the baud rate for communicating with the radio
Vanger 0:d9fd19c8ca39 51 io->baud(115200);
Vanger 0:d9fd19c8ca39 52
Vanger 2:d0d6e939ba70 53 //Creates a radio object
Vanger 0:d9fd19c8ca39 54 Cellular* radio = CellularFactory::create(io);
Vanger 2:d0d6e939ba70 55
Vanger 3:7fac2f012338 56 if (! radio) {
Vanger 3:7fac2f012338 57 logFatal("Failed to initialize radio");
Vanger 3:7fac2f012338 58 return 1;
Vanger 3:7fac2f012338 59 }
Vanger 3:7fac2f012338 60
dmjanke 5:f453130cd6a7 61 //Commenting out next line. D4, D7, or RESET may be overlapping A0 Sensor Input
dmjanke 5:f453130cd6a7 62 //radio->configureSignals(D4,D7,RESET);
dmjanke 5:f453130cd6a7 63
Vanger 4:ad889da9578c 64 Transport::setTransport(radio);
Vanger 4:ad889da9578c 65
Vanger 2:d0d6e939ba70 66 //Set radio APN
dmjanke 5:f453130cd6a7 67 printf("Setting APN [%s]\r\n", APN);
Vanger 1:1f5c9497a125 68 for (int i = 0; i < 10; i++) {
Vanger 1:1f5c9497a125 69 if (i >= 10) {
Vanger 1:1f5c9497a125 70 logError("Failed to set APN\n");
Vanger 1:1f5c9497a125 71 }
Vanger 1:1f5c9497a125 72 if (radio->setApn(APN) == MTS_SUCCESS) {
Vanger 1:1f5c9497a125 73 logInfo("Successfully set APN\n");
Vanger 1:1f5c9497a125 74 break;
Vanger 1:1f5c9497a125 75 } else {
Vanger 1:1f5c9497a125 76 wait(1);
Vanger 1:1f5c9497a125 77 }
Vanger 1:1f5c9497a125 78 }
Vanger 0:d9fd19c8ca39 79
dmjanke 5:f453130cd6a7 80 float value = 0.0f;
dmjanke 5:f453130cd6a7 81 heater = 0; //Active Low, 0 is turning it on.
dmjanke 5:f453130cd6a7 82 wait(0.1f);
dmjanke 5:f453130cd6a7 83
dmjanke 5:f453130cd6a7 84 // Waiting for the sensor to warm-up
dmjanke 5:f453130cd6a7 85 while(value > 0.001f) {
dmjanke 5:f453130cd6a7 86 wait(1.0f);
dmjanke 5:f453130cd6a7 87 value = 1.0f - sensor;
dmjanke 5:f453130cd6a7 88 printf("Sensor is: %2.2f\r\n", value);
Vanger 1:1f5c9497a125 89 }
dmjanke 5:f453130cd6a7 90
dmjanke 5:f453130cd6a7 91 printf("Sensor is warmed up!!! :-) \r\n");
dmjanke 5:f453130cd6a7 92
dmjanke 5:f453130cd6a7 93 while(1) {
dmjanke 5:f453130cd6a7 94 while(!button) {
dmjanke 5:f453130cd6a7 95 //Do Nothing
Vanger 1:1f5c9497a125 96 }
dmjanke 5:f453130cd6a7 97 printf("3\r\n");
dmjanke 5:f453130cd6a7 98 wait(1.0f);
dmjanke 5:f453130cd6a7 99 printf("2\r\n");
dmjanke 5:f453130cd6a7 100 wait(1.0f);
dmjanke 5:f453130cd6a7 101 printf("1\r\n");
dmjanke 5:f453130cd6a7 102 wait(1.0f);
dmjanke 5:f453130cd6a7 103 printf("BLOW!!!! :-)");
dmjanke 5:f453130cd6a7 104 wait(3.0f);
dmjanke 5:f453130cd6a7 105 value = 1.0f - sensor;
dmjanke 5:f453130cd6a7 106
dmjanke 5:f453130cd6a7 107 if (value > .8f) {
dmjanke 5:f453130cd6a7 108 txtmsg.message = "Get Uber Now! ;-)";
dmjanke 5:f453130cd6a7 109 } else if (value > .6f) {
dmjanke 5:f453130cd6a7 110 txtmsg.message = "Feeling Groovey";
dmjanke 5:f453130cd6a7 111 } else if (value > .4f) {
dmjanke 5:f453130cd6a7 112 txtmsg.message = "Have Another";
dmjanke 5:f453130cd6a7 113 } else {
dmjanke 5:f453130cd6a7 114 txtmsg.message = "Boooring";
dmjanke 5:f453130cd6a7 115 }
dmjanke 5:f453130cd6a7 116 printf("%s\n\r", txtmsg.message.c_str());
dmjanke 5:f453130cd6a7 117 printf("Sensor is: %2.2f\r\n", value);
dmjanke 5:f453130cd6a7 118
dmjanke 5:f453130cd6a7 119
dmjanke 5:f453130cd6a7 120 // Send SMS message to phone
dmjanke 5:f453130cd6a7 121 for (int i = 1; i < 10; i++) {
dmjanke 5:f453130cd6a7 122 if(radio->sendSMS(txtmsg) == MTS_SUCCESS) {
dmjanke 5:f453130cd6a7 123 logInfo("Sent SMS successfully:<%s>\n", txtmsg.message.c_str());
dmjanke 5:f453130cd6a7 124 break;
dmjanke 5:f453130cd6a7 125 } else {
dmjanke 5:f453130cd6a7 126 logError("Failed to send SMS<%s>\n", txtmsg.message.c_str());
Vanger 1:1f5c9497a125 127 }
Vanger 1:1f5c9497a125 128 }
Vanger 3:7fac2f012338 129
dmjanke 5:f453130cd6a7 130
Vanger 1:1f5c9497a125 131 }
Vanger 0:d9fd19c8ca39 132 }