safwan092

DR.Sahbi_Project_12-12-2024_Tested

Dec 12th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.95 KB | None | 0 0
  1. //***********************************************************************************************************************
  2. //*****************************************[ Publish only if Values Delta (%) ]******************************************
  3. const float MIN_CHANGE_RATE = 0.05; // 5% change rate threshold
  4. // Add these variables to store previous sensor values
  5. float previousDistanceCm = 0;
  6. float previousVolume_cm3 = 0;
  7. float previousWaterLevel = 0;
  8. float previousTemperatureC = 0;
  9. float previousTdsValue = 0;
  10.  
  11. unsigned long lastMessageTimeee = 0; // Variable to store the last time a message was sent
  12. const unsigned long MESSAGE_INTERVALeee = 60000; // Interval in milliseconds (1 minute)
  13.  
  14. //***********************************************************************************************************************
  15. //***********************************************[ Included Libraries ]**************************************************
  16. #include <WiFi.h>
  17. #include <WiFiClientSecure.h>
  18. #include <UniversalTelegramBot.h>
  19. #include "Adafruit_MQTT.h"
  20. #include "Adafruit_MQTT_Client.h"
  21. #include <ArduinoJson.h>
  22. #include <OneWire.h>
  23. #include <DallasTemperature.h>
  24. //***********************************************************************************************************************
  25. //***********************************************************************************************************************
  26. //**************************************************[ Pin Definitions ]**************************************************
  27. //Pump Relay Connections
  28. const int pumpRelayPin = 21;
  29. //TDS Sensor Connections
  30. const int TdsSensorPin = 34;
  31. //DS18B20 Sensor Connections
  32. const int oneWireBus = 4;
  33. //Ultrasonic Sensor Connections
  34. const int trigPin = 5;
  35. const int echoPin = 18;
  36. //***********************************************************************************************************************
  37. //***********************************************************************************************************************
  38. //**************************************************[ Web Dashboard Setup ]**********************************************
  39. /************************* WiFi Access Point *********************************/
  40. const char* ssid = "BS Home1";
  41. const char* password = "0554418546";
  42. /************************* Telegram Setup ************************************/
  43. #define BOTtoken "7659855835:AAH-p1outEnBtW4eWhUcFWD29kLYkdjFUPA"
  44. #define CHAT_ID "-4533797433"
  45. /*********************** MQTT Account Setup **********************************/
  46. #define AIO_USERNAME "project19102024"
  47. #define AIO_KEY "aio_oONO288tq2G4GFfzGQTyhL3jaNUw"
  48.  
  49. #define AIO_SERVER "io.adafruit.com"
  50. // Using port 8883 for MQTTS
  51. #define AIO_SERVERPORT 8883
  52. // Adafruit IO Account Configuration
  53. // (to obtain these values, visit https://io.adafruit.com and click on Active Key)
  54. /************ Global State (you don't need to change this!) ******************/
  55. // WiFiFlientSecure for SSL/TLS support
  56. WiFiClientSecure client;
  57. // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
  58. Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
  59. // io.adafruit.com root CA
  60. const char* adafruitio_root_ca =
  61. "-----BEGIN CERTIFICATE-----\n"
  62. "MIIEjTCCA3WgAwIBAgIQDQd4KhM/xvmlcpbhMf/ReTANBgkqhkiG9w0BAQsFADBh\n"
  63. "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
  64. "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n"
  65. "MjAeFw0xNzExMDIxMjIzMzdaFw0yNzExMDIxMjIzMzdaMGAxCzAJBgNVBAYTAlVT\n"
  66. "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n"
  67. "b20xHzAdBgNVBAMTFkdlb1RydXN0IFRMUyBSU0EgQ0EgRzEwggEiMA0GCSqGSIb3\n"
  68. "DQEBAQUAA4IBDwAwggEKAoIBAQC+F+jsvikKy/65LWEx/TMkCDIuWegh1Ngwvm4Q\n"
  69. "yISgP7oU5d79eoySG3vOhC3w/3jEMuipoH1fBtp7m0tTpsYbAhch4XA7rfuD6whU\n"
  70. "gajeErLVxoiWMPkC/DnUvbgi74BJmdBiuGHQSd7LwsuXpTEGG9fYXcbTVN5SATYq\n"
  71. "DfbexbYxTMwVJWoVb6lrBEgM3gBBqiiAiy800xu1Nq07JdCIQkBsNpFtZbIZhsDS\n"
  72. "fzlGWP4wEmBQ3O67c+ZXkFr2DcrXBEtHam80Gp2SNhou2U5U7UesDL/xgLK6/0d7\n"
  73. "6TnEVMSUVJkZ8VeZr+IUIlvoLrtjLbqugb0T3OYXW+CQU0kBAgMBAAGjggFAMIIB\n"
  74. "PDAdBgNVHQ4EFgQUlE/UXYvkpOKmgP792PkA76O+AlcwHwYDVR0jBBgwFoAUTiJU\n"
  75. "IBiV5uNu5g/6+rkS7QYXjzkwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsG\n"
  76. "AQUFBwMBBggrBgEFBQcDAjASBgNVHRMBAf8ECDAGAQH/AgEAMDQGCCsGAQUFBwEB\n"
  77. "BCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMEIGA1Ud\n"
  78. "HwQ7MDkwN6A1oDOGMWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEds\n"
  79. "b2JhbFJvb3RHMi5jcmwwPQYDVR0gBDYwNDAyBgRVHSAAMCowKAYIKwYBBQUHAgEW\n"
  80. "HGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwDQYJKoZIhvcNAQELBQADggEB\n"
  81. "AIIcBDqC6cWpyGUSXAjjAcYwsK4iiGF7KweG97i1RJz1kwZhRoo6orU1JtBYnjzB\n"
  82. "c4+/sXmnHJk3mlPyL1xuIAt9sMeC7+vreRIF5wFBC0MCN5sbHwhNN1JzKbifNeP5\n"
  83. "ozpZdQFmkCo+neBiKR6HqIA+LMTMCMMuv2khGGuPHmtDze4GmEGZtYLyF8EQpa5Y\n"
  84. "jPuV6k2Cr/N3XxFpT3hRpt/3usU/Zb9wfKPtWpoznZ4/44c1p9rzFcZYrWkj3A+7\n"
  85. "TNBJE0GmP2fhXhP1D/XVfIW/h0yCJGEiV9Glm/uGOa3DXHlmbAcxSyCRraG+ZBkA\n"
  86. "7h4SeM6Y8l/7MBRpPCz6l8Y=\n"
  87. "-----END CERTIFICATE-----\n";
  88. /****************************** Feeds ***************************************/
  89. //Data Rate Limit: The free account has a limit of 30 data points per minute
  90. //e.g. [5] Data points every [10] seconds gives [30] data points every [1 minute]
  91. //increasing interval between sending data points to avoid restriction on the account
  92. static unsigned long timeBetweenDataPointsToBeSent = 12000;
  93. Adafruit_MQTT_Publish distance_mqtt_Publish = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/distance_mqtt");
  94. Adafruit_MQTT_Publish volume_mqtt_Publish = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/volume_mqtt");
  95. Adafruit_MQTT_Publish waterLevel_mqtt_Publish = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/waterLevel_mqtt");
  96. Adafruit_MQTT_Publish temprature_mqtt_Publish = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temprature_mqtt");
  97. Adafruit_MQTT_Publish tds_mqtt_Publish = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/tds_mqtt");
  98. //***********************************************************************************************************************
  99. //***********************************************************************************************************************
  100. //******************************************[ Variables for TDS Sensor ]*************************************************
  101. #define VREF 3.3 // Reference voltage of ESP32 (3.3V for most ESP32 boards)
  102. #define ADC_RESOLUTION 4095 // 12-bit ADC resolution for ESP32
  103. float temperature = 25; // Temperature in Celsius, adjust as needed
  104. float calibrationFactor = 0.6; // TDS calibration factor (default 0.5 for most sensors)
  105. //86 ppm
  106. int analogValueTDS;
  107. float voltageTDS;
  108. float tdsValue;
  109. //***********************************************************************************************************************
  110. //***********************************************************************************************************************
  111. //***********************************************[ Read TDS Sensor Function ]********************************************
  112. void ReadTDSSensor() {
  113. analogValueTDS = analogRead(TdsSensorPin); // Read analog value from sensor
  114. voltageTDS = analogValueTDS * VREF / ADC_RESOLUTION; // Convert to voltageTDS
  115. tdsValue = (voltageTDS / calibrationFactor) * 1000; // Calculate TDS in ppm
  116. tdsValue = tdsValue / (1.0 + 0.02 * (25 - 25.0)); // Temperature compensation
  117. Serial.println("-------------------------");
  118. Serial.print("TDS Value: ");
  119. Serial.print(tdsValue, 2);
  120. Serial.println(" ppm");
  121. Serial.println("-------------------------");
  122. }
  123. //***********************************************************************************************************************
  124. //***********************************************************************************************************************
  125. //**************************************************[ Telegram Setup ]***************************************************
  126. WiFiClientSecure Sclient;
  127. UniversalTelegramBot bot(BOTtoken, Sclient);
  128. unsigned long bot_lasttime;
  129. unsigned long mqtt_lasttime;
  130. bool Start = false;
  131. float value1 = 0;
  132. float value2 = 0;
  133. //***********************************************************************************************************************
  134. //***********************************************************************************************************************
  135. //******************************************[ Variables for Ultrasonic Sensor ]******************************************
  136. //define sound speed in cm/uS
  137. #define SOUND_SPEED 0.034
  138. float radius = 17; //half the diameter in [CM]
  139. float hight = 22; //hight of the container in [CM]
  140. long duration;
  141. float distanceCm;
  142. float volume_cm3;
  143. int waterLevel;
  144. int pumpONFlag = 0;
  145. int lastSentRange = -1; // Stores the last level sent to avoid repeated messages
  146. //***********************************************************************************************************************
  147. //***********************************************************************************************************************
  148. //*****************************************[ Temprature Sensor Setup ]***************************************************
  149. OneWire oneWire(oneWireBus);
  150. DallasTemperature sensors(&oneWire);
  151. float temperatureC;
  152. //***********************************************************************************************************************
  153. //***********************************************************************************************************************
  154. //**************************************************[ Main Setup Function ]**********************************************
  155. void setup() {
  156. Serial.begin(115200);
  157. SetupSensors();
  158. pumpOFF();
  159. SetupWiFiandTelegramBot();
  160. bot.sendMessage(CHAT_ID, "ESP32 Started");
  161. }
  162. //***********************************************************************************************************************
  163. //***********************************************************************************************************************
  164. //**************************************************[ Main Loop Function ]***********************************************
  165. void loop() {
  166. ReadDistanceUsingUltrasonicSensor();
  167. ReceiveMessageFromTelegram();
  168. ReadTempratureSensor();
  169. Publish_Sensor_Data();
  170. ReadTDSSensor();
  171. if (waterLevel < 10 && pumpONFlag == 0) {
  172. pumpON();
  173. pumpONFlag = 1;
  174. }
  175. else if (waterLevel > 90 && pumpONFlag == 1) {
  176. pumpOFF();
  177. pumpONFlag = 0;
  178. }
  179. int currentRange = getRange(waterLevel);
  180. // Check if the water level has changed
  181. if (currentRange != lastSentRange) {
  182. sendWaterLevelMessage(currentRange);
  183. lastSentRange = currentRange; // Update the last sent range
  184. }
  185.  
  186. if (tdsValue > 50) {
  187. unsigned long currentTimeee = millis(); // Get the current time in milliseconds
  188. // Check if one minute has passed since the last message
  189. if (currentTimeee - lastMessageTimeee >= MESSAGE_INTERVALeee) {
  190. String mssg = "TDS is High >50 - TDS: ";
  191. mssg += String(tdsValue, 2);
  192. bot.sendMessage(CHAT_ID, mssg);
  193.  
  194. // Update the last message time
  195. lastMessageTimeee = currentTimeee;
  196. }
  197.  
  198. }
  199.  
  200. /*
  201. if (waterLevel == 50) {
  202. bot.sendMessage(CHAT_ID, "Did you see the action message?");
  203. }
  204. */
  205. //delay(500);
  206. }
  207. //***********************************************************************************************************************
  208. //***********************************************************************************************************************
  209. //*************************************************[ Setup Sensors Function ]********************************************
  210. void SetupSensors() {
  211. pinMode(pumpRelayPin, OUTPUT);
  212. pinMode(TdsSensorPin, INPUT);
  213. pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  214. pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  215. sensors.begin();
  216. }
  217. //***********************************************************************************************************************
  218. //***********************************************************************************************************************
  219. //*************************************************[ Pump Functions ]********************************************
  220. void pumpON() {
  221. digitalWrite(pumpRelayPin, 1);
  222. delay(500);
  223. }
  224. void pumpOFF() {
  225. digitalWrite(pumpRelayPin, 0);
  226. delay(500);
  227. }
  228. //***********************************************************************************************************************
  229. //***********************************************************************************************************************
  230. //**********************************************[ Setup WiFi and Telegram Function]**************************************
  231. void SetupWiFiandTelegramBot() {
  232. // Connect to Wi-Fi
  233. WiFi.mode(WIFI_STA);
  234. WiFi.begin(ssid, password);
  235. Sclient.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
  236. while (WiFi.status() != WL_CONNECTED) {
  237. delay(1000);
  238. Serial.println("Wifi Connected..");
  239. }
  240. // Print ESP32 Local IP Address
  241. Serial.println(WiFi.localIP());
  242. Serial.print("Retrieving time: ");
  243. configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
  244. time_t now = time(nullptr);
  245. while (now < 24 * 3600) {
  246. Serial.print(".");
  247. delay(100);
  248. now = time(nullptr);
  249. }
  250. Serial.println(now);
  251. // Set Adafruit IO's root CA
  252. client.setCACert(adafruitio_root_ca);
  253. }
  254. //***********************************************************************************************************************
  255. //***********************************************************************************************************************
  256. //*********************************************[ Telegram Messages Function ]********************************************
  257. void handleNewMessages(int numNewMessages) {
  258. Serial.println("handleNewMessages");
  259. Serial.println(String(numNewMessages));
  260. for (int i = 0; i < numNewMessages; i++) {
  261. String chat_id = bot.messages[i].chat_id;
  262. String text = bot.messages[i].text;
  263. String from_name = bot.messages[i].from_name;
  264. if (from_name == "")
  265. from_name = "Guest";
  266. // Find position of ',' and '='
  267. int posA = text.indexOf("a=");
  268. int posB = text.indexOf("b=");
  269. if (posA != -1 && posB != -1) {
  270. // Extract values of a and b
  271. String value1String = text.substring(posA + 2, posB - 1);
  272. String value2String = text.substring(posB + 2);
  273. // Convert string values to integers
  274. value1 = value1String.toFloat();
  275. value2 = value2String.toFloat();
  276. }
  277. // Print extracted values for debugging
  278. Serial.print("Value of a: ");
  279. Serial.println(value1);
  280. Serial.print("Value of b: ");
  281. Serial.println(value2);
  282. if (text == "/send_test_action") {
  283. bot.sendChatAction(chat_id, "typing");
  284. delay(4000);
  285. bot.sendMessage(chat_id, "Did you see the action message?");
  286. }
  287. if (text == "/start") {
  288. String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
  289. welcome += "This is Chat Action Bot example.\n\n";
  290. welcome += "/send_test_action : to send test chat action message\n";
  291. bot.sendMessage(chat_id, welcome);
  292. }
  293. }
  294. }
  295. //***********************************************************************************************************************
  296. //***********************************************************************************************************************
  297. //******************************************[ Handel Telegram Messages Function ]****************************************
  298. void ReceiveMessageFromTelegram() {
  299. if (millis() - bot_lasttime > 1000) {
  300. int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
  301. while (numNewMessages) {
  302. Serial.println("got response");
  303. handleNewMessages(numNewMessages);
  304. numNewMessages = bot.getUpdates(bot.last_message_received + 1);
  305. }
  306. bot_lasttime = millis();
  307. }
  308. }
  309. //***********************************************************************************************************************
  310. //***********************************************************************************************************************
  311. //*************************************[ Read Ultrasonic Sensor Function ]***********************************************
  312. void ReadDistanceUsingUltrasonicSensor() {
  313. // Clears the trigPin
  314. digitalWrite(trigPin, LOW);
  315. delayMicroseconds(2);
  316. // Sets the trigPin on HIGH state for 10 micro seconds
  317. digitalWrite(trigPin, HIGH);
  318. delayMicroseconds(10);
  319. digitalWrite(trigPin, LOW);
  320. // Reads the echoPin, returns the sound wave travel time in microseconds
  321. duration = pulseIn(echoPin, HIGH);
  322. // Calculate the distance
  323. distanceCm = duration * SOUND_SPEED / 2;
  324. // Convert to Volume
  325. // ↓ Calibration Factor
  326. //volume_cm3 = int((hight - (-2 + distanceCm)) * 3.14 * radius * radius);
  327.  
  328. waterLevel = map((distanceCm - 2), 0, hight, 100, 0);
  329. if (waterLevel < 0) {
  330. waterLevel = 0;
  331. }
  332. if (waterLevel > 100) {
  333. waterLevel = 100;
  334. }
  335. // Prints the distance in the Serial Monitor
  336. Serial.print("Distance (cm): ");
  337. Serial.println(distanceCm);
  338. //Serial.print("Volume (CM^3): ");
  339. //Serial.println(volume_cm3);
  340. Serial.print("Water Level (%): ");
  341. Serial.println(waterLevel);
  342. }
  343. //***********************************************************************************************************************
  344. //***********************************************************************************************************************
  345. //*******************************************[ Read Temprature Sensor Function ]*****************************************
  346. void ReadTempratureSensor() {
  347. sensors.requestTemperatures();
  348. temperatureC = sensors.getTempCByIndex(0);
  349. Serial.print("Temprature (ΒΊC): ");
  350. Serial.println(temperatureC);
  351. }
  352. //***********************************************************************************************************************
  353. //***********************************************************************************************************************
  354. //******************************************[ Publish Data To Dashboard Function ]***************************************
  355. void Publish_Sensor_Data() {
  356. if (millis() - mqtt_lasttime > timeBetweenDataPointsToBeSent) {
  357. MQTT_connect();
  358. // Publish distance to MQTT Server
  359. float distanceChangeRate = abs((distanceCm - previousDistanceCm) / previousDistanceCm);
  360. if (distanceChangeRate > MIN_CHANGE_RATE || previousDistanceCm == 0) {
  361. if (!distance_mqtt_Publish.publish(distanceCm)) {
  362. Serial.println(F("distance_mqtt_Publish: Failed"));
  363. } else {
  364. Serial.println(F("distance_mqtt_Publish: OK!************************"));
  365. }
  366. previousDistanceCm = distanceCm;
  367. }
  368. /*
  369. // Publish volume to MQTT Server
  370. float volumeChangeRate = abs((volume_cm3 - previousVolume_cm3) / previousVolume_cm3);
  371. if (volumeChangeRate > MIN_CHANGE_RATE || previousVolume_cm3 == 0) {
  372. if (!volume_mqtt_Publish.publish(volume_cm3)) {
  373. Serial.println(F("volume_mqtt_Publish: Failed"));
  374. } else {
  375. Serial.println(F("volume_mqtt_Publish: OK!"));
  376. }
  377. previousVolume_cm3 = volume_cm3;
  378. }
  379. */
  380. // Publish waterLevel to MQTT Server
  381. float waterLevelChangeRate = abs((waterLevel - previousWaterLevel) / previousWaterLevel);
  382. if (waterLevelChangeRate > MIN_CHANGE_RATE || previousWaterLevel == 0) {
  383. if (!waterLevel_mqtt_Publish.publish(waterLevel)) {
  384. Serial.println(F("waterLevel_mqtt_Publish: Failed"));
  385. } else {
  386. Serial.println(F("waterLevel_mqtt_Publish: OK!************************"));
  387. }
  388. previousWaterLevel = waterLevel;
  389. }
  390. // Publish Temprature to MQTT Server
  391. float tempratureChangeRate = abs((temperatureC - previousTemperatureC) / previousTemperatureC);
  392. if (tempratureChangeRate > MIN_CHANGE_RATE || previousTemperatureC == 0) {
  393. if (!temprature_mqtt_Publish.publish(temperatureC)) {
  394. Serial.println(F("temprature_mqtt_Publish: Failed"));
  395. } else {
  396. Serial.println(F("temprature_mqtt_Publish: OK!************************"));
  397. }
  398. previousTemperatureC = temperatureC;
  399. }
  400. // Publish TDS to MQTT Server
  401. float tdsChangeRate = abs((tdsValue - previousTdsValue) / previousTdsValue);
  402. if (tdsChangeRate > MIN_CHANGE_RATE || previousTdsValue == 0) {
  403. if (!tds_mqtt_Publish.publish(tdsValue)) {
  404. Serial.println(F("tds_mqtt_Publish: Failed"));
  405. } else {
  406. Serial.println(F("tds_mqtt_Publish: OK!************************"));
  407. }
  408. previousTdsValue = tdsValue;
  409. }
  410.  
  411. mqtt_lasttime = millis();
  412. }
  413. }
  414. //***********************************************************************************************************************
  415. //***********************************************************************************************************************
  416. //******************************************[ Re/Connect to MQTT Server Function ]***************************-***********
  417. void MQTT_connect() {
  418. int8_t ret;
  419. // Stop if already connected.
  420. if (mqtt.connected()) {
  421. return;
  422. }
  423. Serial.print("Connecting to MQTT... ");
  424. uint8_t retries = 3;
  425. while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
  426. Serial.println(mqtt.connectErrorString(ret));
  427. Serial.println("Retrying MQTT connection in 5 seconds...");
  428. mqtt.disconnect();
  429. delay(5000); // wait 5 seconds
  430. retries--;
  431. if (retries == 0) {
  432. // basically die and wait for WDT to reset me
  433. while (1);
  434. }
  435. }
  436. Serial.println("MQTT Connected!");
  437. }
  438. //***********************************************************************************************************************
  439. //***********************************************************************************************************************
  440.  
  441. // Function to determine the range of the water level
  442. int getRange(int level) {
  443. if (level >= 0 && level < 10) return 0; // 0% range
  444. if (level >= 10 && level < 40) return 25; // 25% range
  445. if (level >= 40 && level <= 60) return 50; // 50% range
  446. if (level > 60 && level <= 90) return 75; // 75% range
  447. if (level > 90) return 100; // 100% range
  448. return -1; // Invalid range
  449. }
  450.  
  451. // Function to send a water level message
  452. void sendWaterLevelMessage(int range) {
  453. switch (range) {
  454. case 0:
  455. bot.sendMessage(CHAT_ID, "Water Level is at 0% - Critical low level!");
  456. break;
  457. case 25:
  458. bot.sendMessage(CHAT_ID, "Water Level is at 25% - Low level warning.");
  459. break;
  460. case 50:
  461. bot.sendMessage(CHAT_ID, "Water Level is at 50% - Half full.");
  462. break;
  463. case 75:
  464. bot.sendMessage(CHAT_ID, "Water Level is at 75% - Almost full.");
  465. break;
  466. case 100:
  467. bot.sendMessage(CHAT_ID, "Water Level is at 100% - Tank full!");
  468. break;
  469. default:
  470. // Do nothing for invalid ranges
  471. break;
  472. }
  473. }
Advertisement
Add Comment
Please, Sign In to add comment