![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ok gps fails to lock for long time hard coding seems ok
Dependencies: EthernetInterface GPS NTPClient SimpleSMTPClient mbed-rtos mbed
main.cpp@0:d08060f66f4f, 2014-04-17 (annotated)
- Committer:
- avnisha
- Date:
- Thu Apr 17 20:03:56 2014 +0000
- Revision:
- 0:d08060f66f4f
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avnisha | 0:d08060f66f4f | 1 | |
avnisha | 0:d08060f66f4f | 2 | |
avnisha | 0:d08060f66f4f | 3 | #include "mbed.h" |
avnisha | 0:d08060f66f4f | 4 | #include "GPS.h" |
avnisha | 0:d08060f66f4f | 5 | #include "rtos.h" |
avnisha | 0:d08060f66f4f | 6 | #include <string> |
avnisha | 0:d08060f66f4f | 7 | #include "EthernetInterface.h" |
avnisha | 0:d08060f66f4f | 8 | #include "NTPClient.h" |
avnisha | 0:d08060f66f4f | 9 | #include "SimpleSMTPClient.h" |
avnisha | 0:d08060f66f4f | 10 | |
avnisha | 0:d08060f66f4f | 11 | using namespace std; |
avnisha | 0:d08060f66f4f | 12 | |
avnisha | 0:d08060f66f4f | 13 | const string GoogleChunk = "https://maps.google.com/?q="; // URL constant |
avnisha | 0:d08060f66f4f | 14 | const string GoogleExtras = ""; // Zoom Level (0-20) |
avnisha | 0:d08060f66f4f | 15 | char GPRSbuffer[512]; |
avnisha | 0:d08060f66f4f | 16 | char NUMBER[13]; |
avnisha | 0:d08060f66f4f | 17 | string MESSAGE; |
avnisha | 0:d08060f66f4f | 18 | int index; |
avnisha | 0:d08060f66f4f | 19 | int i = 0; |
avnisha | 0:d08060f66f4f | 20 | float latitude; |
avnisha | 0:d08060f66f4f | 21 | float longitude; |
avnisha | 0:d08060f66f4f | 22 | char message[256]; |
avnisha | 0:d08060f66f4f | 23 | |
avnisha | 0:d08060f66f4f | 24 | GPS gps(p9,p10); |
avnisha | 0:d08060f66f4f | 25 | DigitalOut myled1(LED1); |
avnisha | 0:d08060f66f4f | 26 | DigitalOut myled2(LED2); |
avnisha | 0:d08060f66f4f | 27 | DigitalOut myled3(LED3); |
avnisha | 0:d08060f66f4f | 28 | DigitalOut myled4(LED4); |
avnisha | 0:d08060f66f4f | 29 | |
avnisha | 0:d08060f66f4f | 30 | void led_thread(void const *argument) |
avnisha | 0:d08060f66f4f | 31 | { |
avnisha | 0:d08060f66f4f | 32 | while (true) { |
avnisha | 0:d08060f66f4f | 33 | DigitalOut leds[4] = {myled1, myled2, myled3, myled4}; |
avnisha | 0:d08060f66f4f | 34 | int pattern[6][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1},{0,0,1,0},{0,1,0,0}}; |
avnisha | 0:d08060f66f4f | 35 | int i=0; |
avnisha | 0:d08060f66f4f | 36 | while(1) { |
avnisha | 0:d08060f66f4f | 37 | leds[0] = pattern[i][0]; |
avnisha | 0:d08060f66f4f | 38 | leds[1] = pattern[i][1]; |
avnisha | 0:d08060f66f4f | 39 | leds[2] = pattern[i][2]; |
avnisha | 0:d08060f66f4f | 40 | leds[3] = pattern[i][3]; |
avnisha | 0:d08060f66f4f | 41 | wait(0.2); |
avnisha | 0:d08060f66f4f | 42 | i++; |
avnisha | 0:d08060f66f4f | 43 | i == 6? i=0:0; |
avnisha | 0:d08060f66f4f | 44 | } |
avnisha | 0:d08060f66f4f | 45 | } |
avnisha | 0:d08060f66f4f | 46 | } |
avnisha | 0:d08060f66f4f | 47 | |
avnisha | 0:d08060f66f4f | 48 | |
avnisha | 0:d08060f66f4f | 49 | #define DOMAIN "comcast.net" |
avnisha | 0:d08060f66f4f | 50 | #define SERVER "smtp.comcast.net" |
avnisha | 0:d08060f66f4f | 51 | #define PORT "587" //25 or 587,465(OutBound Port25 Blocking ) |
avnisha | 0:d08060f66f4f | 52 | #define USER "avnisha" |
avnisha | 0:d08060f66f4f | 53 | #define PWD "Bubbles1231" |
avnisha | 0:d08060f66f4f | 54 | #define FROM_ADDRESS "avnisha@comcast.net" |
avnisha | 0:d08060f66f4f | 55 | #define TO_ADDRESS "avnisha@comcast.net" |
avnisha | 0:d08060f66f4f | 56 | #define SUBJECT "Test Mail" |
avnisha | 0:d08060f66f4f | 57 | |
avnisha | 0:d08060f66f4f | 58 | int sms_setup() |
avnisha | 0:d08060f66f4f | 59 | { |
avnisha | 0:d08060f66f4f | 60 | EthernetInterface eth; |
avnisha | 0:d08060f66f4f | 61 | char strTimeMsg[16]; |
avnisha | 0:d08060f66f4f | 62 | |
avnisha | 0:d08060f66f4f | 63 | printf("Setting up SMS ...\n"); |
avnisha | 0:d08060f66f4f | 64 | eth.init(); |
avnisha | 0:d08060f66f4f | 65 | eth.connect(); |
avnisha | 0:d08060f66f4f | 66 | printf("Connected OK\n"); |
avnisha | 0:d08060f66f4f | 67 | |
avnisha | 0:d08060f66f4f | 68 | // IP Address |
avnisha | 0:d08060f66f4f | 69 | |
avnisha | 0:d08060f66f4f | 70 | printf("IP Address is %s\n", eth.getIPAddress()); |
avnisha | 0:d08060f66f4f | 71 | printf("%s", eth.getIPAddress()); |
avnisha | 0:d08060f66f4f | 72 | |
avnisha | 0:d08060f66f4f | 73 | // NTP Client |
avnisha | 0:d08060f66f4f | 74 | printf("NTP setTime...\n"); |
avnisha | 0:d08060f66f4f | 75 | NTPClient ntp; |
avnisha | 0:d08060f66f4f | 76 | ntp.setTime("pool.ntp.org"); |
avnisha | 0:d08060f66f4f | 77 | |
avnisha | 0:d08060f66f4f | 78 | time_t ctTime = time(NULL)+32400; // JST |
avnisha | 0:d08060f66f4f | 79 | printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime)); |
avnisha | 0:d08060f66f4f | 80 | strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime)); |
avnisha | 0:d08060f66f4f | 81 | printf("[%s]",strTimeMsg); |
avnisha | 0:d08060f66f4f | 82 | |
avnisha | 0:d08060f66f4f | 83 | return 1; |
avnisha | 0:d08060f66f4f | 84 | |
avnisha | 0:d08060f66f4f | 85 | } |
avnisha | 0:d08060f66f4f | 86 | |
avnisha | 0:d08060f66f4f | 87 | int sms_send(char *message) { |
avnisha | 0:d08060f66f4f | 88 | |
avnisha | 0:d08060f66f4f | 89 | SimpleSMTPClient smtp; |
avnisha | 0:d08060f66f4f | 90 | int ret; |
avnisha | 0:d08060f66f4f | 91 | char msg[]="Hello SimpleSMTPClient "; |
avnisha | 0:d08060f66f4f | 92 | |
avnisha | 0:d08060f66f4f | 93 | smtp.setFromAddress(FROM_ADDRESS); |
avnisha | 0:d08060f66f4f | 94 | smtp.setToAddress(TO_ADDRESS); |
avnisha | 0:d08060f66f4f | 95 | smtp.setMessage(SUBJECT,msg); |
avnisha | 0:d08060f66f4f | 96 | smtp.addMessage(message); |
avnisha | 0:d08060f66f4f | 97 | |
avnisha | 0:d08060f66f4f | 98 | // |
avnisha | 0:d08060f66f4f | 99 | // send as SMS text |
avnisha | 0:d08060f66f4f | 100 | // |
avnisha | 0:d08060f66f4f | 101 | |
avnisha | 0:d08060f66f4f | 102 | smtp.setFromAddress(FROM_ADDRESS); |
avnisha | 0:d08060f66f4f | 103 | smtp.setToAddress("5105794214@txt.att.net"); // MODIFY for carrier |
avnisha | 0:d08060f66f4f | 104 | smtp.setMessage(SUBJECT,msg); |
avnisha | 0:d08060f66f4f | 105 | smtp.addMessage(message); |
avnisha | 0:d08060f66f4f | 106 | |
avnisha | 0:d08060f66f4f | 107 | ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_PLAIN); |
avnisha | 0:d08060f66f4f | 108 | |
avnisha | 0:d08060f66f4f | 109 | if (ret) { |
avnisha | 0:d08060f66f4f | 110 | printf("SMS Transmission Error\r\n"); |
avnisha | 0:d08060f66f4f | 111 | } else { |
avnisha | 0:d08060f66f4f | 112 | printf("SMS Transmission OK\r\n"); |
avnisha | 0:d08060f66f4f | 113 | } |
avnisha | 0:d08060f66f4f | 114 | |
avnisha | 0:d08060f66f4f | 115 | return 0; |
avnisha | 0:d08060f66f4f | 116 | |
avnisha | 0:d08060f66f4f | 117 | } |
avnisha | 0:d08060f66f4f | 118 | |
avnisha | 0:d08060f66f4f | 119 | int getGPS() { |
avnisha | 0:d08060f66f4f | 120 | |
avnisha | 0:d08060f66f4f | 121 | #define CANNED |
avnisha | 0:d08060f66f4f | 122 | #ifdef CANNED |
avnisha | 0:d08060f66f4f | 123 | printf("CANNED GPS\n\r"); |
avnisha | 0:d08060f66f4f | 124 | longitude = -201; |
avnisha | 0:d08060f66f4f | 125 | latitude = 37; |
avnisha | 0:d08060f66f4f | 126 | return 1; |
avnisha | 0:d08060f66f4f | 127 | #endif |
avnisha | 0:d08060f66f4f | 128 | if(gps.sample()) { |
avnisha | 0:d08060f66f4f | 129 | printf("I'm at %f, %f\n", gps.longitude, gps.latitude); |
avnisha | 0:d08060f66f4f | 130 | } else { |
avnisha | 0:d08060f66f4f | 131 | printf("Oh Dear! No lock :(\n"); |
avnisha | 0:d08060f66f4f | 132 | return 0; |
avnisha | 0:d08060f66f4f | 133 | } |
avnisha | 0:d08060f66f4f | 134 | |
avnisha | 0:d08060f66f4f | 135 | longitude = gps.longitude; |
avnisha | 0:d08060f66f4f | 136 | latitude = gps.latitude; |
avnisha | 0:d08060f66f4f | 137 | return 1; |
avnisha | 0:d08060f66f4f | 138 | } |
avnisha | 0:d08060f66f4f | 139 | |
avnisha | 0:d08060f66f4f | 140 | void sendGPS() |
avnisha | 0:d08060f66f4f | 141 | { |
avnisha | 0:d08060f66f4f | 142 | |
avnisha | 0:d08060f66f4f | 143 | sprintf(message, "Find me at....\n %s%f,%f%s", GoogleChunk, latitude, longitude, GoogleExtras); |
avnisha | 0:d08060f66f4f | 144 | sms_send(message); |
avnisha | 0:d08060f66f4f | 145 | |
avnisha | 0:d08060f66f4f | 146 | } |
avnisha | 0:d08060f66f4f | 147 | |
avnisha | 0:d08060f66f4f | 148 | |
avnisha | 0:d08060f66f4f | 149 | int main() |
avnisha | 0:d08060f66f4f | 150 | { |
avnisha | 0:d08060f66f4f | 151 | |
avnisha | 0:d08060f66f4f | 152 | //Thread thread(led_thread); |
avnisha | 0:d08060f66f4f | 153 | |
avnisha | 0:d08060f66f4f | 154 | printf("Send GPS SMS message\r\n"); |
avnisha | 0:d08060f66f4f | 155 | sms_setup(); |
avnisha | 0:d08060f66f4f | 156 | |
avnisha | 0:d08060f66f4f | 157 | // Get in a while loop |
avnisha | 0:d08060f66f4f | 158 | |
avnisha | 0:d08060f66f4f | 159 | while (1) { |
avnisha | 0:d08060f66f4f | 160 | if (getGPS()) { |
avnisha | 0:d08060f66f4f | 161 | sendGPS(); |
avnisha | 0:d08060f66f4f | 162 | } |
avnisha | 0:d08060f66f4f | 163 | |
avnisha | 0:d08060f66f4f | 164 | wait(600); |
avnisha | 0:d08060f66f4f | 165 | } |
avnisha | 0:d08060f66f4f | 166 | } |
avnisha | 0:d08060f66f4f | 167 | |
avnisha | 0:d08060f66f4f | 168 |