Salve,ieri mi è arrivata un Arduino duemilanove,l'ethernet shield e un lm35.
Di conseguenza mi sono subito messo a fare qualcosina...il problema si presenta con l'invio del dato della temperatura ad una pagina php(permessi settati a 777) presente nel server e situata nel public_html.
Ovviamente non trovo l'errore e quindi chiedo un aiutino a voi ![]()
Codice Arduino:
#include <SPI.h>
#include <String.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x42, 0x0F };
byte ip[] = { 192, 168, 0, 9 };
byte gw[] = { 192, 168, 0, 1};
byte serverip[] = { 69, 175, 122, 178};
byte subnet[] = { 255, 255, 255, 0 };
float tdata = 0;
float tempc=0;
int tempPin = 1; // In This case the temperature is taken from pin 1
//Server server = Server(80);
Client client(serverip,80);
void setup()
{
Ethernet.begin(mac, ip);
pinMode(tempPin, INPUT);
Serial.begin(9600);
delay(1000);
//server.begin();
}
void loop()
{
Serial.println("Program running...");
//delay(1800000);
delay(5000); // Data is sent every 30m
senddata(); // Data is sent every 5s
}
void senddata()
{
tdata = analogRead(tempPin); //Reading analog data
tempc=(5.0 * tdata * 100.0)/1024.0;
/*Serial.println();
Serial.println("Forbinder...");
delay(5000); //Keeps the connection from freezing
if (client.connect()) {
Serial.println("Connected");
// client.print("GET http://69.175.122.178/vaerdi.php?tempar=");
client.print("GET /vaerdi.php?tempar=tempc HTTP/1.1");
//client.print(tempc,DEC);
Serial.println(tempc);
// client.println(" HTTP/1.1");
// client.println("Host: 69.175.122.178");
client.println();
Serial.println();*/
if (client.connect()){
Serial.println(tempc);
Serial.println("connected, writing ...");
delay(5000);
client.print("GET http://farebury.exofire.net/vaerdi.php?tempar=");
client.print(tempc);
client.println("&cod=3 HTTP/1.1 ");
client.println("Host:farebury.exofire.net");
client.println();
}
else
{
Serial.println("Connection unsuccesfull");
}
//}
//stop client
client.stop();
while(client.status() != 0)
{
delay(5);
}
}
Codice php
<?php
$temperatura = $_GET['tempar'];
$scrivo=fopen("tempera.txt","a+"); //scrivo in un file
fwrite($scrivo,$temperatura);
fclose($scrivo);
$message="La temperatura è: $temperatura";
$signature="Arduino Meteo";
pushMeTo($message, $signature);
/*function pushMeTo($widgeturl,$text,$signature) {
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12";
if (!function_exists("curl_init")) die("pushMeTo needs CURL module, please install CURL on your php.");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $widgeturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$page = curl_exec($ch);
preg_match("/form action=\"(.*?)\"/", $page, $form_action);
preg_match("/textarea name=\"(.*?)\"/", $page, $message_field);
preg_match("/input type=\"text\" name=\"(.*?)\"/", $page, $signature_field);
$ch = curl_init();
$strpost = $message_field[1].'=' . urlencode($text) . '&'.$signature_field[1].'=' . urlencode($signature);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
curl_setopt($ch, CURLOPT_URL, $form_action[1]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$page = curl_exec($ch);
}*/
function pushMeTo($mess, $sign) { //invio push a IPhone
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://pushme.to/razorphyn/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'message=' . urlencode($mess) . '&signature=' . urlencode($sign));
curl_exec($curl);
curl_close($curl);
}
?>
<html>
<head>
<title>prova</title>
</head>
<body>
<input>ciao</input>
</body>
</html>
E questo è quello che appare sul serial monitor:
Program running...
Forbinder...
Connected
53.00
Program running...
Forbinder...
Connected
53.00