Twilio call to your phone example
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:215c9ef8ad80
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 08 12:13:59 2014 +0000 @@ -0,0 +1,98 @@ +/* twilio.c + * + * Copyright (C) 2006-2014 wolfSSL Inc. + * + * This file is part of CyaSSL. + * + * CyaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CyaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "mbed.h" +#include "EthernetInterface.h" +#include "HTTPClient.h" + +#define KEYS "https://192.168.49.57/574d76fcb/keys.txt" + +#define BUFFSIZE (50+1) + +extern void twilio_call(char *twilio_AccountSid, + char *twilio_AuthToken, + char *twilio_From, + char *twilio_To, + char *twilio_Url) ; + +extern HTTPClient http; +EthernetInterface eth; + +void thread_main(void const *av) +{ + int ret ; + int i ; + static char recvBuff[BUFFSIZE*6] ; + static char dummy1[BUFFSIZE], dummy2[BUFFSIZE] ; + static char twilio_AccountSid[BUFFSIZE] ; + static char twilio_AuthToken[BUFFSIZE] ; + static char twilio_From[BUFFSIZE] ; + static char twilio_To[BUFFSIZE] ; + static char twilio_Url[BUFFSIZE] ; + + memset(recvBuff, '\0', sizeof(recvBuff)) ; + ret = http.get(KEYS, recvBuff, sizeof(recvBuff)); + if (ret) { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + return ; + } + + sscanf(recvBuff, "%50s\n%50s\n%50s\n%50s\n%50s\n%50s", dummy1, dummy2, + twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_Url) ; + printf("id=%s\nToken=%s\nFrom=%s\nUrl=%s\n\n", + twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_Url) ; + + printf("Phone Number:") ; + for(i=0; i<BUFFSIZE; i++) { + if((twilio_To[i] = getchar()) == '\r') { + twilio_To[i] = '\0' ; + putchar('\n') ; + break ; + } else putchar(twilio_To[i]) ; + } + + twilio_call(twilio_AccountSid, twilio_AuthToken, twilio_From, twilio_To, twilio_Url) ; + + while (true) { + wait(10.0); + } +} + +int main() { + int ret ; + void *av ; + + ret = eth.init(); //Use DHCP + printf("Twilio Client Starting,...\n") ; + + while(1) { + ret = eth.connect(); + if(ret == 0)break ; + wait(0.1); + } + printf("IP = %s\n", eth.getIPAddress()); + + #define STACK_SIZE 20000 + Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE); + + while(1) + wait(10.0) ; +} \ No newline at end of file