Twilio call to your phone example

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* twilio.c
00002  *
00003  * Copyright (C) 2006-2014 wolfSSL Inc.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 #include "mbed.h"
00023 #include "EthernetInterface.h"
00024 #include "HTTPClient.h"
00025 
00026 #define KEYS "https://192.168.49.57/574d76fcb/keys.txt"
00027 
00028 #define BUFFSIZE (50+1)
00029 
00030 extern void twilio_call(char *twilio_AccountSid,
00031                         char *twilio_AuthToken,
00032                         char *twilio_From,
00033                         char *twilio_To,
00034                         char *twilio_Url) ;
00035 
00036 extern HTTPClient http;
00037 EthernetInterface eth;
00038 
00039 void thread_main(void const *av)
00040 {
00041     int ret ; 
00042     int i ;
00043     static char recvBuff[BUFFSIZE*6] ;
00044     static char dummy1[BUFFSIZE], dummy2[BUFFSIZE] ;
00045     static char twilio_AccountSid[BUFFSIZE] ;
00046     static char twilio_AuthToken[BUFFSIZE] ;
00047     static char twilio_From[BUFFSIZE] ;
00048     static char twilio_To[BUFFSIZE] ;
00049     static char twilio_Url[BUFFSIZE] ;
00050   
00051     memset(recvBuff, '\0', sizeof(recvBuff)) ;
00052     ret = http.get(KEYS, recvBuff, sizeof(recvBuff));
00053     if (ret) {
00054         printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
00055         return ;
00056     }
00057 
00058     sscanf(recvBuff, "%50s\n%50s\n%50s\n%50s\n%50s\n%50s", dummy1, dummy2,
00059            twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_Url) ;
00060     printf("id=%s\nToken=%s\nFrom=%s\nUrl=%s\n\n", 
00061         twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_Url) ;
00062     
00063     printf("Phone Number:") ;
00064     for(i=0; i<BUFFSIZE; i++) {
00065         if((twilio_To[i] = getchar()) == '\r') {
00066             twilio_To[i] = '\0' ;
00067             putchar('\n') ;
00068             break ;
00069         } else putchar(twilio_To[i]) ;
00070     }
00071     
00072     twilio_call(twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_To, twilio_Url) ;
00073 
00074     while (true) {
00075         wait(10.0);
00076     }
00077 }
00078 
00079 int main() {
00080     int ret ;
00081     void *av ;
00082     
00083     ret = eth.init(); //Use DHCP
00084     printf("Twilio Client Starting,...\n") ;
00085 
00086     while(1) {
00087         ret = eth.connect();
00088         if(ret == 0)break ;
00089         wait(0.1);
00090     }
00091     printf("IP = %s\n", eth.getIPAddress());
00092     
00093     #define STACK_SIZE 20000
00094     Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE);
00095 
00096     while(1)
00097         wait(10.0) ;
00098 }