ต้องการวัดความชื้นในดิน และ ส่งผ่านไลน์โดยใช้ esp8266

(อยากได้โค๊ดหรือคำแนะนำดีๆครับ แอเฟสมาได้ครับ Sorrawat Buahom line:1kongtoloveaom1)

ลิ้งเซ็นเซอร์

ลิ้งบอร์ด
https://www.lazada.co.th/products/nodemcu-v3-esp8266-esp-12e-ch340-i150410834-s175568672.html?spm=a2o4m.searchlist.list.1.29c9707fBK2Ojd&search=1

ใส่รายละเอียดในกระทู้ด้วยนะครับ ใช้เซนเซอร์ตัวไหนรุ่นไรเพราะ แต่ละตัว liberi ไม่เหมือนกันครับ

ครับจะแปะลิ้งไว้ให้ครับ

ถ้าให้แนะนำตัววัดความชื่นก็จะเป็นตัวนี้ครับ

image

เพราะเราสามารถต่อแล้วดึงค่าด้วยคำสั้ง analogRead(); ออกมาใช้ได้เลย

int SensorPin = A0;    // พินที่ใช้รับค่า A0 
int SensorValue = 0;  // ตัวแปรของ ความชื้นในดิน เริ่มต้นด้วย 0    

void setup() {

  Serial.begin(9600);

}

 

void loop() {

  // อ่านค่าจาก Sensor:

  sensorValue = analogRead(SensorPin);    

  sensorValue = map(SensorValue, 350, 1023, 100, 0);

  Serial.print("Moisture of Soil:  "); ตั้งชื่อคำนำหน้า

  Serial.println(SensorValue); //เรียนดูค่า SensorValue ใน Serial ว่ามีค่าเท่าไหร่

}

ส่วนการส่งค่าผ่าน line เดียวเขียนบทความมาแปะให้ดูอีกทีครับ

พอดีสั่งมาแล้วอะครับพี่

พอดีต้องใช้พรุ่งนี้อะครับพี่

จริงๆ จะใช้พรุ่งนี้ควรถามก่อนหน้านี้นะครับ ต้องมีเวลาศึกษาด้วย ต้องให้เวลากับมันเยอะๆ เรื่องบางเรื่องต้องคุยกันหลายรอบกว่าจะเข้าใจถูกต้อง

ทีนี้ถ้าใช้เซ็นเซอร์ที่ซื้อมาก็ใช้โค้ตชุดเดียวกันได้ครับการต่อใช้งานก็ประมาณนี้

Interface Description การต่อใช้งานกับ Arduino แบบ 4 เส้น

  • VCC: 3V-5V

  • GND: GND ของ Arduino

  • D0: ต่อเข้ากับขา Digital ของ Arduino

  • A0: ต่อเข้ากับขา Analog ของ Arduino

ส่วนโค้ตชุดที่ส่ง line ส่วนโค้ตชุดที่ส่งเข้าไลน์ก็ขอตอบล้วกๆ ละกันครับ ทำตามนี้

https://www.ioxhop.com/article/47/esp8266-esp8285-กับการส่งการแจ้งเตือนเข้า-line

ส่วนโค้ตก็เอามารวมกันแล้วจัด layout ให้ดีครับ

ขอบคุณมากๆครับ

ลองรวมโค้ตแล้วเทสดูติดตรงไหน เอาโค้ตมาคุยกันต่อครับ


ขึ้นงี้อะครับ

ผมนต้องใช้เวอร์ชั่นไหนอะครับ หาเวอร์ชั่นบอร์ดตัวเองไม่เจอเลย

void Line_Notify(String message) ;

#include <ESP8266WiFi.h>
#include <WiFiClientSecureAxTLS.h> // กรณีขึ้น Error ให้เอาบรรทัดนี้ออก

// Config connect WiFi
#define WIFI_SSID "Meeting Home_2.4GHz"
#define WIFI_PASSWORD "Home9999"

// Line config
#define LINE_TOKEN "7fU5yMzWkcbslrvhSTflMPCuK3DGHsVHo60429YFQbb"



String message = "โดนกด"; // ArduinoIDE เวอร์ชั่นใหม่ ๆ ใส่ภาษาไทยลงไปได้เลย

int SensorPin = A0;    // พินที่ใช้รับค่า A0 
int SensorValue = 0;  // ตัวแปรของ ความชื้นในดิน เริ่มต้นด้วย 0    

void setup() {

  Serial.begin(9600);

}

 

void loop() {

  // อ่านค่าจาก Sensor:

  sensorValue = analogRead(SensorPin);    

  sensorValue = map(SensorValue, 350, 1023, 100, 0);

  Serial.print("Moisture of Soil:  "); 

  Serial.println(SensorValue); //เรียนดูค่า SensorValue ใน Serial ว่ามีค่าเท่าไหร่

}
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());

โค้ตผิดครับ

พิมพ์ไม่ได้ครับ มันขึ้น new user ไม่สามารถวาง2ลิ้งได้

แก้ให้ละครับ

oid Line_Notify(String message) ;

#include <ESP8266WiFi.h>
#include <WiFiClientSecureAxTLS.h> // กรณีขึ้น Error ให้เอาบรรทัดนี้ออก

// Config connect WiFi
#define WIFI_SSID "Kongtohome"
#define WIFI_PASSWORD "0850911xxx"

// Line config
#define LINE_TOKEN "txJIhkKTWQXIOpCQL6TiWcY7uFAI3OrkpQ3d5T5yry8"

#define SW D2

String message = "โดนกด"; // ArduinoIDE เวอร์ชั่นใหม่ ๆ ใส่ภาษาไทยลงไปได้เลย

void setup() {
  pinMode(SW, INPUT);

  Serial.begin(9600);

  WiFi.mode(WIFI_STA);
  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  if (digitalRead(SW) == HIGH) {
    while(digitalRead(SW) == HIGH) delay(10);

    Serial.println("Enter !");
    Line_Notify(message);
    // Serial.println();
  }
  delay(10);
}

void Line_Notify(String message) {
  axTLS::WiFiClientSecure client; // กรณีขึ้น Error ให้ลบ axTLS:: ข้างหน้าทิ้ง

  if (!client.connect("notify-api.line.me", 443)) {
    Serial.println("connection failed");
    return;   
  }

  String req = "";
  req += "POST /api/notify HTTP/1.1\r\n";
  req += "Host: notify-api.line.me\r\n";
  req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n";
  req += "Cache-Control: no-cache\r\n";
  req += "User-Agent: ESP8266\r\n";
  req += "Connection: close\r\n";
  req += "Content-Type: application/x-www-form-urlencoded\r\n";
  req += "Content-Length: " + String(String("message=" + message).length()) + "\r\n";
  req += "\r\n";
  req += "message=" + message;
  // Serial.println(req);
  client.print(req);
    
  delay(20);

  // Serial.println("-------------");
  while(client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      break;
    }
    //Serial.println(line);
  }
  // Serial.println("-------------");
}void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

ถ้าจะเพิ่มวัดความชื้นต้องเปลี่ยนตรงไหนครับ

/* 
 * ไลบรารี่ TridentTD_LineNotify version 2.1
 * ใช้สำหรับ ส่ง แจ้งเตือนไปยัง LINE สำหรับ ESP8266 และ ESP32
 * สามารถส่งได้ทั้ง ข้อความ , สติกเกอร์ และรูปภาพ(ด้วย url)
 * -----------------------------------------------------
 * ให้ save เป็น file ต่างหากก่อนถึงจะส่ง Line Notify ภาษาไทยได้
 */

#include <TridentTD_LineNotify.h>

#define SSID        "Kongtohome"
int    PASSWORD    "0850911228"
#define LINE_TOKEN  "7fU5yMzWkcbslrvhSTflMPCuK3DGHsVHo60429YFQbb"

void setup() {
  Serial.begin(115200); Serial.println();
  Serial.println(LINE.getVersion());
  
  WiFi.begin(SSID, Password);
  Serial.printf("WiFi connecting to %s\n",  SSID);
  while(WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(400); }
  Serial.printf("\nWiFi connected\nIP : ");
  Serial.println(WiFi.localIP());  
int SensorPin = A0;    // พินที่ใช้รับค่า A0 
int SensorValue = 0;  // ตัวแปรของ ความชื้นในดิน เริ่มต้นด้วย 0    

void setup() {

  Serial.begin(9600);

}

void loop() {

  // อ่านค่าจาก Sensor:

  sensorValue = analogRead(SensorPin);    

  sensorValue = map(SensorValue, 350, 1023, 100, 0);

  Serial.print("Moisture of Soil:   "); //340 ตั้งชื่อคำนำหน้า

  Serial.println(SensorValue); //เรียนดูค่า SensorValue ใน Serial ว่ามีค่าเท่าไหร่

}
  // กำหนด Line Token
  LINE.setToken(LINE_TOKEN);

  // ตัวอย่างส่งข้อความ
  LINE.notify("อุณหภูมิ เกินกำหนด");

  // ตัวอย่างส่งข้อมูล ตัวเลข
  LINE.notify(2342);          // จำนวนเต็ม
  LINE.notify(212.43434,5);   // จำนวนจริง แสดง 5 หลัก

  // เลือก Line Sticker ได้จาก https://devdocs.line.me/files/sticker_list.pdf
  LINE.notifySticker(3,240);        // ส่ง Line Sticker ด้วย PackageID 3 , StickerID 240
  LINE.notifySticker("Hello",1,2);  // ส่ง Line Sticker ด้วย PackageID 1 , StickerID 2  พร้อมข้อความ

  // ตัวอย่างส่ง รูปภาพ ด้วย url
  LINE.notifyPicture("https://preview.ibb.co/j6G51n/capture25610417181915334.png");
  LINE.notifyPicture("จตุธาตุ","https://www.fotoaparat.cz/storage/pm/09/10/23/670915_a5351.jpg");
}

void loop() {
  delay(1);
}

ลบออกครับมันซ้ำกันจะคอมไพลฺไม่ผ่าน