#include <Arduino.h>
#include <WiFi.h>
#include "HX711.h"
#include "twilio.hpp"
// const char *ssid = "Redmi 10";
// const char *password = "09876543";
const char *account_sid = "AC1c928c0916ef9b44dd12034b7c6ad2f7";
const char *auth_token = "45f47142775962f16978276ef05688aa";
const char *from_number = "+14387977289";
const char *to_number = "+916267040095";
const char *message = "Sent from my ESP32";
HX711 scale;
Twilio *twilio;
bool success;
int LoadCell_DT_Pin = 16;
int LoadCell_SCK_Pin = 4;
float To_KG = 0.002381;
void initWiFi() {
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
}
void setup() {
Serial.begin(115200);
delay(10);
Serial.println('\n');
initWiFi();
scale.begin(LoadCell_DT_Pin, LoadCell_SCK_Pin);
twilio = new Twilio(account_sid, auth_token);
delay(2000);
String response;
Serial.println("Sending initial message...");
Serial.println("Jayesh");
success = twilio->send_message(to_number, from_number, message, response);
if (success) {
Serial.println("Sent message successfully!");
} else {
Serial.print("Error sending message: ");
Serial.println(response);
}
}
void loop() {
float reading = scale.get_units() * To_KG;
Serial.print("Reading: ");
Serial.print(reading);
Serial.println(" kg");
if (reading > 4) {
String response;
Serial.println("Sending weight notification...");
success = twilio->send_message(to_number, from_number, "Weight: " + String(reading) + " kg", response);
if (success) {
Serial.println("Sent message successfully!");
} else {
Serial.print("Error sending message: ");
Serial.println(response);
}
}
delay(1000);
}