Twilio phone calls by Dropbox phone book

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

This simple Twilio example works with HTTPS based Twilio API from mbed, makes phone calls and talks text speech message by referring phone book file in Dropbox.

For using this example:

- Prepare mbed with Ethernet connection.

- Go to http://twilio.com, and sign up.

- Copy Twilio Sid, Token, phone number and TwiML URL in twilio.cpp.

static char twilio_AccountSid[] = "TWILIO_ACCOUNT_SID" ;
static char twilio_AuthToken[]  = "AUTH_TOKEN" ;
static const char twilio_From[] = "PHONE_NUMBER_FROM" ;
static const char twilio_Url[]  = "http://twimlbin.com/TWIML_PATH" ;

- Copy Dropbox file link URL to dropbox.cpp.

static char Dropbox_URL[] = "https://www.dropbox.com/PHONE_LIST_FILE" ;

- The demo makes a call from Twilio to the phone numbers listed on the Dropbox phone book. Phone book is list of the number CSV file.

- Set up a TwiML web page defining Twilio action, set the url to twilio_Url.

TwiML first step example:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
	<Say language="ja-JP">もしもし。聞こえますか?こちらツイリオです</Say>
</Response>

- Build, download it to mbed, and you will get a call on your phone.

Have fun!

For FRDM-k64f: http://mbed.org/users/wolfSSL/code/CyaSSL-Twilio-Dropbox-FRDM/

日本語:http://mbed.org/users/wolfSSL/code/CyaSSL-Twilio/wiki/CyaSSL-Twilio-Dropbox-jp

Committer:
wolfSSL
Date:
Mon Jul 21 11:29:59 2014 +0000
Revision:
0:ca5715c208bf
Twilio phone calls with Dropbox phone book;

Who changed what in which revision?

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