Meteo station arduino YUN

Hello everyone.I'm sorry if I'm in the wrong section of the forum but i'm new here and i'm new in Arduino's world too.
I'm a programmer with decent knowledge of electronics and so I decided to try my hand in the creation of this project.

I still have not made ??purchases of sensors or other, but I limited myself to buy the Arduino board to begin to take confidence with the YUN board.

The aim of my project is to create a circuit connected to Yun , battery-powered and comes in a waterproof box to be able to accommodate even the open air so that it can collect data from the environment .

These data must then be sent to an Apache Web server and stored in a MySQL database.

My problem is not with the circuitry but in the communication between arduino and apache.

I hope someone can give me some tips because , I repeat, I am new to the arduino world Yun and therefore I did not understand how I should do to send a value recorded in a database.

I want to send data from the YUN in some way to a php page then thought we would have to save the data in the database.

My main request is precisely how to send the data to the php page on apache?

I hope I was clear and I hope someone can help me.

Matteo.

The Yun has built in Ethernet, so the process of sending data to an Apache server is EXACTLY the same as on any board with an Ethernet shield. You make a GET request to execute a PHP script, supplying it with the data needed to perform the operation required, after connecting to the correct server.

Yes i know.

But i'm using it under Wifi not with an ethernet cable.

I found lots of example that was using ethernet.h library but i want to use my station under wifi.

Did you understand what i want to do? :slight_smile:

Did you understand what i want to do?

Can you quote the part from your original post that mentions WiFi?

Have you looked at the WiFi examples? There are client and server examples (you want client) there, too.

The Yun uses a different mechanism (not SPI) to communicate with the Ethernet and WiFi hardware. If you haven't already, I suggest that you spend some time here:
http://arduino.cc/en/Guide/ArduinoYun

Sorry you're right i did'nt say that i wanted it on WiFi.

I saw the link you said but i really can't understand how to do it.

Can you explain me, if it's not a problem, the protocol and the library of the YUN that i have to use?

Sorry for my hard question but i got my first board yesterday and i have been studying the Network only for two months.

You can use the HttpClient sketch that comes with the Yun

You just change this line

client.get("http://arduino.cc/asciilogo.txt");

To whatever you are using.

This is the sketch on my Arduino YUN.

#include<Bridge.h>
#include<YunClient.h>
int watt = 0;
int readyLed = 13;
YunClient client;

void setup()
{
  
Bridge.begin();
digitalWrite(readyLed,HIGH); 


}
void loop()
{

      
  delay(3000);
  senddata();

}
void senddata()
{

watt = watt+1;      





client.connect("localhost:8888/MiaCartella/ProvaArduino/Sbam.php",80);
Serial.println();
Serial.println("Initiates connection");
Serial.println("Connecting");
delay(1000); //This one keeps it from hanging

if (client.connected()) {
Serial.println("Connected!");
client.print("GET http://localhost:8888/MiaCartella/ProvaArduino/Sbam.php?watt=");
client.print(watt);
client.println(" HTTP/1.1");
client.println("Host: localhost:8888");
client.println();
                            }
 
 else 
 {
 Serial.println("Connection failed");
 }
//}
  //stop client
  client.stop();
  while(client.connected() != 0) 
 {
   delay(5);
 }
}

This is my php page (Sbam.php) on Apache :

<html>



<?php
    
    $Host='localhost';
    $User='root';
    $Password='root';
    $Database='ProvaArduino';
    
    $Connessione=mysql_connect($Host , $User , $Password);
    if(!$Connessione){
        echo "Connessione fallita";
    }
    
    $DB=mysql_select_DB($Database);
    if(!$DB){
        echo "Impossibile trovare il DataBase";
    }

    
    $forbrukning = $_GET['watt'];
    
    echo $forbrukning;
    echo("Hello, World");
    
  
    
    ?>
</html>

In the php page i can't see the data sent from the arduino.

Where did i fail?

I was referring to the HttpClient example:

You just substitute this line

client.get("http://arduino.cc/asciilogo.txt");

With this:

sprintf (buf, "http://localhost:8888/MiaCartella/ProvaArduino/Sbam.php?watt=%u", watt);
client.get(buf);

Ofcource you have to define buf, eg:

char buf[50];

I want to send data to php page.

Like this it doesen't work.

With the echo instruction i want to see on the page the data watt sent by arduino.

Like this it doesen't work.

How do you determin that it is not working? Do you get anny errots ?
I just tried your sketch, it worked as expected on my Yun.

Edit:
And DO NOT CROSSPOST

http://forum.arduino.cc//index.php?topic=193697.0

This:

http://localhost:8888/MiaCartella/ProvaArduino/Sbam.php?watt=1000

doesn't work when I paste it in my browser. It does not get a response from the Sbam.php script.

Can you tell why? If not, then network programming is not (yet) for you. You need to start with understanding what localhost means. The Yun IS the localhost, and it doesn't know squat about that script. Clearly, you don't mean localhost, since the Yun isn't serving the page.

http://localhost:8888/MiaCartella/ProvaArduino/Sbam.php?watt=1000

I'm not very good in network programmin and i said this.

You can't see it on your browser cause it's the adress of my php page situated on the apache web server.

I can't understand on what ip and port i have to connect the YunClient for sending to my PHP page the HTTP request.

Help me please.

cappun:
I can't understand on what ip and port i have to connect the YunClient for sending to my PHP page the HTTP request.

Assuming your client and server are within the same network, the hostname and port that you specify for the server need to match the hostname and port that the server is actually running on.