arduino สามารถนำค่าของเซนเซอร์เข้า sql ได้ไหมครับ

IOT - Internet of things
ไอโอที (IoT) หมายถึงเครือข่ายของวัตถุ อุปกรณ์ พาหนะ สิ่งปลูกสร้าง และสิ่งของอื่นๆ ที่มีวงจรอิเล็กทรอนิกส์ ซอฟต์แวร์ เซ็นเซอร์ และการเชื่อมต่อกับเครือข่าย ฝังตัวอยู่ และทำให้วัตถุเหล่านั้นสามารถเก็บบันทึกและแลกเปลี่ยนข้อมูลได้

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
dewhaha
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 07/12/2022 11:51 pm

arduino สามารถนำค่าของเซนเซอร์เข้า sql ได้ไหมครับ

โพสต์ที่ยังไม่ได้อ่าน โดย dewhaha »

คือผมจะทำโปรเจคจบของ ปวช ครับ คิดว่าจะทำเซนเซอร์ที่ส่งค่าข้อมูลที่ได้ไปเก็บไว้ใน database ครับ แล้วอยากจะทำให้เปิดจากมือถือได้ด้วย ผมศึกษามาได้ประมาณนึง คือต้องเขียนโค้ดของรีเลย์ด้วยแล้วก็เขียนโค้ด สำหรับรับค่าและส่งค่าด้วยใช่ไหมครับ อยากถามทุกคนว่ามันมีแนวโน้มที่ทำได้ใช่ไหมครับ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: arduino สามารถนำค่าของเซนเซอร์เข้า sql ได้ไหมครับ

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ใช่ครับ หลังจากได้ค่าจาก รีเลย์แล้ว
ส่งค่า http แล้วใช้ php รับบันทึกลงฐานข้อมูลได้ครับ
ประมาณนี้

โค้ด: เลือกทั้งหมด

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-mysql
 */

#include <SPI.h>
#include <Ethernet.h>

// replace the MAC address below by the MAC address printed on a sticker on the Arduino Shield 2
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetClient client;

int    HTTP_PORT   = 80;
String HTTP_METHOD = "GET";
char   HOST_NAME[] = "192.168.0.26"; // change to your PC's IP address
String PATH_NAME   = "/insert_temp.php";
String queryString = "?temperature=29.1";

void setup() {
  Serial.begin(9600);

  // initialize the Ethernet shield using DHCP:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to obtaining an IP address using DHCP");
    while(true);
  }

  // connect to web server on port 80:
  if(client.connect(HOST_NAME, HTTP_PORT)) {
    // if connected:
    Serial.println("Connected to server");
    // make a HTTP request:
    // send HTTP header
    client.println(HTTP_METHOD + " " + PATH_NAME + queryString + " HTTP/1.1");
    client.println("Host: " + String(HOST_NAME));
    client.println("Connection: close");
    client.println(); // end HTTP header

    while(client.connected()) {
      if(client.available()){
        // read an incoming byte from the server and print it to serial monitor:
        char c = client.read();
        Serial.print(c);
      }
    }

    // the server's disconnected, stop the client:
    client.stop();
    Serial.println();
    Serial.println("disconnected");
  } else {// if not connected:
    Serial.println("connection failed");
  }
}

void loop() {

}
ส่วนการแสดงผลมือถือ ก็ใช้ php ดึงมาแสดงได้เลย หรือจะใช้ เป็น web service เพิ่มทำเป็น app แสดงผลก็ได้

ดูต่อที่นี่บทความเขียนไว้ดีเลยครับ ทำตาม step by step ได้ แต่บางขั้นตอนก็อ้อมไปหน่อย
https://arduinogetstarted.com/tutorials/arduino-mysql

ติดขัดขั้นตอนไหน สอบถามได้ โดยเอา Error ที่เจอ กับขั้นตอนที่ไปมาสอบถามได้
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 62