Latest mbed source and updated location for mtsas library. 2015-10-19
main.cpp@0:1683e80da94e, 2015-10-20 (annotated)
- Committer:
- BlueShadow
- Date:
- Tue Oct 20 00:49:12 2015 +0000
- Revision:
- 0:1683e80da94e
Latest mbed source and updated location for mtsas library. 2015-10-19
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BlueShadow | 0:1683e80da94e | 1 | |
BlueShadow | 0:1683e80da94e | 2 | #include "mbed.h" |
BlueShadow | 0:1683e80da94e | 3 | #include "mtsas.h" |
BlueShadow | 0:1683e80da94e | 4 | // #include "PubSubClient.h" |
BlueShadow | 0:1683e80da94e | 5 | |
BlueShadow | 0:1683e80da94e | 6 | //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx" |
BlueShadow | 0:1683e80da94e | 7 | string PHONE_NUMBER = "169524576179"; |
BlueShadow | 0:1683e80da94e | 8 | |
BlueShadow | 0:1683e80da94e | 9 | |
BlueShadow | 0:1683e80da94e | 10 | AnalogIn sensor(PC_2); //A0 pin on UDK |
BlueShadow | 0:1683e80da94e | 11 | DigitalIn button(PA_9); // D5 pin |
BlueShadow | 0:1683e80da94e | 12 | |
BlueShadow | 0:1683e80da94e | 13 | int main(void) |
BlueShadow | 0:1683e80da94e | 14 | { |
BlueShadow | 0:1683e80da94e | 15 | wait(15); |
BlueShadow | 0:1683e80da94e | 16 | printf("Moisture Meter Starting ...\n\r"); |
BlueShadow | 0:1683e80da94e | 17 | |
BlueShadow | 0:1683e80da94e | 18 | //Sets the log level to INFO, higher log levels produce more log output. |
BlueShadow | 0:1683e80da94e | 19 | //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE |
BlueShadow | 0:1683e80da94e | 20 | MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); |
BlueShadow | 0:1683e80da94e | 21 | |
BlueShadow | 0:1683e80da94e | 22 | Cellular::Sms txtmsg; |
BlueShadow | 0:1683e80da94e | 23 | txtmsg.phoneNumber = PHONE_NUMBER; |
BlueShadow | 0:1683e80da94e | 24 | |
BlueShadow | 0:1683e80da94e | 25 | if(PHONE_NUMBER == "CHANGE ME PLEASE") { |
BlueShadow | 0:1683e80da94e | 26 | while(1) { |
BlueShadow | 0:1683e80da94e | 27 | printf("FORGOT TO SET THE PHONE NUMBER\r\n"); |
BlueShadow | 0:1683e80da94e | 28 | wait(1.0f); |
BlueShadow | 0:1683e80da94e | 29 | } |
BlueShadow | 0:1683e80da94e | 30 | } |
BlueShadow | 0:1683e80da94e | 31 | |
BlueShadow | 0:1683e80da94e | 32 | /** STMicro Nucelo F411RE |
BlueShadow | 0:1683e80da94e | 33 | * The supported jumper configurations of the MTSAS do not line up with |
BlueShadow | 0:1683e80da94e | 34 | * the pin mapping of the Nucleo F411RE. Therefore, the MTSAS serial TX |
BlueShadow | 0:1683e80da94e | 35 | * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2) |
BlueShadow | 0:1683e80da94e | 36 | * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to |
BlueShadow | 0:1683e80da94e | 37 | * Serial1 TX (Shield pin D8). |
BlueShadow | 0:1683e80da94e | 38 | */ |
BlueShadow | 0:1683e80da94e | 39 | |
BlueShadow | 0:1683e80da94e | 40 | MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6); |
BlueShadow | 0:1683e80da94e | 41 | |
BlueShadow | 0:1683e80da94e | 42 | //Sets the baud rate for communicating with the radio |
BlueShadow | 0:1683e80da94e | 43 | io->baud(115200); |
BlueShadow | 0:1683e80da94e | 44 | |
BlueShadow | 0:1683e80da94e | 45 | //Creates a radio object |
BlueShadow | 0:1683e80da94e | 46 | Cellular* radio = CellularFactory::create(io); |
BlueShadow | 0:1683e80da94e | 47 | |
BlueShadow | 0:1683e80da94e | 48 | if (! radio) { |
BlueShadow | 0:1683e80da94e | 49 | logFatal("Failed to initialize radio"); |
BlueShadow | 0:1683e80da94e | 50 | return 1; |
BlueShadow | 0:1683e80da94e | 51 | } |
BlueShadow | 0:1683e80da94e | 52 | |
BlueShadow | 0:1683e80da94e | 53 | printf("ready to wait \r\n"); |
BlueShadow | 0:1683e80da94e | 54 | wait(2.0f); |
BlueShadow | 0:1683e80da94e | 55 | printf("Sensor is ready to read data!!! :-) \r\n"); |
BlueShadow | 0:1683e80da94e | 56 | float value =0.0f; |
BlueShadow | 0:1683e80da94e | 57 | while(1) { |
BlueShadow | 0:1683e80da94e | 58 | |
BlueShadow | 0:1683e80da94e | 59 | while(!button) { |
BlueShadow | 0:1683e80da94e | 60 | value = sensor; |
BlueShadow | 0:1683e80da94e | 61 | printf("Moisture level: %f \n",value); |
BlueShadow | 0:1683e80da94e | 62 | wait (3.0f); |
BlueShadow | 0:1683e80da94e | 63 | } |
BlueShadow | 0:1683e80da94e | 64 | printf("\r\n3\r\n"); |
BlueShadow | 0:1683e80da94e | 65 | wait(1.0f); |
BlueShadow | 0:1683e80da94e | 66 | printf("2\r\n"); |
BlueShadow | 0:1683e80da94e | 67 | wait(1.0f); |
BlueShadow | 0:1683e80da94e | 68 | printf("1\r\n"); |
BlueShadow | 0:1683e80da94e | 69 | wait(1.0f); |
BlueShadow | 0:1683e80da94e | 70 | printf("Measuring!!!! :-)\r\n\n"); |
BlueShadow | 0:1683e80da94e | 71 | wait(3.0f); |
BlueShadow | 0:1683e80da94e | 72 | value = sensor; |
BlueShadow | 0:1683e80da94e | 73 | |
BlueShadow | 0:1683e80da94e | 74 | if (value > .8f) { |
BlueShadow | 0:1683e80da94e | 75 | txtmsg.message = "Call a life Gaurd Now! ;-)"; |
BlueShadow | 0:1683e80da94e | 76 | } else if (value > .6f) { |
BlueShadow | 0:1683e80da94e | 77 | txtmsg.message = "Feeling Groovey"; |
BlueShadow | 0:1683e80da94e | 78 | } else if (value > .4f) { |
BlueShadow | 0:1683e80da94e | 79 | txtmsg.message = "I'm Good"; |
BlueShadow | 0:1683e80da94e | 80 | } else { |
BlueShadow | 0:1683e80da94e | 81 | txtmsg.message = "Very Dry"; |
BlueShadow | 0:1683e80da94e | 82 | } |
BlueShadow | 0:1683e80da94e | 83 | printf("%s\n\r", txtmsg.message.c_str()); |
BlueShadow | 0:1683e80da94e | 84 | printf("Sensor is: %2.2f\r\n\r\n", 100*value); |
BlueShadow | 0:1683e80da94e | 85 | |
BlueShadow | 0:1683e80da94e | 86 | |
BlueShadow | 0:1683e80da94e | 87 | // Send SMS message to phone |
BlueShadow | 0:1683e80da94e | 88 | // for (int i = 1; i < 10; i++) { |
BlueShadow | 0:1683e80da94e | 89 | // if(radio->sendSMS(txtmsg) == MTS_SUCCESS) { |
BlueShadow | 0:1683e80da94e | 90 | // logInfo("Sent SMS successfully: <%s>\n", txtmsg.message.c_str()); |
BlueShadow | 0:1683e80da94e | 91 | // break; |
BlueShadow | 0:1683e80da94e | 92 | // } else { |
BlueShadow | 0:1683e80da94e | 93 | // logError("Failed to send SMS: <%s>\n", txtmsg.message.c_str()); |
BlueShadow | 0:1683e80da94e | 94 | // } |
BlueShadow | 0:1683e80da94e | 95 | } |
BlueShadow | 0:1683e80da94e | 96 | |
BlueShadow | 0:1683e80da94e | 97 | } |