Rozy Rozy - 1 month ago 15
MySQL Question

PhpMyAdmin table gives empty column

I am working on a project to send sensor data to phpmyadmin table using GET request.

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).
It seems the problem is with the Arduino code.

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

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);

?>

Answer

I Usually send data from the Arduino board to PhpmyAdmin(Wamp Server or XXamp) with the help of NodeJS. It is pretty easy to send data with the help of 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/

Hope it will help