Twilio phone calls by Dropbox phone book

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed-src

Committer:
wolfSSL
Date:
Mon Jul 21 11:31:19 2014 +0000
Revision:
0:30641b73b139
Twilio phone calls by Dropbox phone book, FRDM-K64F board;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:30641b73b139 1 /* main.cpp */
wolfSSL 0:30641b73b139 2 /* Copyright (C) 2014 wolfSSL, MIT License
wolfSSL 0:30641b73b139 3 *
wolfSSL 0:30641b73b139 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
wolfSSL 0:30641b73b139 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
wolfSSL 0:30641b73b139 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
wolfSSL 0:30641b73b139 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
wolfSSL 0:30641b73b139 8 * furnished to do so, subject to the following conditions:
wolfSSL 0:30641b73b139 9 *
wolfSSL 0:30641b73b139 10 * The above copyright notice and this permission notice shall be included in all copies or
wolfSSL 0:30641b73b139 11 * substantial portions of the Software.
wolfSSL 0:30641b73b139 12 *
wolfSSL 0:30641b73b139 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
wolfSSL 0:30641b73b139 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
wolfSSL 0:30641b73b139 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
wolfSSL 0:30641b73b139 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wolfSSL 0:30641b73b139 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
wolfSSL 0:30641b73b139 18 */
wolfSSL 0:30641b73b139 19
wolfSSL 0:30641b73b139 20
wolfSSL 0:30641b73b139 21 #include "mbed.h"
wolfSSL 0:30641b73b139 22 #include "EthernetInterface.h"
wolfSSL 0:30641b73b139 23 #include "HTTPClient.h"
wolfSSL 0:30641b73b139 24
wolfSSL 0:30641b73b139 25 HTTPClient http;
wolfSSL 0:30641b73b139 26 extern HTTPResult dropbox_get(const char *url, char * buff, int size) ;
wolfSSL 0:30641b73b139 27 extern HTTPResult twilio_main(const char *phone) ;
wolfSSL 0:30641b73b139 28
wolfSSL 0:30641b73b139 29 static char Dropbox_URL[] = "https://www.dropbox.com/PHONE_LIST_FILE" ;
wolfSSL 0:30641b73b139 30
wolfSSL 0:30641b73b139 31 #define BUFF_SIZE 256
wolfSSL 0:30641b73b139 32 static char buff[BUFF_SIZE] ;
wolfSSL 0:30641b73b139 33
wolfSSL 0:30641b73b139 34 void thread_main(void const *av) {
wolfSSL 0:30641b73b139 35 dropbox_get(Dropbox_URL, buff, BUFF_SIZE) ;
wolfSSL 0:30641b73b139 36 char *p = buff ;
wolfSSL 0:30641b73b139 37 bool endflg = false ;
wolfSSL 0:30641b73b139 38 for(int i = 0 ; i<BUFF_SIZE; i++) {
wolfSSL 0:30641b73b139 39 if((p[i] == '\0') || (p[i] == '\n'))
wolfSSL 0:30641b73b139 40 endflg = true ;
wolfSSL 0:30641b73b139 41 if((p[i] == ',') || (p[i] == '\n') || (p[i] == '\0')){
wolfSSL 0:30641b73b139 42 p[i] = '\0' ;
wolfSSL 0:30641b73b139 43 twilio_main(p) ;
wolfSSL 0:30641b73b139 44 if(endflg)break ;
wolfSSL 0:30641b73b139 45 p = &(p[i+1]) ;
wolfSSL 0:30641b73b139 46 }
wolfSSL 0:30641b73b139 47 }
wolfSSL 0:30641b73b139 48 }
wolfSSL 0:30641b73b139 49
wolfSSL 0:30641b73b139 50 int main()
wolfSSL 0:30641b73b139 51 {
wolfSSL 0:30641b73b139 52 int ret ;
wolfSSL 0:30641b73b139 53 void const *av ;
wolfSSL 0:30641b73b139 54
wolfSSL 0:30641b73b139 55 EthernetInterface eth;
wolfSSL 0:30641b73b139 56
wolfSSL 0:30641b73b139 57 printf("Dropbox Starting,...\n") ;
wolfSSL 0:30641b73b139 58 ret = eth.init(); //Use DHCP
wolfSSL 0:30641b73b139 59 while(1) {
wolfSSL 0:30641b73b139 60 ret = eth.connect();
wolfSSL 0:30641b73b139 61 if(ret == 0)break ;
wolfSSL 0:30641b73b139 62 }
wolfSSL 0:30641b73b139 63 printf("IP = %s\n", eth.getIPAddress());
wolfSSL 0:30641b73b139 64
wolfSSL 0:30641b73b139 65 #define BOARD_FRDM_K64F
wolfSSL 0:30641b73b139 66 #ifdef BOARD_FRDM_K64F
wolfSSL 0:30641b73b139 67 #define STACK_SIZE 10000
wolfSSL 0:30641b73b139 68 Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE);
wolfSSL 0:30641b73b139 69 #else
wolfSSL 0:30641b73b139 70 thread_main(av) ;
wolfSSL 0:30641b73b139 71 #endif
wolfSSL 0:30641b73b139 72
wolfSSL 0:30641b73b139 73 while (true) {
wolfSSL 0:30641b73b139 74 Thread::wait(1000);
wolfSSL 0:30641b73b139 75 }
wolfSSL 0:30641b73b139 76 }