Arduino Yun to send data to MySQL(XAMPP) over wifi

Hi there!

I am experiencing problems to write data to MySQL db which is located on my home pc. I got a sketch which worked fine with uno and network shield but I experience problems to adapt it for Yun which I bought solely for the WiFi. I read about how Yun’s structure with the Arduino core and the Linux core and the Bridge connection between them but cannot find a simple way to get data from the analog pin A0 and send it to the PC over Wifi without doing anything else (python and etc.).

I have tried with the following code which is an edited sketch which I used to send over Enet with Uno. The php file which is on the server side is posted bellow this.

#include <dht.h>
#include <SPI.h>
#include <Bridge.h>
#include<YunClient.h>
#define dht_apin A0 
dht DHT;
char server[] = "192.168.0.2"; 


YunClient client;

void setup() {
  Serial.begin(9600);
}

void loop() {

  ////Temp & Humidity
  
   DHT.read11(dht_apin);
   Serial.println(DHT.temperature);
   Serial.println(DHT.humidity);
  if (client.connect(server, 80)) {
    Serial.print("connected");
     client.print("GET /write_data2.php?"); // This
        client.print("temp="); 
        client.print(DHT.temperature);
        client.print("&&");
        client.print("humid="); 
        client.print(DHT.humidity);
        client.println(" HTTP/1.1"); // Part of the GET request
        client.println("Host: 192.168.0.2"); 
        client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
        client.println(); // Empty line
        client.println(); // Empty line
        client.stop();    // Closing connection to server
  }
  else {
 //  If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
  }
 }

PHP code on XAMPP side:

<?php

    // Prepare variables for database connection
   
    $dbusername = "arduino";  
    $dbpassword = "yun";  
    $server = "localhost";

    // Connect to your database

    $dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
    $dbselect = mysql_select_db("test",$dbconnect);

    // Prepare the SQL statement

    $sql = "INSERT INTO test.count (temp,humid) VALUES ('".$_GET["temp"]."','".$_GET["humid"]."')";    
 
 
    // Execute SQL statement

    mysql_query($sql);

?>

Solved it myself! Forgot to add Bridge.begin() in setup.

May its possible to post a complete tut of your script? Its exact what i am searching

greetz

oblique:
May its possible to post a complete tut of your script? Its exact what i am searching

greetz

Yes i'm searching for that aswell. If you could post it i would be greatly appreceated :slight_smile:

Thanks