简体   繁体   English

PhpMyAdmin表给出空列

[英]PhpMyAdmin table gives empty column

I am working on a project to send sensor data to phpmyadmin table using GET request. 我正在开发一个项目,使用GET请求将传感器数据发送到phpmyadmin表。

I am not able to see sensor data in the table when I consider my Arduino to be the client, but when I use this URL on my Google chrome browser it shows the result (ex. 40). 当我认为我的Arduino是客户端时,我无法在表中看到传感器数据,但是当我在我的Google Chrome浏览器上使用此URL时,它会显示结果(例如40)。 It seems the problem is with the Arduino code. 似乎问题出在Arduino代码上。

int samples[NUMSAMPLES];
void loop() {
// Thermistor

 uint8_t i;
  float average;
  // take N samples in a row, with a slight delay
   for (i=0; i< NUMSAMPLES; i++) {
   samples[i] = analogRead(THERMISTORPIN);
    delay(10);
    }

  // average all the samples out
    average = 0;
    for (i=0; i< NUMSAMPLES; i++) {
    average += samples[i];
     }
    average /= NUMSAMPLES;


   // convert the value to resistance
   average = 1023 / average - 1;
   average = SERIESRESISTOR / average;

    float Steinhart;
    Steinhart = average / THERMISTORNOMINAL;     // (R/Ro)
    Steinhart = log(Steinhart);                  // ln(R/Ro)
    Steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
    Steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
    Steinhart = 1.0 / Steinhart;                 // Invert
    Steinhart -= 273.15;                         // convert to C

    Serial.print("Temperature "); 
    Serial.print(Steinhart);
    Serial.println(" *C");

     delay(5000);


     Serial.println("\nStarting connection to server...");
     // if you get a connection, report back via serial:
    if (client.connect(server, 80)) {
      Serial.println("connected to server");
      // Make a HTTP request:
       client.println("GET /add.php?");
       client.print("Steinhart=");
        client.print(Steinhart);
         }

       // if there are incoming bytes available 
        // from the server, read them and print them:
        while (client.available()) {
        char c = client.read();
        Serial.write(c);
        }
        }

     void setup() {
     //Initialize serial and wait for port to open:
       Serial.begin(9600); 
       while (!Serial) {
       ; // wait for serial port to connect. Needed for Leonardo only
       }


       // check for the presence of the shield:
       if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present"); 
          // don't continue:
           while(true);
        } 

   // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) { 
     Serial.print("Attempting to connect to SSID: ");
      Serial.println(ssid);
        // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
        status = WiFi.begin(ssid);

      // wait 10 seconds for connection:
       delay(10000);
        } 
        Serial.println("Connected to wifi");
        printWifiStatus();


       } // end of void setup()

And here is my PHP code: add.php file 这是我的PHP代码:add.php文件

  <?php

   include("connect.php");

    $link=Connection();

     $Steinhart = ""; // or null !!
     $timeStamp="";

        $Steinhart = isset($_GET['Steinhart']) ? $_GET['Steinhart'] : '';

       date_default_timezone_set("Asia/Dubai");
       $timeStamp = date('Y-m-d H:i:s', time());


      $query= "INSERT INTO `time` (`id`, `timeStamp`, `Steinhart`) VALUES (NULL, '$timeStamp','$Steinhart')";
      mysqli_query($link, $query);
      mysqli_close($link);

      ?>

I Usually send data from the Arduino board to PhpmyAdmin(Wamp Server or XXamp) with the help of NodeJS. 我通常在NodeJS的帮助下将数据从Arduino板发送到PhpmyAdmin(Wamp Server或XXamp)。 It is pretty easy to send data with the help of NodeJS. 在NodeJS的帮助下发送数据非常容易。 Here i attach the code. 在这里我附上代码。

var request = require('request');
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;

var serialPort = new SerialPort("COM5", {
  baudrate: 9600,
  parser: serialport.parsers.readline("\n")
});


serialPort.on("open", function () {
  console.log('open');
  serialPort.on('data', function(data) {
    console.log(data);
  });
});

serialPort.on('data', sendSerialData);

function sendSerialData(data) {
 request({
  uri: "http://127.0.0.1/write_data.php?value="+data,
 method: "GET",
  timeout: 10000,
   followRedirect: true,
   maxRedirects: 10
}, function(error, response, body) {
   console.log(body);
});


}

By this you can easily send the data. 通过这种方式,您可以轻松发送数据。 Also you can just follow this link 您也可以点击此链接

http://www.instructables.com/id/PART-1-Send-Arduino-data-to-the-Web-PHP-MySQL-D3js/ http://www.instructables.com/id/PART-1-Send-Arduino-data-to-the-Web-PHP-MySQL-D3js/

Hope it will help 希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM