Go Down

Topic: [SOLVED] Yun MySQL connection (Read 1 time) previous topic - next topic

istrait77

May 13, 2015, 03:33 am Last Edit: May 14, 2015, 03:13 am by istrait77
Hey there...  Noob here...

I followed all the instructions here and have the Yun reporting one value to the database.

http://forum.arduino.cc/index.php?topic=239575.msg1720142#msg1720142

Now I am trying to get it to report 2 values to the database instead of one.

Code: [Select]

#include <DHT.h>
#include <Process.h>

#define DHTPIN 4   
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
    // initialize digital pin 13 as an output (light to show start of process).
  pinMode(13, OUTPUT);
  delay(4000);
 Bridge.begin();  // Initialize Bridge
}

void loop() {
 //2 variables that I am measuring
 int h = dht.readHumidity();
 int t = dht.readTemperature();
 
 // Displays the values on the serial monitor for debug.
 
  Serial.print("Temp=");
  Serial.print(t);
  Serial.print(" C  ");
  Serial.print("Humidity=");
  Serial.print(h);
  Serial.print("%   ");
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level) to show start
  delay(1000);              // wait for a second
 
 // Section to send the data to the php file.
 
 Process p;             
 p.begin("/mnt/sda1/db.php");     
 p.addParameter(String(t) + " " + String(h));
 p.run();
 
 // Shows what was sent
 
  Serial.print(String(t) + " " + String(h));
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);

// Delays the loop for 5 seconds.
delay(5000);

}


I am not really sure how to see what this sends out to the php file (which is attached)

Code: [Select]

#!/usr/bin/php-cli
<?php
$temperature 
$argv[1]; 
$humidity $argv[2];
$DBServer '192.168.0.99'
$DBUser   'root';
$DBPass   'password';
$DBName   'sensors';  
$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 sensor_data (temperature, humidity) VALUES ($temperature$humidity)";
if(
$conn->query($sql) === false) {
  
trigger_error('Wrong SQL: ' $sql ' Error: ' $conn->errorE_USER_ERROR);

?>



I do not think that the php file is the problem as I can run the following from ssh on the yun and get the expected values.

Code: [Select]

/mnt/sda1/db.php  80 40


Any ideas?  I am not sure that the information is being passed from the arduno into the array.

sonnyyu

#1
May 13, 2015, 03:39 am Last Edit: May 13, 2015, 03:44 am by sonnyyu
$humidity = argv[2];

Code: [Select]
$humidity = $argv[2];

p.addParameter(String(t) + " " + String(h));

Code: [Select]
p.addParameter(String(t));
p.addParameter(String(h));









istrait77

Awesome....Thanks for the help...


This took care of it...

$humidity = argv[2];

Code: [Select]
$humidity = $argv[2];

p.addParameter(String(t) + " " + String(h));

Code: [Select]
p.addParameter(String(t));
p.addParameter(String(h));










jessemonroy650

Awesome....Thanks for the help...


This took care of it...

@istrait77,
can you append to the subject line [SOLVED]. This will help others in the future with the same or similar problems.

TIA
Jesse

istrait77

Updated the subject.... 

Thanks for the hint..

Now to make it work with my dragino shield....

Go Up