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#msg1720142Now I am trying to get it to report 2 values to the database instead of one.
#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)
#!/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_error, E_USER_ERROR);
}
$sql="INSERT INTO sensor_data (temperature, humidity) VALUES ($temperature, $humidity)";
if($conn->query($sql) === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_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.
/mnt/sda1/db.php 80 40
Any ideas? I am not sure that the information is being passed from the arduno into the array.