Go Down

Topic: Why Can't I send data through wifi to mysql database (Read 1 time) previous topic - next topic

tim9510019

First of all, i don't know how to get data by PHP file.
I host a WAMP PHP server and database, and i don't know how to get data by the code below.

Second, the arduino code doesn't work for me, what's the problem with my code

Can somebody give me a hand?
I feel hopeless now.

Code: [Select]

#!/usr/bin/php-cli
<?php
$temperature 
$argv[1]; 
$DBServer 'localhost'
$DBUser   'TIM';
$DBPass   '51354181';
$DBName   'artemp';  
$conn = new mysqli($DBServer$DBUser$DBPass$DBName);
// check connection
if ($conn->connect_error) {
  
trigger_error('Database connection failed: '  $conn->connect_errorE_USER_ERROR);
}
$sql="INSERT INTO tmonitor (monitor) VALUES ('$temperature')";

if(
$conn->query($sql) === false) {
  
trigger_error('Wrong SQL: ' $sql ' Error: ' $conn->errorE_USER_ERROR);

?>





Code: [Select]

#include <Process.h>
#include <Bridge.h>
int temperature;
void setup() {
  Bridge.begin();  // Initialize Bridge
}
void loop() {
  int temperature = random(0, 100);
  Process p;               
  p.begin("http://timblog.tk/db/db.php");
  p.addParameter(String(temperature));
  if(p.run()){
    Serial.println("sending");
  }else{
    Serial.println("not sending");
  }
  delay(5000);
}

tim9510019

The error code for the php:

Notice: Undefined variable: argv in D:\wamp\www\db\db.php on line 3


The client print of arduino:

not sending

tim9510019

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld.sock' (146)

I can't set up mysql on YUN how can i solve it??

sonnyyu

WAMP PHP server:

remove "#!/usr/bin/php-cli" line

Code: [Select]
<?php
$temperature 
$_GET["temperature"]; 
$DBServer 'localhost'
...


Test with browser "http://WAMP_ip/db/db.php?temperature=100".





sonnyyu

Arduino:

Code: [Select]
...
  Process p;              
  p.begin("curl");
  p.addParameter("http://timblog.tk/db/db.php?temperature=" + String(temperature));
...





tim9510019

#5
Feb 09, 2016, 02:47 am Last Edit: Feb 09, 2016, 12:50 pm by tim9510019
Dear sonnyyu:

I can send the data to data base now.
Here is my work:
http://timblog.tk/chartphp/

Because of your useful hint, I became one of your fans.

I will do some IR control of Dehumidifier, air conditioner, and radiators.
It's a lot of fun to edit PHP, Arduino, and Mysql.

There are many things to learn including hardware, software, firmware, website, and database.

My facebook is https://www.facebook.com/zhengtingc
Thumb-up is really needed.

I'm now organizing notes of this three-day journey.
I've learned something.
Thanks for your help sincerely.

B.R
Tim Chen


koley

Dear Tim,

Can you please give me the full arduino code? Because I am also facing the same problem.

Go Up