#include <WiFi.h>
#include <HTTPClient.h>
#include "base64.h"
#define WIFI_NETWORK "Wokwi-GUEST"
#define pass ""
WiFiClient client;
//Crenditals for Twilio (Messaging)
const char* accountSid = "AC7453b8c526f2e794354d093abc8fed52";
const char* authToken = "229ed4405177834bbdefeea0f1ff7344";
const char* fromPhoneNumber = "+15176189861";
const char* toPhoneNumber = "+918668135837";
//Function to connect to the WiFi
void connectToWifi()
{
Serial.print("Connecting To Wifi");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_NETWORK);
while(WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(100);
}
if(WiFi.status() !=WL_CONNECTED)
{
Serial.print("Failed");
}
else
{
Serial.print("Connected");
Serial.print(WiFi.localIP());
}
}
void setup() {
// put your setup code here, to run once:
connectToWifi();
}
void loop() {
// put your main code here, to run repeatedly:
String messageBody = "Hello!! This is a sample test";
// Encode the Twilio credentials
String credentials = String(accountSid) + ":" + String(authToken);
String encodedCredentials = base64::encode(credentials);
// Create the URL for the Twilio API
String url = "https://api.twilio.com/2010-04-01/Accounts/" + String(accountSid) + "/Messages.json";
// Create the POST data
String postData = "To=" + String(toPhoneNumber) + "&From=" + String(fromPhoneNumber) + "&Body=" + messageBody;
// Create and configure the HTTP client for Twilio
HTTPClient http;
http.begin(url);
http.addHeader("Authorization", "Basic " + encodedCredentials);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST(postData);
if (httpCode == HTTP_CODE_OK) {
;
}
// Close the connection
http.end();
delay(10000);
}