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.
main.cpp
00001 00002 #include "mbed.h" 00003 #include "mtsas.h" 00004 // #include "PubSubClient.h" 00005 00006 //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx" 00007 string PHONE_NUMBER = "169524576179"; 00008 00009 00010 AnalogIn sensor(PC_2); //A0 pin on UDK 00011 DigitalIn button(PA_9); // D5 pin 00012 00013 int main(void) 00014 { 00015 wait(15); 00016 printf("Moisture Meter Starting ...\n\r"); 00017 00018 //Sets the log level to INFO, higher log levels produce more log output. 00019 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE 00020 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); 00021 00022 Cellular::Sms txtmsg; 00023 txtmsg.phoneNumber = PHONE_NUMBER; 00024 00025 if(PHONE_NUMBER == "CHANGE ME PLEASE") { 00026 while(1) { 00027 printf("FORGOT TO SET THE PHONE NUMBER\r\n"); 00028 wait(1.0f); 00029 } 00030 } 00031 00032 /** STMicro Nucelo F411RE 00033 * The supported jumper configurations of the MTSAS do not line up with 00034 * the pin mapping of the Nucleo F411RE. Therefore, the MTSAS serial TX 00035 * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2) 00036 * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to 00037 * Serial1 TX (Shield pin D8). 00038 */ 00039 00040 MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6); 00041 00042 //Sets the baud rate for communicating with the radio 00043 io->baud(115200); 00044 00045 //Creates a radio object 00046 Cellular* radio = CellularFactory::create(io); 00047 00048 if (! radio) { 00049 logFatal("Failed to initialize radio"); 00050 return 1; 00051 } 00052 00053 printf("ready to wait \r\n"); 00054 wait(2.0f); 00055 printf("Sensor is ready to read data!!! :-) \r\n"); 00056 float value =0.0f; 00057 while(1) { 00058 00059 while(!button) { 00060 value = sensor; 00061 printf("Moisture level: %f \n",value); 00062 wait (3.0f); 00063 } 00064 printf("\r\n3\r\n"); 00065 wait(1.0f); 00066 printf("2\r\n"); 00067 wait(1.0f); 00068 printf("1\r\n"); 00069 wait(1.0f); 00070 printf("Measuring!!!! :-)\r\n\n"); 00071 wait(3.0f); 00072 value = sensor; 00073 00074 if (value > .8f) { 00075 txtmsg.message = "Call a life Gaurd Now! ;-)"; 00076 } else if (value > .6f) { 00077 txtmsg.message = "Feeling Groovey"; 00078 } else if (value > .4f) { 00079 txtmsg.message = "I'm Good"; 00080 } else { 00081 txtmsg.message = "Very Dry"; 00082 } 00083 printf("%s\n\r", txtmsg.message.c_str()); 00084 printf("Sensor is: %2.2f\r\n\r\n", 100*value); 00085 00086 00087 // Send SMS message to phone 00088 // for (int i = 1; i < 10; i++) { 00089 // if(radio->sendSMS(txtmsg) == MTS_SUCCESS) { 00090 // logInfo("Sent SMS successfully: <%s>\n", txtmsg.message.c_str()); 00091 // break; 00092 // } else { 00093 // logError("Failed to send SMS: <%s>\n", txtmsg.message.c_str()); 00094 // } 00095 } 00096 00097 }
Generated on Thu Aug 4 2022 16:44:39 by
