Untitled
unknown
c_cpp
3 years ago
1.2 kB
8
Indexable
#include <HTTPClient.h>
const char* ssid = "your_WiFi_SSID";
const char* password = "your_WiFi_password";
const char* accountSid = "your_Twilio_account_SID";
const char* authToken = "your_Twilio_auth_token";
const char* fromNumber = "+1your_Twilio_number";
const char* toNumber = "+1receiver_number";
const char* callUrl = "http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
makeCall();
}
void loop() {
// empty
}
void makeCall() {
HTTPClient http;
String url = "https://api.twilio.com/2010-04-01/Accounts/";
url += accountSid;
url += "/Calls.json";
http.begin(url);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.addHeader("Authorization", "Basic " + base64::encode(accountSid + ":" + authToken));
String payload = "To=" + toNumber;
payload += "&From=" + fromNumber;
payload += "&Url=" + callUrl;
int httpCode = http.POST(payload);
String response = http.getString();
Serial.println("Response code: " + String(httpCode));
Serial.println("Response body: " + response);
}
Editor is loading...