// #include <Wire.h>
// #include <WiFi.h>
// #include <MQTT.h>
// #include <OneWire.h>
// #include <DallasTemperature.h>
// #include <NusabotSimpleTimer.h>
// // #include <CoreX.h>
// // #include "Connection.h"
// #define DSB_PIN 12
// #define TDS_PIN 35
// #define PH_PIN 26
// #define DO_PIN 32
// #define VREF 3300
// #define ADC_RES 4096
// // Single-point calibration Mode=0
// // Two-point calibration Mode=1
// #define TWO_POINT_CALIBRATION 0
// #define CAL1_V (131) // mv
// #define CAL1_T (25) // ℃
// #define CAL2_V (1300) // mv
// #define CAL2_T (15) // ℃
// const uint16_t DO_Table[41] = {
// 14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530,
// 11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270,
// 9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690,
// 7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410
// };
// // CoreXTimer timer;
// WiFiClient net;
// MQTTClient client;
// NusabotSimpleTimer timer;
// OneWire oneWire(DSB_PIN);
// DallasTemperature dsbSensor(&oneWire);
// uint8_t tempValue;
// uint16_t ADC_Raw, ADC_Voltage, DOValue;
// float phValue, TdsValue;
// const char* AUTH_TOKEN = "8xOYmo5DYIafEh3";
// const char* DEVICE_ID = "pzTDcYwlD";
// const char ssid[] = "Wokwi-GUEST";
// const char pass[] = "";
// int16_t readDO(uint32_t voltage_mv, uint8_t temperature_c) {
// #if TWO_POINT_CALIBRATION == 0
// uint16_t V_saturation = (uint32_t)CAL1_V + (uint32_t)35 * temperature_c - (uint32_t)CAL1_T * 35;
// return (voltage_mv * DO_Table[temperature_c] / V_saturation);
// #else
// uint16_t V_saturation = (int16_t)((int8_t)temperature_c - CAL2_T) * ((uint16_t)CAL1_V - CAL2_V) / ((uint8_t)CAL1_T - CAL2_T) + CAL2_V;
// return (voltage_mv * DO_Table[temperature_c] / V_saturation);
// #endif
// }
// void send() {
// dsbSensor.requestTemperatures();
// tempValue = dsbSensor.getTempCByIndex(0);
// phValue = ((float) analogRead(PH_PIN) / 4095.0) * 14;
// ADC_Raw = analogRead(DO_PIN);
// ADC_Voltage = (uint32_t)VREF * ADC_Raw / ADC_RES;
// DOValue = readDO(ADC_Voltage, tempValue);
// int16_t tdsValue = analogRead(TDS_PIN);
// float voltage1 = tdsValue * (5.0 / 4095.0);
// TdsValue = (voltage1 / 2.3) * 1000;
// // corex.send("temp", String(temperature));
// // corex.send("ph", String(phValue));
// // corex.send("do", String(DOValue));
// // corex.send("tds", String(TdsValue));
// client.publish("mqttx/affan/sensor/temp", String(tempValue), true, 1);
// client.publish("mqttx/affan/sensor/ph",String(phValue), true, 1);
// client.publish("mqttx/affan/sensor/do",String(DOValue), true, 1);
// client.publish("mqttx/affan/sensor/tds",String(TdsValue), true, 1);
// Serial.print("Temp: ");
// Serial.print(tempValue);
// Serial.println(" °C");
// Serial.print("pH : ");
// Serial.println(phValue);
// Serial.print("DO : ");
// Serial.print(DOValue);
// Serial.println(" ppm");
// Serial.print("TDS : ");
// Serial.print(TdsValue);
// Serial.println(" mg/L");
// Serial.println("");
// }
// void connectWiFi(){
// WiFi.begin(ssid, pass);
// Serial.print("Menghubungkan ke WiFi");
// while(WiFi.status() != WL_CONNECTED){
// Serial.print(".");
// delay(1000);
// }
// Serial.println("");
// Serial.println("Berhasil Terhubung ke WiFi");
// }
// void connectMQTT(){
// client.begin("broker.emqx.io", net);
// Serial.print("Menghubungkan ke Broker");
// while(!client.connect("98howeb")){
// Serial.print(".");
// delay(1000);
// }
// Serial.println("");
// Serial.println("Berhasil Terhubung ke Server");
// client.subscribe("mqttx/affan/sensor/#", 1);
// }
// void setup() {
// Wire.begin(23, 22);
// Serial.begin(115200);
// connectWiFi();
// connectMQTT();
// dsbSensor.begin();
// pinMode(TDS_PIN, INPUT);
// pinMode(PH_PIN, INPUT);
// pinMode(DO_PIN, INPUT);
// // WiFi.begin(ssid, pass);
// // while (WiFi.status() != WL_CONNECTED) {
// // delay(500);
// // Serial.println("Connecting to WiFi...");
// // }
// // corex.begin(net);
// timer.setInterval(1000, send);
// // setupCorex();
// }
// void loop() {
// delay(10);
// timer.run();
// if (!client.connected()){
// connectMQTT();
// }
// // if (!corex.connected()) {
// // setupCorex();
// // }
// }