mikroavr

gps_npk_nextion

Oct 28th, 2022
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 24.20 KB | None | 0 0
  1. /*2710/2022
  2.    nextion Serial 2
  3.    GPS SerialGPS RX 17 TX 16
  4.    hum dan NPK SErial NPK RS 27 TX 32 or 14
  5.    
  6.    editing nextion OK
  7.    editing NPK not ok - 27/10
  8.    
  9. */
  10.  
  11. #include <TinyGPS++.h>
  12. TinyGPSPlus gps;
  13. //#define ss Serial1
  14. #include <WiFi.h>
  15.  
  16. #define RXD_RS485 33 // rubah dari 27 ke 33
  17. #define TXD_RS485 32  //14 yg baru 32 yg lm
  18.  
  19. #define pinLed 13
  20.  
  21. #define RXD_GPS 17
  22. #define TXD_GPS 16
  23.  
  24. String str_lat = "";
  25. String str_lon = "";
  26. String str_date = "";
  27. String str_time = "";
  28.  
  29. int myIP;
  30. int _gauge_display;
  31. int val_sen, val_min;
  32. double val_max;
  33. const char* ssid     = "untan";
  34. const char* password = "";
  35.  
  36. int buf_detik, detik = 0;
  37. int jam, menit;
  38. int tahun, bulan, tanggal;
  39. int counter;
  40. int pin_value = 0;
  41. int progress_value;
  42. bool ledState = 0;
  43.  
  44. /*Nextion */
  45. uint16_t voltageGraph;   // a variable to store the reading
  46. // for simplicity reasons, we do not use float and we are going to take the measure in millivolts
  47.  
  48. const int volt = 34;
  49. int potValue = 0;
  50. const int REFRESH_TIME = 3000;           // time to refresh the Nextion page every 100 ms
  51. unsigned long refresh_timer = millis();
  52. unsigned long cur_time, old_time;
  53.  
  54. const byte hum[] =      {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
  55. //const byte hum[] =    {0x01, 0x03, 0x02, 0x00, 0x00, 0x02, 0xC5, 0xB3};
  56. const byte temp[] =     {0x01, 0x03, 0x00, 0x12, 0x00, 0x01, 0x24, 0x0f};
  57. const byte rh[] =       {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
  58. const byte condutiv[] = {0x01, 0x03, 0x00, 0x15, 0x00, 0x01, 0x95, 0xCE};
  59. const byte ph[] =       {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0B};
  60. const byte nitro[] =    {0x01, 0x03, 0x00, 0x1E, 0x00, 0x01, 0xE4, 0x0C};
  61. const byte phos[] =     {0x01, 0x03, 0x00, 0x1F, 0x00, 0x01, 0xB5, 0xCC};
  62. const byte pota[] =     {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xC0};
  63.  
  64. //const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
  65. //const byte sens[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x04, 0x08};
  66. //const byte hum[] =      {0x01, 0x03, 0x00, 0x12, 0x00, 0x02, 0x64, 0x0e};
  67.  
  68.  
  69. byte values[11];
  70. int val_hum = 0;
  71. int val_temp = 0;
  72. float val_ph = 0;
  73.  
  74. int val_con, val_nitro, val_phos, val_pota;
  75. int val_rh;
  76. String humid, temper, acid, nitrog, posf, kalium, con; //mjd string buat nextion
  77.  
  78. static uint8_t npkAddr = 1;
  79.  
  80. byte val1, val2, val3, val4, val5, val6, val7; //mjd hex
  81. int nit, pho, kal, soiltmp, soilrh, soilhum, soilph; //mjd angka
  82. //byte baca_nitro, baca_phos, baca_pota; //menjadi HEX
  83. //int  val_nitro, val_phos, val_pota; //menjadi angka
  84. //String nitrog, posf, kalium; //menjadi string buat nextion
  85. /*=========================================================================================================VOID SETUP===================================================================================*/
  86. void setup()
  87. {
  88.   delay(100);
  89.   pinMode(pinLed, OUTPUT);
  90.   Serial.begin(115200);
  91.   Serial2.begin(9600, SERIAL_8N1, 35, 15); // nextion serial
  92.   delay(100);
  93.   WiFi.mode(WIFI_STA);
  94.   WiFi.begin(ssid, password);
  95.   int timeout = 10 * 4; // 10 seconds
  96.   while (WiFi.status() != WL_CONNECTED  && (timeout-- > 0)) {
  97.     delay(250);
  98.   }
  99.   Serial.println("");
  100.  
  101.   if (WiFi.status() != WL_CONNECTED) {
  102.     Serial.println("Failed to connect");
  103.   }
  104.   //Serial.print("WiFi connected in: ");
  105.   //Serial.print(millis());
  106.   Serial.print(ssid);
  107.   Serial.print(":");
  108.   Serial.println(WiFi.localIP());
  109.   myIP = WiFi.localIP();
  110.   String statIP = String(myIP);
  111.   tampil_text("IP", statIP);
  112.   Serial.println(statIP);
  113.   Serial.println(myIP);
  114.   delay(100);
  115. }
  116.  
  117. /*============================================================================================================VOID LOOP================================================================================*/
  118.  
  119. void loop() {
  120. byte val1, val2, val3, val4, val5, val6, val7;
  121. //-------------------------------------task 1 -----------------------------------------------
  122.   cur_time = millis();
  123.   if (cur_time - old_time >= 3000) {
  124.     Serial.println("baca Sensor");
  125.     serial_rs485();
  126.     //for (int i = 0; i < 11; i++) {
  127.       //baca_hum();
  128.       //baca_npk;
  129.           val1 = baca_nitro();
  130.           nit = val1;
  131.           delay(250);
  132.           Serial.print("N:");
  133.           Serial.println(nit);
  134.           val_nitro = val1;
  135.    
  136.           val2 = baca_phos();
  137.           pho = val2;
  138.           delay(250);
  139.           Serial.print("P:");
  140.           Serial.println(pho);
  141.           val_phos=val2;
  142.    
  143.           val3 = baca_pota();
  144.           kal = val3;
  145.           delay(250);
  146.           Serial.print("K:");
  147.           Serial.println(kal);
  148.           val_pota=val3;
  149.    
  150.           val4 = baca_hum();
  151.           soilhum = val4;
  152.          
  153.           delay(250);
  154.           Serial.print("Hum:");
  155.           Serial.println(soilhum);
  156.    
  157.           val5 = baca_temp();
  158.           soiltmp = val5;
  159.           delay(250);
  160.           Serial.print("Temp:");
  161.           Serial.println(soiltmp);
  162.    
  163.           val6 = baca_rh();
  164.           soilrh = val6;
  165.           delay(250);
  166.           Serial.print("EC:");
  167.           Serial.println(soilrh);
  168.           delay(250);
  169.           val7 = baca_ph();
  170.           soilph = val7;
  171.           delay(250);
  172.           Serial.print("pH:");
  173.           Serial.println(soilph);
  174.           delay(250);
  175.  
  176.     //}
  177.    
  178.     serial_gps();
  179.     //sent_nextion;
  180.     for (int i = 0; i < 3; i++) {
  181.       read_gps();
  182.       delay(250);
  183.     }
  184.     old_time = millis();
  185. }
  186.  
  187. //-------------------------------------task 2 -----------------------------------------------
  188.  
  189.   if ((millis() - refresh_timer) > REFRESH_TIME) { //IMPORTANT do not have serial print commands in the loop without a delay
  190.     // or an if statement with a timer condition like this one.
  191.  
  192.     //potValue = analogRead(volt);  // Read the analog pin
  193.     //voltageGraph = map(potValue, 0, 4095, 0, 100);
  194.     //Serial.print("volt  ");
  195.     //Serial.println(voltageGraph);
  196.     counter++;
  197.     val_max = counter;
  198.     Serial.println(val_max);
  199.     //baca_npk;
  200.     tampil_text("statssid", ssid);
  201.     tampil_text("twea", "35");
  202.     tampil_text("tweh", "79");
  203.     kirim_val("jtemp", "35");
  204.     kirim_slider("jtemp", 3);
  205.     String Moisture = String(soilhum);
  206.     String humid = String(soilhum);
  207.     String temper = String(soiltmp);
  208.     String con = String (soilrh);
  209.     String acid = String (soilph);
  210.     String nitrog = String(nit);
  211.     String posf = String (pho);
  212.     String kalium = String (kal);
  213.    
  214.       tampil_text("tp1", humid); //hum
  215.       tampil_text("tp2", temper); //val_temp
  216.       tampil_text("tp3", acid); //value 8
  217.       tampil_text("tp4", con); // value tds
  218.       tampil_text("t7", nitrog); // nitrogen = String (values[8]);
  219.       tampil_text("t8", posf); //String posf = String (values[i]);
  220.       tampil_text("t9", kalium); //String kalium = String (values[i]);
  221.       tampil_text("t7", nitrog); // nitrogen = String (values[8]);
  222.       tampil_text("t8", posf); //String posf = String (values[i]);
  223.       tampil_text("t9", kalium); //String kalium = String (values[i]);
  224.       tampil_text("tp4", con); // value tds
  225.      
  226.     tampil_text("th1", Moisture);
  227.     tampil_text("th2", Moisture);
  228.     tampil_text("th3", Moisture);
  229.     tampil_text("th4", Moisture);
  230.     tampil_text("th5", Moisture);
  231.     tampil_text("th6", Moisture);
  232.  
  233.     kirim_val("j0", Moisture);
  234.     kirim_val("jn", nitrog);
  235.     kirim_val("jp", posf);
  236.     kirim_val("jk", kalium);
  237.     kirim_val("jth", Moisture);
  238.     kirim_val("jtds", Moisture);
  239.     kirim_val("jtur", Moisture);
  240.  
  241.  
  242.     kirim_val("h0", humid); // tipe : text
  243.     kirim_val("h1", temper);
  244.     kirim_val("h2", acid);
  245.     kirim_val("h3", con);
  246.    
  247.    
  248.     kirim_val("z0", nitrog);
  249.     kirim_val("z1", posf);
  250.     kirim_val("z2", kalium);
  251.     kirim_val("z3", Moisture);
  252.     kirim_val("zf", Moisture);
  253.  
  254.     kirim_gauge("z0", val_nitro);
  255.     kirim_gauge("z1", val_phos);
  256.     kirim_gauge("z2", val_pota);
  257.     kirim_gauge("z3", val_max);
  258.     kirim_gauge("zf", val_max);
  259.  
  260.     kirim_slider("j0", val_max); //type text
  261.     kirim_slider("jn", val1);
  262.     kirim_slider("jp", val2);
  263.     kirim_slider("jk", val3);
  264.     kirim_slider("jth", val_max);
  265.     kirim_slider("jtds", val_max);
  266.     kirim_slider("jtur", val_max);
  267.  
  268.     kirim_slider("h0", val_hum);
  269.     kirim_slider("h1", val_temp);
  270.     kirim_slider("h2", val_ph);
  271.     kirim_slider("h3", val_rh);
  272.  
  273.  
  274.  
  275.     tampil_text("tssn", Moisture);
  276.     kirim_val("tssn", Moisture);
  277.     //kirim_slider("tssn", Moisture);
  278.     kirim_wave(val_max);
  279.  
  280.     refresh_timer = millis();  // Set the timer equal to millis, create a time stamp to start over the "delay"
  281.     //old_time = millis();
  282.  
  283.   }
  284. }
  285.  
  286. /*===================================================================================================================END  VOID LOOP =========================================================================*/
  287.  
  288. void serial_rs485() {
  289.   Serial1.begin(4800, SERIAL_8N1, RXD_RS485, TXD_RS485);
  290.  
  291.   delay(500);
  292. }
  293.  
  294. void serial_gps() {
  295.   Serial1.begin(9600, SERIAL_8N1, RXD_GPS, TXD_GPS);
  296.   delay(500);
  297. }
  298. void read_gps() {
  299.   while (Serial1.available() > 0)
  300.     if (gps.encode(Serial1.read()))
  301.       displayInfo();
  302.  
  303.   if (millis() > 5000 && gps.charsProcessed() < 5) //jlh kirim koordinat d serial print
  304.   {
  305.     Serial.println(F("No GPS detected: check wiring."));
  306.     while (true);
  307.   }
  308.   if (buf_detik != detik) {
  309.     String str_buf_date = "";
  310.     String str_buf_time = "";
  311.  
  312.     String str_tgl = "";
  313.     String str_bln = "";
  314.  
  315.     String str_jam = "";
  316.     String str_menit = "";
  317.     String str_detik = "";
  318.  
  319.     str_bln = bulan < 10 ? "0" + String(bulan) : String(bulan);
  320.     str_tgl = tanggal < 10 ? "0" + String(tanggal) : String(tanggal);
  321.  
  322.     str_buf_date = str_bln + "/" + str_tgl + "/" + String(tahun) + " ";
  323.     str_date = str_buf_date;
  324.  
  325.     Serial.print(" tanggal/jam: ");
  326.     Serial.print(str_date);
  327.     tampil_text("t0", str_date);
  328.  
  329.  
  330.     str_detik = detik < 10 ? "0" + String(detik) : String(detik);
  331.     str_menit = menit < 10 ? "0" + String(menit) : String(menit);
  332.     str_jam = jam < 10 ? "0" + String(jam) : String(jam);
  333.  
  334.  
  335.     str_buf_time = str_jam + ":" + str_menit + ":" + str_detik;
  336.     str_time = str_buf_time;
  337.     Serial.print(str_time);
  338.     Serial.println();
  339.     tampil_text("t1", str_time);
  340.     buf_detik = detik;
  341.  
  342.   }
  343. }
  344.  
  345. void displayInfo() {
  346.  
  347.   if (gps.date.isValid())
  348.   {
  349.     bulan = gps.date.month();
  350.     tanggal = gps.date.day();
  351.     tahun = gps.date.year();
  352.  
  353.   }
  354.   else
  355.   {
  356.     Serial.print(F("INVALID"));
  357.   }
  358.  
  359.   if (gps.time.isValid())
  360.   {
  361.     jam =  gps.time.hour();
  362.     detik = gps.time.second();
  363.     menit = gps.time.minute();
  364.  
  365.     //convert to local zone, indonesia + 7
  366.     jam = jam + 7;
  367.     if (jam >= 24 ) {
  368.       jam = jam - 24;
  369.     }
  370.   }
  371.   else
  372.   {
  373.     Serial.print(F("INVALID"));
  374.   }
  375.   String str_buf_lat = "";
  376.   String str_buf_lon = "";
  377.   String str_buf_date = "";
  378.   String str_buf_time = "";
  379.   Serial.print(F("Location: "));
  380.   if (gps.location.isValid())
  381.   {
  382.     str_buf_lat = String(gps.location.lat(), 6);
  383.     str_buf_lon = String(gps.location.lng(), 6);
  384.     Serial.print(str_buf_lat); Serial.print(",");
  385.     Serial.println(str_buf_lon);
  386.     tampil_text("tkx", str_buf_lat);
  387.     tampil_text("tky", str_buf_lon);
  388.   }
  389.   else
  390.   {
  391.     Serial.print(F("INVALID"));
  392.     tampil_text("tkx", "LOST");
  393.     tampil_text("tky", "SIGNAL");
  394.   }
  395. }
  396. /*
  397. void sent_nextion() {
  398.     tampil_text("statssid", ssid);
  399.     tampil_text("twea", "35");
  400.     tampil_text("tweh", "79");
  401.     kirim_val("jtemp", "35");
  402.     kirim_slider("jtemp", 3);
  403.     String Moisture = String(val_hum);
  404.     String humid = String(soilhum);
  405.     String temper = String(soiltmp);
  406.     String con = String (soilrh);
  407.     String acid = String (soilph);
  408.     String nitrog = String(nit);
  409.     String posf = String (pho);
  410.     String kalium = String (kal);
  411.    
  412.       tampil_text("tp1", humid); //hum
  413.       tampil_text("tp2", temper); //val_temp
  414.       tampil_text("tp3", acid); //value 8
  415.       tampil_text("tp4", con); // value tds
  416.       tampil_text("t7", nitrog); // nitrogen = String (values[8]);
  417.       tampil_text("t8", posf); //String posf = String (values[i]);
  418.       tampil_text("t9", kalium); //String kalium = String (values[i]);
  419.       tampil_text("t7", nitrog); // nitrogen = String (values[8]);
  420.       tampil_text("t8", posf); //String posf = String (values[i]);
  421.       tampil_text("t9", kalium); //String kalium = String (values[i]);
  422.       tampil_text("tp4", con); // value tds
  423.      
  424.     tampil_text("th1", Moisture);
  425.     tampil_text("th2", Moisture);
  426.     tampil_text("th3", Moisture);
  427.     tampil_text("th4", Moisture);
  428.     tampil_text("th5", Moisture);
  429.     tampil_text("th6", Moisture);
  430.  
  431.     kirim_val("j0", Moisture);
  432.     kirim_val("jn", Moisture);
  433.     kirim_val("jp", Moisture);
  434.     kirim_val("jk", Moisture);
  435.     kirim_val("jth", Moisture);
  436.     kirim_val("jtds", Moisture);
  437.     kirim_val("jtur", Moisture);
  438.  
  439.  
  440.     kirim_val("h0", Moisture);
  441.     kirim_val("h1", Moisture);
  442.     kirim_val("h2", Moisture);
  443.     kirim_val("h3", Moisture);
  444.  
  445.     kirim_val("z0", Moisture);
  446.     kirim_val("z1", Moisture);
  447.     kirim_val("z2", Moisture);
  448.     kirim_val("z3", Moisture);
  449.     kirim_val("zf", Moisture);
  450.  
  451.     kirim_gauge("z0", val_max);
  452.     kirim_gauge("z1", val_max);
  453.     kirim_gauge("z2", val_max);
  454.     kirim_gauge("z3", val_max);
  455.     kirim_gauge("zf", val_max);
  456.  
  457.     kirim_slider("j0", val_max);
  458.     kirim_slider("jn", val_max);
  459.     kirim_slider("jp", val_max);
  460.     kirim_slider("jk", val_max);
  461.     kirim_slider("jth", val_max);
  462.     kirim_slider("jtds", val_max);
  463.     kirim_slider("jtur", val_max);
  464.  
  465.     kirim_slider("h0", val_max);
  466.     kirim_slider("h1", val_max);
  467.     kirim_slider("h2", val_max);
  468.     kirim_slider("h3", val_max);
  469.  
  470.  
  471.  
  472.     tampil_text("tssn", Moisture);
  473.     kirim_val("tssn", Moisture);
  474.     //kirim_slider("tssn", Moisture);
  475.     kirim_wave(val_max);
  476. }
  477.  
  478.  
  479. /*====================================================================================================*/
  480. /*
  481. byte baca_hum() {
  482.  
  483.   delay(10);
  484.   if (Serial1.write(hum, sizeof(hum)) == 8) {
  485.     for (byte i = 0; i < 9; i++) {
  486.       values[i] = Serial1.read();
  487.       Serial.print(values[i], HEX);
  488.       Serial.print(",");
  489.     }
  490.     Serial.println();
  491.   }
  492.   Serial.print(values[3], HEX);
  493.   Serial.println(values[4], HEX);
  494.  
  495.   Serial.print(values[5], HEX);
  496.   Serial.println(values[6], HEX);
  497.  
  498.   val_hum = (values[3] << 8);// | values[4];
  499.   val_temp = (values[5] << 8);// | values[6];
  500.   String Moisture = String(val_hum);
  501.   String Soiltemp = String(val_temp);
  502.  
  503.   Serial.print("hum: ");
  504.   Serial.println(val_hum);
  505.   tampil_text("tp1", Moisture); //hum
  506.   Serial.print("temp: ");
  507.   Serial.println(val_temp);
  508.   tampil_text("tp3", soiltemp); //value 8
  509. return values[4];
  510. }*/
  511.  
  512.  
  513. /*=================================================================================================================================================================================================*/
  514.  
  515. byte baca_hum() {
  516.   delay(10);
  517.   if (Serial1.write(hum, sizeof(hum)) == 8) {
  518.     for (byte i = 0; i < 7; i++) {
  519.       values[i] = Serial1.read();
  520.       Serial.print(values[i], HEX);
  521.       Serial.print(",");
  522.       val_hum = (values[i], HEX);
  523.      
  524.       //String con = String (val_rh);
  525.       //tampil_text("tp4", con); // value tds
  526.  
  527.     }
  528.     Serial.println();
  529.   }
  530.   return values[4];
  531. }
  532.  
  533. byte baca_temp() {
  534.   delay(10);
  535.   if (Serial1.write(temp, sizeof(temp)) == 8) {
  536.     for (byte i = 0; i < 7; i++) {
  537.       values[i] = Serial1.read();
  538.       Serial.print(values[i], HEX);
  539.       Serial.print(",");
  540.       val_temp = (values[i], HEX);
  541.       //String con = String (val_rh);
  542.       //tampil_text("tp4", con); // value tds
  543.     }
  544.     Serial.println();
  545.   }
  546.   return values[4];
  547. }
  548.  
  549. byte baca_rh() {
  550.   delay(10);
  551.   if (Serial1.write(rh, sizeof(rh)) == 8) {
  552.     for (byte i = 0; i < 7; i++) {
  553.       values[i] = Serial1.read();
  554.       Serial.print(values[i], HEX);
  555.       Serial.print(",");
  556.       val_rh = (values[i], HEX);
  557.       //String con = String (val_rh);
  558.       //tampil_text("tp4", con); // value tds
  559.  
  560.     }
  561.     Serial.println();
  562.   }
  563.   return values[4];
  564. }
  565.  
  566. byte baca_con() {
  567.   delay(10);
  568.   if (Serial1.write(condutiv, sizeof(condutiv)) == 8) {
  569.     for (byte i = 0; i < 7; i++) {
  570.       values[i] = Serial1.read();
  571.       Serial.print(values[i], HEX);
  572.       val_con = (values[i], HEX);
  573.       Serial.print(",");
  574.     }
  575.     Serial.println();
  576.   }
  577.   return values[4];
  578. }
  579.  
  580. byte baca_ph() {
  581.   delay(100);
  582.   if (Serial1.write(ph, sizeof(ph)) == 8) {
  583.     for (byte i = 0; i < 7; i++) {
  584.       values[i] = Serial1.read();
  585.       Serial.print(values[i], HEX);
  586.       //String soilph = String (values[i], HEX);
  587.       //tampil_text("tp3", soilph); // ph = String (values[8]);
  588.       Serial.print(",");
  589.     }
  590.     Serial.println();
  591.   }
  592.   return values[4];
  593. }
  594.  
  595. byte baca_nitro() {
  596.   delay(10);
  597.   if (Serial1.write(nitro, sizeof(nitro)) == 8) {
  598.     for (byte i = 0; i < 7; i++) {
  599.       values[i] = Serial1.read();
  600.       Serial.print(values[i], HEX);
  601.       val_nitro = (values[i], HEX);
  602.       //tampil_text("t7", nitrogen); // nitrogen = String (values[8]);
  603.  
  604.       Serial.print(",");
  605.     }
  606.     Serial.println();
  607.   }
  608.   return values[4];
  609. }
  610.  
  611. byte baca_phos() {
  612.   delay(10);
  613.   if (Serial1.write(phos, sizeof(phos)) == 8) {
  614.     for (byte i = 0; i < 7; i++) {
  615.       values[i] = Serial1.read();
  616.       Serial.print(values[i], HEX);
  617.       //String posf = String (values[i], HEX);
  618.       //tampil_text("t8", posf); //String posf = String (values[i]);
  619.       Serial.print(",");
  620.     }
  621.     Serial.println();
  622.   }
  623.   return values[4];
  624. }
  625.  
  626. byte baca_pota() {
  627.   delay(10);
  628.   if (Serial1.write(pota, sizeof(pota)) == 8) {
  629.     for (byte i = 0; i < 7; i++) {
  630.       values[i] = Serial1.read();
  631.       Serial.print(values[i], HEX);
  632.       //String kalium = String (values[i], HEX);
  633.       //tampil_text("t9", kalium); //String kalium = String (values[i]);
  634.  
  635.       Serial.print(",");
  636.     }
  637.     Serial.println();
  638.   }
  639.   return values[4];
  640. }
  641. /*========================================================================================================================================================================================================
  642. void baca_npk() {
  643.  
  644.   //for (int i = 0; i < 11; i++) {
  645.           val1 = baca_nitro();
  646.           nit = val1;
  647.           delay(250);
  648.           Serial.print("N:");
  649.           Serial.println(nit);
  650.    
  651.           val2 = baca_phos();
  652.           pho = val2;
  653.           delay(250);
  654.           Serial.print("P:");
  655.           Serial.println(pho);
  656.    
  657.           val3 = baca_pota();
  658.           kal = val3;
  659.           delay(250);
  660.           Serial.print("K:");
  661.           Serial.println(kal);
  662.          
  663.    
  664.           val4 = baca_hum();
  665.           soilhum = val4;
  666.           delay(250);
  667.           Serial.print("Hum:");
  668.           Serial.println(soilhum);
  669.    
  670.           val5 = baca_temp();
  671.           soiltmp = val5;
  672.           delay(250);
  673.           Serial.print("Temp:");
  674.           Serial.println(soiltmp);
  675.    
  676.           val6 = baca_rh();
  677.           soilrh = val6;
  678.           delay(250);
  679.           Serial.print("EC:");
  680.           Serial.println(soilrh);
  681.           delay(250);
  682.  
  683.           val7 = baca_ph();
  684.           soilph = val7;
  685.           delay(250);
  686.           Serial.print("pH:");
  687.           Serial.println(soilph);
  688.           delay(250);
  689.  
  690.  
  691.   /*String (nitrog) = String(nit);
  692.   Serial.println(" mg/kg");
  693.   tampil_text("t7", nitrog); // nitrogen = String (values[8]);
  694.  
  695.   Serial.print("Phosphorous: ");
  696.   Serial.print(pho);
  697.   Serial.println(" mg/kg");
  698.   //String posf = String (pho);
  699.   //tampil_text("t8", posf); //String posf = String (values[i]);
  700.  
  701.   Serial.print("Potassium: ");
  702.   Serial.print(kal);
  703.   Serial.println(" mg/kg");
  704.   //String kalium = String (kal);
  705.   //tampil_text("t9", kalium); //String kalium = String (values[i]);
  706.  
  707.   Serial.print("EC:  ");
  708.   Serial.print(val_rh);
  709.   Serial.println(" us");
  710.   //String con = String (val_rh);
  711.   //tampil_text("tp4", con); // value tds*/
  712. //}
  713. /*============================================================================================================================================================================================*/
  714. void tampil_text(String _add_txt, String _txt_display) {
  715.   String buf_txt = _add_txt + ".txt="  + "\"" + _txt_display + "\"";
  716.   Serial2.print(buf_txt);
  717.   Serial2.write(0xff);
  718.   Serial2.write(0xff);
  719.   Serial2.write(0xff);
  720. }
  721.  
  722. void kirim_val(String _add_slide, String _txt_display) {
  723.   String buf_slider = _add_slide + ".val="  + "\"" + _txt_display + "\"";
  724.   Serial2.print(buf_slider);
  725.   Serial2.write(0xff);
  726.   Serial2.write(0xff);
  727.   Serial2.write(0xff);
  728. }
  729. void kirim_gauge(String _add_gauge, int _gauge_display) {
  730.   String warna_jingga = _add_gauge + ".pco=64520";
  731.   String warna_merah = _add_gauge + ".pco=63488";
  732.   String warna_kuning = _add_gauge + ".pco=65519";
  733.   String warna_hijau = _add_gauge + ".pco=34784";
  734.   String warna_bg_green = _add_gauge + ".pco=1024";
  735.   int sensgauge = constrain(_gauge_display, 0, 255); //(buf_senval,0,2048);
  736.   int val_gauge = map(sensgauge, 0, 255, 0, 180); //(sens, 300, 2048, 50, 0);
  737.   Serial2.print("valgauge");
  738.   Serial2.print(val_gauge);
  739.   Serial2.print(_add_gauge);
  740.   Serial2.print(".val=");
  741.   Serial2.print(val_gauge);
  742.   Serial2.write(0xff);
  743.   Serial2.write(0xff);
  744.   Serial2.write(0xff);
  745.   //String buf_gauge = _add_gauge + ".val="  + "\"" + val_gauge+ "\"";
  746.   //Serial1.print(buf_gauge);
  747.   if (val_gauge <= 15) { //}for (val_min > 80; val_min <= 100; val_min++){
  748.     Serial2.print(warna_merah);
  749.     Serial2.write(0xff);
  750.     Serial2.write(0xff);
  751.     Serial2.write(0xff);
  752.   } else if ((val_gauge > 15) && (val_gauge <= 37)) {
  753.     Serial2.print(warna_jingga);
  754.     Serial2.write(0xff);
  755.     Serial2.write(0xff);
  756.     Serial2.write(0xff);
  757.   } else if ((val_gauge > 37) && (val_gauge <= 60)) {
  758.     Serial2.print(warna_kuning);
  759.     Serial2.write(0xff);
  760.     Serial2.write(0xff);
  761.     Serial2.write(0xff);
  762.   } else if ((val_gauge > 60) && (val_gauge <= 80)) {
  763.     Serial2.print(warna_hijau);
  764.     Serial2.write(0xff);
  765.     Serial2.write(0xff);
  766.     Serial2.write(0xff);
  767.   } else if ((val_gauge > 80) && (val_gauge <= 100)) {
  768.     Serial2.print(warna_bg_green);
  769.     Serial2.write(0xff);
  770.     Serial2.write(0xff);
  771.     Serial2.write(0xff);
  772.   } delay(100);
  773. }
  774.  
  775.  
  776. void kirim_slider(String _add_col, int val_sen) {
  777.   //String warna_biru = _add_col + ".pco=64520";
  778.   String warna_merah = _add_col + ".pco=63488";
  779.   String warna_kuning = _add_col + ".pco=65519";
  780.   String warna_hijau = _add_col + ".pco=34784";
  781.   String warna_bg_green = _add_col + ".pco=1024";
  782.  
  783.   //int buf_senval = val_sen.toInt();
  784.   int sens = constrain(val_sen, 0, 400); //(buf_senval,0,2048);
  785.   int val_min = map(sens, 0, 400, 0, 100); //(sens, 300, 2048, 50, 0);
  786.   //String buf_slider = _add_col + ".val="  + "\"" + val_min+ "\"";
  787.   //Serial1.print(buf_slider);
  788.   Serial2.print(_add_col);
  789.   Serial2.print(".val=");
  790.   Serial2.print(val_min);
  791.   Serial2.write(0xff);
  792.   Serial2.write(0xff);
  793.   Serial2.write(0xff);
  794.   if (val_min <= 20) { //}for (val_min > 80; val_min <= 100; val_min++){
  795.     Serial2.print(warna_merah);
  796.     Serial2.write(0xff);
  797.     Serial2.write(0xff);
  798.     Serial2.write(0xff);
  799.   } else if ((val_min > 20) && (val_min <= 40)) {
  800.     Serial2.print(warna_hijau);
  801.     Serial2.write(0xff);
  802.     Serial2.write(0xff);
  803.     Serial2.write(0xff);
  804.   } else if ((val_min > 40) && (val_min <= 60)) {
  805.     Serial2.print(warna_bg_green);
  806.     Serial2.write(0xff);
  807.     Serial2.write(0xff);
  808.     Serial2.write(0xff);
  809.   } else if ((val_min > 60) && (val_min <= 80)) {
  810.     Serial2.print(warna_kuning);
  811.     Serial2.write(0xff);
  812.     Serial2.write(0xff);
  813.     Serial2.write(0xff);
  814.   } else if ((val_min > 80) && (val_min <= 100)) {
  815.     Serial2.print(warna_merah);
  816.     Serial2.write(0xff);
  817.     Serial2.write(0xff);
  818.     Serial2.write(0xff);
  819.   } delay(100);
  820. }
  821.  
  822. void kirim_wave(int wave_val) {
  823.   int senswave = constrain(wave_val, 0, 255); //(buf_senval,0,2048);
  824.   int val_wave = map(senswave, 0, 255, 0, 255); //(sens, 300, 2048, 50, 0);
  825.   Serial1.print("valwave");
  826.   Serial1.print(val_wave);
  827.   //Serial1.print("add 1,1," + val_wave);
  828.   String tosend = "add ";
  829.   tosend += 1;//id
  830.   tosend += ",";
  831.   tosend += 1; //channel
  832.   tosend += ",";
  833.   tosend += val_wave;
  834.   Serial1.print(tosend);
  835.   Serial1.write(0xff);
  836.   Serial1.write(0xff);
  837.   Serial1.write(0xff);
  838.   delay(600);
  839. }
Add Comment
Please, Sign In to add comment