Blynk ตั้งค่าอุณหภูมิ และความชื้น DHT 21 ด้วยการตั้งค่าสไลด์บาร์ V2

โปรแจคที่ทำคือ สมาร์ทฟาร์ม ครับ
ปัญหาของผมคือต้องการใช้ Slider bar blynk ส่งค่าไปให้ node ESP8266 เพื่อตั้งค่าอุณหภูมิตามที่ผมต้องการตามรูปด้านล่าง
image
จากนั้นผมได้เข้าไปอ่านข้อมูลที่น้า adminnop นพพร ศิริกุล และ Permpol Thanapunnamas (ถ้าพิมพ์ชื่อไม่ถูกต้องขออภัยด้วยครับ) ได้แนะแนวทางและได้ไปลองปรับใช้ผลออกมาสามารถปรับได้ครับตาม code ด้านล่างเลย

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SimpleDHT.h>
#include <TimeLib.h>
#include <DHT.h>
#include <DHT_U.h>
#include <TridentTD_LineNotify.h>  //thank you Mr.TridentTD https://github.com/TridentTD/TridentTD_LineNotify
#define  DHTPIN            12     // กำหนดขาให้กับอุปกรณ์ตรวจสอบความชื้น DHT11
#define  DHTTYPE           DHT11  
//////////////////////////////////////////จุดที่เพิ่ม


int setTemp;
int setHumid;


BLYNK_WRITE(V22) //temperature slider in app on pin V22
{ 
  setTemp = param.asInt();
}
BLYNK_WRITE(V23) //temperature slider in app on pin V23
{ 
  setHumid = param.asInt();
}

//////////////////////////////////////////

DHT_Unified dht(DHTPIN, DHTTYPE);

//***BLYNK TOKEN**//
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";


//***LINE TOKEN***//
#define LINE_TOKEN  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

SimpleTimer timer;


BLYNK_CONNECTED() {
  Blynk.syncAll();
}

void setup()
{
  Serial.begin(115200);
  Serial.println("xxxxxxx");
  Serial.println("xxxxxxxx");
  Serial.println(LINE.getVersion());
  LINE.setToken(LINE_TOKEN);
  LINE.notify("myarduino.net");

  Blynk.begin(auth, "xxxx", "xxxxxxxx"); //ใส่ชื่อ WIFI and PASSWORD


  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  pinMode(D1, OUTPUT); //***ควบคุมอุณหภูมิ***///
  digitalWrite(D1, HIGH);
  
  dht.begin();

  timer.setInterval(1000L, sendUptime);

}

void sendUptime()
{
  //*****ชุดคำสั่งการทำงานของอุณหภูมิ******//
  Blynk.virtualWrite(V5, millis() / 1000);
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  if (!isnan(event.temperature)) {
    Blynk.virtualWrite(V1, event.temperature);
    if (event.temperature >= `setTemp`) {
      digitalWrite(D1, LOW);
      String LineText;
      String string1 = "อุณหภูมิ ต่ำกว่ากำหนด ";
      String string2 = " °C";
      LineText = string1 + event.temperature + string2;
      Serial.print("Line ");
      Serial.println(LineText);
      LINE.notify(LineText);
    } 
    else {
      digitalWrite(D1, HIGH);
    }
    }
  dht.humidity().getEvent(&event);
  if (!isnan(event.relative_humidity)) {
    Blynk.virtualWrite(V2, event.relative_humidity);
    if (event.temperature >= `setHumid`) {
      digitalWrite(D7, LOW);
      String LineText;
      String string1 = "ความชื้น ต่ำกว่ากำหนด ";
      String string2 = " %";
      LineText = string1 + event.temperature + string2;
      Serial.print("Line ");
      Serial.println(LineText);
      LINE.notify(LineText);
    }
    else {
      digitalWrite(D7, HIGH);
  }
  }
}

//*********************************************************//

void loop()
{
  //if(Blynk.connected()) {
  Blynk.run();
  timer.run();

}

//*********************************************************//

ขอบคุณมากครับ
ถ้าผมลงอะไรไม่ถูกต้องลบได้นะครับ

1 Likes

แก้ตรงนี้นิดหน่อยครับ เยี่ยมมากเลย

1 Likes

5555…ขอบคุณครับ

เวลาที่ขึ้นตอนตั้งกระทู้พี่ได้ตั้งเองรึเปล่าครับ หรือว่ากดสร้างกระทู้แล้วมันติดมาเอง พอดีกำลังปรับแก้ไขนิดหน่อยครับเลยสอบถาม

1 Likes

พอเข้าไปมันขึ้นมาให้กดนะครับ
ถ้าผมผิดต้องขออภัยด้วยครับ

2 Likes

อ่อ ไม่ได้ผิดอะไรครับ พอดีผมทดสอง แล้วมันอาจจะโพลมาเฉยๆ เว็บนี้ชอบลองของครับ 5555

ผมทำตาม โค้ดขึ้น errorตามรูป เกิดจากอะไรครับ

และมีอีกจุดตรง set HUmid

set

โหลด library ตัวนี้มาลงก่อนครับ TridentTD_LineNotify.h

โค้ดนี้ใช้งานไดเลยไหมครับ

ต้องถามว่ามีพื้นฐานอะไรบ้าง ทำทุกอย่างต้องมีความรู้พื้นฐานทั้งนั้นครับ ไม่รู้ก็ถาม ถ้ารู้ก็แชร์

จากการใช้ CODE แบบข้างบน
ผมติด ERROR ตามรูปที่ส่งมา ไม่ทราบว่าจะแก้อย่างไรครับ

copy error ไปตั้งกระทู้ใหม่หน่อยครับ