You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x1D, 0x6E };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(10,29,224,28); // numeric IP for Google (no DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,108,116,131);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
EthernetClient client2;
int ledo = 8;
int ledf = 7;
const int unBouton = 2;
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /url HTTP/1.1");
client.println("Host: www.telefab.fr");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void connection(){
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /?id=janvier&pass=aurelien&url=http://telefab.fr/lab/api/lieu?password=tatelalefab HTTP/1.1");
client.println("Host: www.telefab.fr");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
//on travaille sur le bouton
int buttonState = digitalRead(unBouton);
// if there are incoming bytes available
// from the server, read them and print the
// lorsque le bouton n'est pas enfoncé
if (buttonState == LOW){
client.connect(server, 80);
Serial.println("connected");
client.println("GET /url HTTP/1.1");
client.println("Host: www.telefab.fr");
client.println("Connection: close");
client.println();
if (client.available()) {
char c = client.read();
Serial.print(c);
tableau[1]=tableau[0];
tableau[0]=c;
}
if(!client.connected()){
Serial.println("disconnecting.");
Serial.print(tableau[1]);
if (tableau[1] == ope){
Serial.println("OUVERT");
digitalWrite(ledo,HIGH);
digitalWrite(ledf,LOW);
}
if (tableau[1] == clo) {
Serial.println("FERME");
digitalWrite(ledf,HIGH);
digitalWrite(ledo,LOW);
}
delay(5000);
// do nothing forevermore
client.stop();
}
}
// Lorsque l'on appuie sur le bouton
if (buttonState == HIGH){
Serial.println("COUCOU1");
client2.connect(server, 80);
Serial.println("connected");
if (tableau[1] == ope) {
etat = 0;
client2.println("POST /url HTTP/1.1");
client2.println("Host: 10.29.224.28");
client2.println("Content-Type: application/x-www-form-urlencoded");
client2.println("Content-Length: 6");
client2.println();
client2.print("open=");
client2.println(etat);
client2.println();
Serial.println("MODIFICATION DONE");
client2.stop();
delay(2000);
client.stop();
}
include <SPI.h>
include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x1D, 0x6E };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(10,29,224,28); // numeric IP for Google (no DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,108,116,131);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
EthernetClient client2;
int ledo = 8;
int ledf = 7;
const int unBouton = 2;
char tableau[2];
char ope = {'N'};
char clo = {'D'};
int etat = 1;
void setup() {
pinMode(ledo, OUTPUT);
pinMode(ledf, OUTPUT);
pinMode(unBouton, INPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /url HTTP/1.1");
client.println("Host: www.telefab.fr");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void connection(){
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /?id=janvier&pass=aurelien&url=http://telefab.fr/lab/api/lieu?password=tatelalefab HTTP/1.1");
client.println("Host: www.telefab.fr");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
//on travaille sur le bouton
int buttonState = digitalRead(unBouton);
// if there are incoming bytes available
// from the server, read them and print the
// lorsque le bouton n'est pas enfoncé
if (buttonState == LOW){
client.connect(server, 80);
Serial.println("connected");
client.println("GET /url HTTP/1.1");
client.println("Host: www.telefab.fr");
client.println("Connection: close");
client.println();
if (client.available()) {
char c = client.read();
Serial.print(c);
tableau[1]=tableau[0];
tableau[0]=c;
}
if(!client.connected()){
Serial.println("disconnecting.");
Serial.print(tableau[1]);
if (tableau[1] == ope){
Serial.println("OUVERT");
digitalWrite(ledo,HIGH);
digitalWrite(ledf,LOW);
}
if (tableau[1] == clo) {
Serial.println("FERME");
digitalWrite(ledf,HIGH);
digitalWrite(ledo,LOW);
}
delay(5000);
// do nothing forevermore
client.stop();
}
// Lorsque l'on appuie sur le bouton
if (buttonState == HIGH){
Serial.println("COUCOU1");
client2.connect(server, 80);
Serial.println("connected");
if (tableau[1] == ope) {
etat = 0;
client2.println("POST /url HTTP/1.1");
client2.println("Host: 10.29.224.28");
client2.println("Content-Type: application/x-www-form-urlencoded");
client2.println("Content-Length: 6");
client2.println();
client2.print("open=");
client2.println(etat);
client2.println();
Serial.println("MODIFICATION DONE");
client2.stop();
delay(2000);
client.stop();
}
}
}
The text was updated successfully, but these errors were encountered: