Initial version, CyaSSL Twilio example
Dependencies: HTTPClient EthernetInterface mbed-rtos mbed
This simple Twilio example works with HTTPS based Twilio API from mbed, makes a call to your phone and talks text speech message.
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_To[] = "PHONE_NUMBER_TO" ; static const char twilio_Url[] = "http://twimlbin.com/TWIML_PATH" ;
- The demo makes a call from Twilio to your phone. Set the phone numbers onto twilio_From and twilio_To.
- 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-FRDM/
日本語:http://mbed.org/users/wolfSSL/code/CyaSSL-Twilio/wiki/CyaSSL-Twilio-jp
main.cpp
- Committer:
- wolfSSL
- Date:
- 2014-07-12
- Revision:
- 3:4c3c4b46a11a
- Parent:
- 0:bd0e8172f67f
File content as of revision 3:4c3c4b46a11a:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" EthernetInterface eth; HTTPClient http; static char str[1500] ; void twilio_main(void *av) { int ret ; #define ALLOWANCE 100 #define SAFIX 10 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_To[] = "PHONE_NUMBER_TO" ; static const char twilio_Url[] = "http://twimlbin.com/TWIML_PATH" ; static const char twilio_api[] = "https://api.twilio.com/2010-04-01/Accounts/%s/%s.%s" ; static const char twilio_Method[] = "GET" ; static const char twilio_FBMethod[] = "GET" ; static const char twilio_StatusCBM[]= "GET" ; static const char twilio_Record[] = "false" ; static char twilio_request[] = "Calls" ; static char twilio_twiML[] = "xml" ; static char uri[ sizeof(twilio_AccountSid) +sizeof(twilio_AuthToken) +sizeof(twilio_api) +SAFIX+ALLOWANCE] ; static char HeaderLines[] = "User-Agent: curl/7.33.0\n" "Host: api.twilio.com\n" "Accept: */*\n" ; //POST data HTTPMap params; HTTPText inText(str, 1500); params.put("From", twilio_From); params.put("To", twilio_To); params.put("Url", twilio_Url); params.put("Method", twilio_Method); params.put("FaulbackMethod", twilio_FBMethod); params.put("StatusCallbackMethod", twilio_StatusCBM); params.put("Record", twilio_Record); printf("\nTrying to call %s\n", twilio_To); sprintf(uri, twilio_api, twilio_AccountSid, twilio_request, twilio_twiML) ; printf("uri=%s\n", uri) ; http.basicAuth(twilio_AccountSid, twilio_AuthToken); http.setHeader(HeaderLines) ; http.setSSLversion(1) ; /* TLSv1.0 */ ret = http.post(uri, params, &inText); if (!ret) { printf("Executed POST successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); } eth.disconnect(); } int main() { int ret ; int av ; EthernetInterface eth; printf("Twilio Client Starting,...\n") ; ret = eth.init(); //Use DHCP while(1) { ret = eth.connect(); if(ret == 0)break ; Thread::wait(100); } printf("IP = %s\n", eth.getIPAddress()); //#define BOARD_FRDM_K64F #ifdef BOARD_FRDM_K64F #define STACK_SIZE 10000 Thread t(twilio_main, NULL, osPriorityNormal, STACK_SIZE); #else twilio_main(&av) ; #endif while (true) { Thread::wait(1000); } }