Twilio call to your phone example

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Committer:
wolfSSL
Date:
Mon Dec 08 12:13:59 2014 +0000
Revision:
0:215c9ef8ad80
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:215c9ef8ad80 1 /* twilio.c
wolfSSL 0:215c9ef8ad80 2 *
wolfSSL 0:215c9ef8ad80 3 * Copyright (C) 2006-2014 wolfSSL Inc.
wolfSSL 0:215c9ef8ad80 4 *
wolfSSL 0:215c9ef8ad80 5 * This file is part of CyaSSL.
wolfSSL 0:215c9ef8ad80 6 *
wolfSSL 0:215c9ef8ad80 7 * CyaSSL is free software; you can redistribute it and/or modify
wolfSSL 0:215c9ef8ad80 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:215c9ef8ad80 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:215c9ef8ad80 10 * (at your option) any later version.
wolfSSL 0:215c9ef8ad80 11 *
wolfSSL 0:215c9ef8ad80 12 * CyaSSL is distributed in the hope that it will be useful,
wolfSSL 0:215c9ef8ad80 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:215c9ef8ad80 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:215c9ef8ad80 15 * GNU General Public License for more details.
wolfSSL 0:215c9ef8ad80 16 *
wolfSSL 0:215c9ef8ad80 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:215c9ef8ad80 18 * along with this program; if not, write to the Free Software
wolfSSL 0:215c9ef8ad80 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:215c9ef8ad80 20 */
wolfSSL 0:215c9ef8ad80 21
wolfSSL 0:215c9ef8ad80 22 #include "mbed.h"
wolfSSL 0:215c9ef8ad80 23 #include "EthernetInterface.h"
wolfSSL 0:215c9ef8ad80 24 #include "HTTPClient.h"
wolfSSL 0:215c9ef8ad80 25
wolfSSL 0:215c9ef8ad80 26 #define KEYS "https://192.168.49.57/574d76fcb/keys.txt"
wolfSSL 0:215c9ef8ad80 27
wolfSSL 0:215c9ef8ad80 28 #define BUFFSIZE (50+1)
wolfSSL 0:215c9ef8ad80 29
wolfSSL 0:215c9ef8ad80 30 extern void twilio_call(char *twilio_AccountSid,
wolfSSL 0:215c9ef8ad80 31 char *twilio_AuthToken,
wolfSSL 0:215c9ef8ad80 32 char *twilio_From,
wolfSSL 0:215c9ef8ad80 33 char *twilio_To,
wolfSSL 0:215c9ef8ad80 34 char *twilio_Url) ;
wolfSSL 0:215c9ef8ad80 35
wolfSSL 0:215c9ef8ad80 36 extern HTTPClient http;
wolfSSL 0:215c9ef8ad80 37 EthernetInterface eth;
wolfSSL 0:215c9ef8ad80 38
wolfSSL 0:215c9ef8ad80 39 void thread_main(void const *av)
wolfSSL 0:215c9ef8ad80 40 {
wolfSSL 0:215c9ef8ad80 41 int ret ;
wolfSSL 0:215c9ef8ad80 42 int i ;
wolfSSL 0:215c9ef8ad80 43 static char recvBuff[BUFFSIZE*6] ;
wolfSSL 0:215c9ef8ad80 44 static char dummy1[BUFFSIZE], dummy2[BUFFSIZE] ;
wolfSSL 0:215c9ef8ad80 45 static char twilio_AccountSid[BUFFSIZE] ;
wolfSSL 0:215c9ef8ad80 46 static char twilio_AuthToken[BUFFSIZE] ;
wolfSSL 0:215c9ef8ad80 47 static char twilio_From[BUFFSIZE] ;
wolfSSL 0:215c9ef8ad80 48 static char twilio_To[BUFFSIZE] ;
wolfSSL 0:215c9ef8ad80 49 static char twilio_Url[BUFFSIZE] ;
wolfSSL 0:215c9ef8ad80 50
wolfSSL 0:215c9ef8ad80 51 memset(recvBuff, '\0', sizeof(recvBuff)) ;
wolfSSL 0:215c9ef8ad80 52 ret = http.get(KEYS, recvBuff, sizeof(recvBuff));
wolfSSL 0:215c9ef8ad80 53 if (ret) {
wolfSSL 0:215c9ef8ad80 54 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
wolfSSL 0:215c9ef8ad80 55 return ;
wolfSSL 0:215c9ef8ad80 56 }
wolfSSL 0:215c9ef8ad80 57
wolfSSL 0:215c9ef8ad80 58 sscanf(recvBuff, "%50s\n%50s\n%50s\n%50s\n%50s\n%50s", dummy1, dummy2,
wolfSSL 0:215c9ef8ad80 59 twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_Url) ;
wolfSSL 0:215c9ef8ad80 60 printf("id=%s\nToken=%s\nFrom=%s\nUrl=%s\n\n",
wolfSSL 0:215c9ef8ad80 61 twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_Url) ;
wolfSSL 0:215c9ef8ad80 62
wolfSSL 0:215c9ef8ad80 63 printf("Phone Number:") ;
wolfSSL 0:215c9ef8ad80 64 for(i=0; i<BUFFSIZE; i++) {
wolfSSL 0:215c9ef8ad80 65 if((twilio_To[i] = getchar()) == '\r') {
wolfSSL 0:215c9ef8ad80 66 twilio_To[i] = '\0' ;
wolfSSL 0:215c9ef8ad80 67 putchar('\n') ;
wolfSSL 0:215c9ef8ad80 68 break ;
wolfSSL 0:215c9ef8ad80 69 } else putchar(twilio_To[i]) ;
wolfSSL 0:215c9ef8ad80 70 }
wolfSSL 0:215c9ef8ad80 71
wolfSSL 0:215c9ef8ad80 72 twilio_call(twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_To, twilio_Url) ;
wolfSSL 0:215c9ef8ad80 73
wolfSSL 0:215c9ef8ad80 74 while (true) {
wolfSSL 0:215c9ef8ad80 75 wait(10.0);
wolfSSL 0:215c9ef8ad80 76 }
wolfSSL 0:215c9ef8ad80 77 }
wolfSSL 0:215c9ef8ad80 78
wolfSSL 0:215c9ef8ad80 79 int main() {
wolfSSL 0:215c9ef8ad80 80 int ret ;
wolfSSL 0:215c9ef8ad80 81 void *av ;
wolfSSL 0:215c9ef8ad80 82
wolfSSL 0:215c9ef8ad80 83 ret = eth.init(); //Use DHCP
wolfSSL 0:215c9ef8ad80 84 printf("Twilio Client Starting,...\n") ;
wolfSSL 0:215c9ef8ad80 85
wolfSSL 0:215c9ef8ad80 86 while(1) {
wolfSSL 0:215c9ef8ad80 87 ret = eth.connect();
wolfSSL 0:215c9ef8ad80 88 if(ret == 0)break ;
wolfSSL 0:215c9ef8ad80 89 wait(0.1);
wolfSSL 0:215c9ef8ad80 90 }
wolfSSL 0:215c9ef8ad80 91 printf("IP = %s\n", eth.getIPAddress());
wolfSSL 0:215c9ef8ad80 92
wolfSSL 0:215c9ef8ad80 93 #define STACK_SIZE 20000
wolfSSL 0:215c9ef8ad80 94 Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE);
wolfSSL 0:215c9ef8ad80 95
wolfSSL 0:215c9ef8ad80 96 while(1)
wolfSSL 0:215c9ef8ad80 97 wait(10.0) ;
wolfSSL 0:215c9ef8ad80 98 }