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

main.cpp

Committer:
wolfSSL
Date:
2014-07-21
Revision:
0:ca5715c208bf

File content as of revision 0:ca5715c208bf:

/* main.cpp */
/* Copyright (C) 2014 wolfSSL, MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"

HTTPClient http;
extern HTTPResult dropbox_get(const char *url, char * buff, int size) ;
extern HTTPResult twilio_main(const char *phone) ;
 
static char Dropbox_URL[] = "https://www.dropbox.com/PHONE_LIST_FILE" ;

#define BUFF_SIZE 256
static char buff[BUFF_SIZE] ;

void thread_main(void const *av) {
    dropbox_get(Dropbox_URL, buff, BUFF_SIZE) ;
    char *p = buff ;
    bool endflg = false ;
    for(int i = 0 ; i<BUFF_SIZE; i++) {
        if((p[i] == '\0') || (p[i] == '\n'))
            endflg = true ;
        if((p[i] == ',') || (p[i] == '\n') || (p[i] == '\0')){
            p[i] = '\0' ;
            twilio_main(p) ;
            if(endflg)break ;
            p = &(p[i+1]) ;
        }
    }
}

int main()
{
    int ret ;
    void const *av ;
    
    EthernetInterface eth;

    printf("Dropbox Starting,...\n") ;
    ret = eth.init(); //Use DHCP
    while(1) {
        ret = eth.connect();
        if(ret == 0)break ;
    }
    printf("IP = %s\n", eth.getIPAddress());
    
    //#define BOARD_FRDM_K64F
    #ifdef BOARD_FRDM_K64F
    #define STACK_SIZE 10000
        Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE);
    #else
        thread_main(av) ;
    #endif

    while (true) {
        Thread::wait(1000);
    }
}