我最近想將DHT11的數據存到raspberry中的php並且傳給mysql,可是一直到沒連接到raspberry中的php檔
我想請問我少寫了什麼嗎?
我使用的開發板是Linkit7697


以下是Arduino IDE的code
#include <LWiFi.h>
#include <DHT.h>
char _lwifi_ssid[] = "";//wifi_id
char _lwifi_pass[] = "";//wifi_pass
WiFiClient client;
char server[] = "192.168.0.11";   //eg: 192.168.0.222
//IPAddress ip(192,168,0,11);
String str;
DHT dht11_p2(2, DHT11);
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
  while (!Serial);
  WiFi.begin(_lwifi_ssid,_lwifi_pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}
void loop() {
  // put your main code here, to run repeatedly:
  //以下溫溼度建立
  Serial.print("溫度:");
  Serial.println(dht11_p2.readTemperature());
  Serial.print("濕度:");
  Serial.println(dht11_p2.readHumidity());
  
  str = String("http://192.168.0.11/dht11.php?temperature=") + String(dht11_p2.readTemperature()) + String("&humidity=") + String(dht11_p2.readHumidity());
  //Serial3.println(str);
  Serial.println(str);
  receiveData();
  Serial.println(str);
  Sending_To_phpmyadmindatabase();
  //if (Serial.available())  {
  //Serial.write(Serial.read());
  //}
  delay(5000);
}
void receiveData()  {
  str = "";
  char c;
  while (Serial.available()) {
    if ((c = Serial.read()) != EOF) {
      str += c;
    }
  }
}
void Sending_To_phpmyadmindatabase()  { //CONNECTING WITH MYSQL
  if (!client.connect(server, 80)) {
    Serial.println("connection failed!");
    return;                //return在程序中有退出loop函數的作用,不過loop函數會再次運行
  }
  client.print("GET ");
  client.print(str);
  client.print(" ");      //SPACE BEFORE HTTP/1.1
  client.print("HTTP/1.1");
  client.println();
  client.println("Host:192.168.0.11");
  client.println("Connection: close");
  client.println();
}
以下是raspberry中php檔的code
<?php
class data{
 public $link='';
 function __construct($temperature, $humidity){
  $this->connect();
  $this->storeInDB($temperature, $humidity);
 }
 function connect(){
  $this->link = mysqli_connect('localhost','ASL111','qaws') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'temphumid1') or die('Cannot select the DB');
 }
 function storeInDB($temperature, $humidity){
  $query = "insert into surroundings set humidity='".$humidity."', temperature='".$temperature."'>
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
}
if($_GET['temperature'] != '' and  $_GET['humidity'] != ''){
 $data=new data($_GET['temperature'],$_GET['humidity']);
}
?>
先糾正你的說詞一下。
phpmyadmin不是資料庫,而是一個控管資料庫的管理器。
所以「無法存入phpmyadmin」這個說詞是不對的。
因該是「無法存入資料庫」
再來,你的程式碼用圖片。很難COPY下來查看程式碼。
所以得先用說的。
你要先確定你的程式碼,能正常連結資料庫。
由於你用圖片且很模糊。我無法幫你查看程式碼中哪邊有問題。
你就先自行檢查處理是否資料庫連結有異常。
如使用了ROOT帳號做遠程連結。
只要是非用 localhost 或 127.0.0.1,都是視為遠程連結。
現在的資料庫大多預設有做ROOT不允行遠程連結的特性。(除非有特別去做調整)