Hi everyone ,
I'm trying to call a php file to change a Field in my database hosted in www.hostinger.fr but i've tried many topics but no way.
Here is my code :
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {192,168,1,65};
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
Servo porteservo; // create servo object to control a servo
Servo garageservo; // create servo object to control a servo
String readString;
int vent = 3 ;
int motporte = 2 ;
int motfenetre = 5 ;
int lampe = 6 ;
int motgarage = 7 ;
int capteurgas = 8 ;
int capteurfumee = 9 ;
int ledgas = 13 ;
const int analogInPingas = A0 ;
int gassensorValue = 0;
//////////////////////
void setup(){
porteservo.attach(motporte); // attaches the servo on pin 9 to the servo object
garageservo.attach(motgarage); // attaches the servo on pin 9 to the servo object
pinMode(vent, OUTPUT); //pin selected to control
pinMode(motporte, OUTPUT); //pin selected to control
pinMode(motfenetre, OUTPUT); //pin selected to control
pinMode(lampe, OUTPUT); //pin selected to control
pinMode(motgarage, OUTPUT); //pin selected to control
pinMode(ledgas, OUTPUT);
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//the pin for the servo co
//enable serial data print
Serial.begin(9600);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}
void loop(){
// read the analog in value:
gassensorValue = analogRead(analogInPingas);
if (gassensorValue >= 750)
{
digitalWrite(ledgas, HIGH); // sets the LED on
}
else
{
digitalWrite(ledgas, LOW); // sets the LED off
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.println(gassensorValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(5000);
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />");
client.println("<TITLE>Home Automation</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Home Automation</H1>");
client.println("<hr />");
client.println("
");
client.println("<a href=\"/?venton\"\">Ouvrir ventilateur</a>");
client.println("<a href=\"/?ventoff\"\">Fermer ventilateur</a>
");
client.println("
");
client.println("<a href=\"/?porteon\"\">Ouvrir porte</a>");
client.println("<a href=\"/?porteoff\"\">Fermer porte</a>
");
client.println("
");
client.println("<a href=\"/?feneton\"\">Ouvrir fenetre</a>");
client.println("<a href=\"/?fenetreoff\"\">Fermer fenetre</a>
");
client.println("
");
client.println("<a href=\"/?lighton\"\">Ouvrir lampe</a>");
client.println("<a href=\"/?lightoff\"\">Eteindre lampe</a>
");
client.println("
");
client.println("<a href=\"/?garageon\"\">Ouvrir porte garage</a>");
client.println("<a href=\"/?garageoff\"\">Fermer porte garage</a>
");
client.println("
");
client.println("<a href=\"/?entree\"\">Scénario d'entrée</a>");
client.println("<a href=\"/?sortie\"\">Scénario de sortie</a>
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("?venton") >0)//checks for on
{
digitalWrite(vent, HIGH); // set pin 4 high
Serial.println("Ventilateur En Marche");
}
else{
if(readString.indexOf("?ventoff") >0)//checks for off
{
digitalWrite(vent, LOW); // set pin 4 low
Serial.println("Ventilateur En Arrêt");
}
else{ if(readString.indexOf("?porteon") >0)//checks for off
{
porteservo.write(90); // set pin 4 low
delay(3);
Serial.println("Porte Ouverte");
}
else{ if(readString.indexOf("?porteoff") >0)//checks for off
{
porteservo.write(1); // set pin 4 low
delay(3);
Serial.println("Porte Fermée");
}
else{ if(readString.indexOf("?feneton") >0)//checks for off
{
digitalWrite(motfenetre, HIGH); // set pin 4 low
Serial.println("Fenetre ouverte");
}
else{ if(readString.indexOf("?fenetoff") >0)//checks for off
{
digitalWrite(motfenetre, LOW); // set pin 4 low
Serial.println("Fenetre Fermée");
}
else{ if(readString.indexOf("?lighton") >0)//checks for off
{
digitalWrite(lampe, HIGH); // set pin 4 low
Serial.println("Lampe Allumée");
}
else{ if(readString.indexOf("?lightoff") >0)//checks for off
{
digitalWrite(lampe, LOW); // set pin 4 low
Serial.println("Lampe Eteinte");
}
else{ if(readString.indexOf("?garageon") >0)//checks for off
{
garageservo.write(150);
delay(3);
Serial.println("Porte Garage Ouverte");
}
else{ if(readString.indexOf("?garageoff") >0)//checks for off
{
garageservo.write(0);
delay(3);
Serial.println("Porte Garage Fermée");
}
else{ if(readString.indexOf("?entree") >0)//checks for off
{
digitalWrite(vent,HIGH);
Serial.println("Ventilateur En Marche");
digitalWrite(motgarage, HIGH); // set pin 4 low
Serial.println("Porte Garage Ouverte");
digitalWrite(lampe,HIGH);
Serial.println("Lampe Allumée");
delay(10000);
digitalWrite(lampe , LOW);
digitalWrite(motgarage , LOW);
}
else{ if(readString.indexOf("?sortie") >0)//checks for off
{
digitalWrite(vent, LOW); // set pin 4 low
Serial.println("Ventilateur Fermée");
digitalWrite(lampe,HIGH);
Serial.println("Lampe Allumée");
digitalWrite(motgarage,HIGH);
Serial.println("Porte Garage Ouverte");
delay(10000);
digitalWrite(lampe,LOW);
digitalWrite(motgarage , LOW);
}
}}}}}}}}}}}
//clearing string for next read
readString="";
}
}
}
}
}
The code i want to search for solution is :
{
digitalWrite(vent, HIGH); // set pin 4 high
Serial.println("Ventilateur En Marche");
if (client.connected()) {
client.println("smarthousesfax.bl.ee/venton.php");
client.println("Host smarthousesfax.bl.ee");
}
And my other problem is with android
How to make my application listening to every changing in the field of database
it means if
if(readString.indexOf("?venton") >0)
a notification will be sent to the application
Think you
