Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > กระทู้สำหรับภาษาต่าง ๆ > วิธีการส่งข้อมูลจาก NodeMCU-V.3(esp8266) ไปเก็บไว้ใน mySQL บน 000webhost.com



วิธีการส่งข้อมูลจาก NodeMCU-V.3(esp8266) ไปเก็บไว้ใน mySQL บน 000webhost.com

 
Topic : 135173



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook


ผมมีข้อสงสัยครับ พอดีเป็นมือใหม่เรื่องนี้

ผมต้องการใช้ NodeMCU-V.3(esp8266) ทำการวัดค่าและส่งข้อมูลเข้าไปเก็บไว้ใน MySQL บน WebHosting : 000webhost.com ครับ แต่ไม่รู้ทำไมมันถึงส่งไม่ได้ครับ

จาก code ที่ผมลงไว้ พอจะมีใครทราบรึเปล่าครับว่าผมพลาดอะไรไป ขอบคุณครับ

อันนี้เป็น code newconnect.php รับค่าจาก esp8266 และส่งไป mysql ครับ อยู่ใน 000webhost.com
Code (PHP)
<?php
class xxxx{
 public $link='';
 function __construct($A, $B, $C){
  $this->connect();
  $this->storeInDB($A, $B, $C);
 }
 
 function connect(){
  $this->link = mysqli_connect('localhost','aaaa','') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'bbbb') or die('Cannot select the DB');
 }
 
 function storeInDB($A, $B, $C){
  $query = "insert into xxxx set C='" .$C."', B='".$B."', A='".$A."';
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}
if($_GET['A'] != '' and  $_GET['B'] != '' and  $_GET['C'] != ''){
 $dht11=new realproject($_GET['A'],$_GET['Bs'],$_GET['C']);
}
?>


อันนี้เป็น code arduino ใน esp8266 ที่วัดค่าแล้วส่งค่าให้ 000webhost
Code (C#)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <SPI.h>

String data; 
String dat1, dat2, dat3;

float A,B,C;

const char* ssid = "abc";// 
const char* password = "acb";
//WiFiClient client;
const char* host = "xxxx.000webhostapp.com";

WiFiClient client;    

void setup()
{
 Serial.begin(9600);
  delay(10);
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
//  server.begin();
  Serial.println("Server started");
  Serial.println("IP address: ");
  Serial.print(WiFi.localIP());
  delay(1000);
  Serial.println("connecting...");
}

void loop() 
{
 if(Serial.available() > 0) 
 {
    data = Serial.readStringUntil('\n'); 
    dat1  = getValue(data, ',', 0);
    dat2  = getValue(data, ',', 1);
    dat3  = getValue(data, ',', 2);
    
    A = dat1.toFloat();
    B = dat2.toFloat();
    C = dat3.toFloat();
    Sending_To_phpmyadmindatabase();
 }
}

void Sending_To_phpmyadmindatabase()   //CONNECTING WITH MYSQL
{
   Serial.print("connecting to ");
   Serial.println(host);

   WiFiClient client;
   const int httpPort = 80;
   
   if (client.connect(host, httpPort)) 
   {
    String url = "/public_html/testweb/newconnect.php?C=" + String(C) +"&B=" +String(B)+"&A=" +String(A);
    Serial.print("Requesting URL: ");
    Serial.println(url);

    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                  "Host: " + host "\r\n" +
                  "Connection: cloase\r\n\r\n");
    } else 
    {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    return;
    }
} 

/////////////////////// ฟังก์ชันการแยกข้อมูล String ///////////////////////                      
String getValue(String data, char separator, int index)       
{
  int found = 0;                                         
  int strIndex[] = {0, -1  };                                
  int maxIndex = data.length()-1;                              
  for(int i=0; i<=maxIndex && found<=index; i++){             
  if(data.charAt(i)==separator || i==maxIndex){               
  found++;                                                    
  strIndex[0] = strIndex[1]+1;                               
  strIndex[1] = (i == maxIndex) ? i+1 : i;                    
  }
 }
  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";   
}




Tag : MySQL, HTML, C, Web Hosting


Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2020-04-28 15:46:17 By : deatinyfrank View : 731 Reply : 5
 

 

No. 1



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

000webhost ไม่ได้ใช้นานแล้ว ลองเทส url ว่าถูกต้องหรือไม่
เช่น http://xxxx.000webhostapp.com/public_html/testweb/newconnect.php ถ้าได้ 404 หรือไม่พบไฟล์ ลองเปลี่ยนเป็น

http://xxxx.000webhostapp.com/testweb/newconnect.php หรือ https://xxxx.000webhostapp.com/testweb/newconnect.php


ลองไปจนใช้งานได้ปกติ แล้วค่อยมาไล่โค้ดครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-04-29 12:11:44 By : PhrayaDev
 


 

No. 2



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 1 เขียนโดย : PhrayaDev เมื่อวันที่ 2020-04-29 12:11:44
รายละเอียดของการตอบ ::
ลองเข้าดูแล้วครับ มันขึ้นหน้าขาวแบบไม่มีอะไรเลย แบบนี้แปลว่าเจอไฟล์ใช่รึเปล่าครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-04-29 15:35:54 By : deatinyfrank
 


 

No. 3



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

ใน newconnect.php ลองใส่ echo ซักบรรทัด เพื่อเช็ค พอรู้ว่า url ถูกแล้วค่อยแก้คืนครับ

Code (PHP)
<?php
class xxxx{
 public $link='';
 function __construct($A, $B, $C){
  $this->connect();
  $this->storeInDB($A, $B, $C);
 }
 
 function connect(){
  $this->link = mysqli_connect('localhost','aaaa','') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'bbbb') or die('Cannot select the DB');
 }
 
 function storeInDB($A, $B, $C){
  $query = "insert into xxxx set C='" .$C."', B='".$B."', A='".$A."';
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}
if($_GET['A'] != '' and  $_GET['B'] != '' and  $_GET['C'] != ''){
 $dht11=new realproject($_GET['A'],$_GET['Bs'],$_GET['C']);
}

echo "ถูกหน้าแล้ว!";
?>


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-04-29 16:15:19 By : PhrayaDev
 


 

No. 4



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 3 เขียนโดย : PhrayaDev เมื่อวันที่ 2020-04-29 16:15:19
รายละเอียดของการตอบ ::
เจอแล้วครับ!!!!

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-04-29 19:26:53 By : deatinyfrank
 


 

No. 5



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

เจอหน้าแล้วก็ลบ echo ใน newconnect.php ออก (หรือจะเก็บไว้ก็ตามชอบครับ )

แล้วแก้ url ฝั่ง esp8266 ให้ตรงกัน จากนั้น ก็ทดสอบระบบโดยรวมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-04-29 21:30:45 By : PhrayaDev
 


   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : วิธีการส่งข้อมูลจาก NodeMCU-V.3(esp8266) ไปเก็บไว้ใน mySQL บน 000webhost.com
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่