Ethernet shield and PHP
hi, how can use php ethernet shield?
i've read cookie ethernet shield, possible?
i've read cookie ethernet shield, possible?
code: [select]
client.println("http/1.1 200 ok");
client.println("content-type: text/html");
client.println();
client.println("<html><head>");
//refresh per le temperature
client.print("<meta http-equiv='refresh' content='2'>");
client.println("<title>arduino home</title></head><body>");
client.println("<?php if (!isset($_cookie['nome_utente'])){");
client.println(" print('pagina scaduta <br>'); ");
client.println(" print('se vuoi ritornare alla pagina di login clicca '); ");
client.println(" print('<a href=""http://192.168.0.10/tesina/index.php"">qui</a>');");
client.println(" die(); ?>");
client.println("<table border=""2"" width=""100%"" height=""100%""><tr><td align=""center"">");
etc....
you can't execute php on arduino , serve on ethernet way can regular webserver; however, if asking can call php cgi script on webserver ethernet equipped arduino answer yes. here example have sends sensor data web server (apache).
code: [select]
#include <time.h>
#include <wire.h>
#include <spi.h>
#include <ethernet.h>
#include <adafruit_bmp085.h>
#include "dht.h"
#include "adafruit_mcp9808.h"
#include <mcp79412rtc.h>
#include <sfe_tsl2561.h>
#define dhttype dht22
const int dhtpin=5;
const int sspin = 53;
const int http_port = 80;
byte mac[] = { 0xac, 0x03, 0xfb, 0xb4, 0xee, 0x00 };
char memoria[] = "192.168.0.100";
char location[] = "indoor";
//char location[] = "outdoor";
unsigned char gain; // gain setting, 0 = x1, 1 = x16;
unsigned int ms; // integration ("shutter") time in milliseconds
static long lastprint=0;
ipaddress ip(192,168,0,199);
ipaddress mydns(192,168,0,1);
dht dht(dhtpin, dhttype);
adafruit_bmp085 bmp;
adafruit_mcp9808 tempsensor = adafruit_mcp9808();
sfe_tsl2561 light;
ethernetclient client;
void httprequest(char *query) {
// if there's successful connection:
if (client.connect(memoria, http_port)) {
// send http request:
client.println(query);
serial.println(query);
client.println("host: 192.168.0.100");
client.println("user-agent: arduino");
client.println("connection: close");
client.println();
delay(50);
client.stop();
}
else {
// if couldn't make connection:
serial.println("connection failed");
serial.println("disconnecting.");
client.stop();
}
}
void setup() {
serial.begin(115200);
delay(1000);
// start ethernet connection using fixed ip address , dns server:
ethernet.begin(mac, ip, mydns);
setsyncprovider(rtc.get);
if (timestatus() != timeset)
serial.println("unable sync rtc");
if (!tempsensor.begin()) {
serial.println("couldn't find mcp9808!");
while (1);
}
if (!bmp.begin()) {
serial.println("could not find valid bmp085 sensor, check wiring!");
while (1) {}
}
dht.begin();
light.begin();
gain = 0;
unsigned char time = 2;
light.settiming(gain,time,ms);
light.setpowerup();
}
void loop()
{
if ((millis() - lastprint) > 30000l)
{
lastprint = millis();
char buffer[250];
long dht_h = dht.readhumidity() * 10;
long mcp_c = tempsensor.readtempc() * 100;
long mcp_f = ((float) (tempsensor.readtempc() * 9.0 / 5.0 + 32.0))*100;
long bmp_p = ((bmp.readpressure() / 1000.0) * 0.3)*100;
unsigned int data0;
unsigned int data1;
light.getdata(data0, data1);
double lux;
boolean = light.getlux(gain,ms,data0,data1,lux);
long llux = lux*100;
sprintf(buffer, "get /apps/add_env.php?rec_date=%04d-%02d-%02d%c20%02d:%02d:%02d&location=%s&temperature=%ld&pressure=%ld&humidity=%ld&illumination=%ld http/1.1",
year(), month(), day(), '%', hour(), minute(), second(), location, mcp_f, bmp_p, dht_h, llux);
serial.println(buffer);
httprequest(buffer);
}
}
Arduino Forum > Using Arduino > Programming Questions > Ethernet shield and PHP
arduino
Comments
Post a Comment