combined codes : connected letter box

Hi everybody ! :)

I'm discovering the arduino, I love it but I still have a lot to learn...

I'm trying to make a connected mailbox. To do this, I proceeded in two phases: 1) Receive a notification on my smartphone via pushingbox when the mailbox opens. 2) Be able to open the mailbox online.

I use a shield ethernet as well as a shield relays that is connected to an electrical gash.

I have both codes (opening online and sending notifications via pushingbox) that works separately. However, when I combine them, the online opening works without any problem but sending notifications via puhingbox no longer works. I must have made an error in the combination of codes. Anyone can help me ?

Thank you very much, have a nice day ! :)

Hi everybody ! :)

I'm discovering the arduino, I love it but I still have a lot to learn...

I'm trying to make a connected mailbox. To do this, I proceeded in two phases: 1) Receive a notification on my smartphone via pushingbox when the mailbox opens. 2) Be able to open the mailbox online.

I use a shield ethernet as well as a shield relays that is connected to an electrical gash.

I have both codes (opening online and sending notifications via pushingbox) that works separately. However, when I combine them, the online opening works without any problem but sending notifications via puhingbox no longer works. I must have made an error in the combination of codes. Anyone can help me ?

Thank you very much, have a nice day ! :)

If you want us to help with your code is it not logical that we must see your code? What is an electrical gash? Please read the "how to use the forum" stickies to see how to format and post code.

electric door lock* (problem of translation)

Code:

#include <SPI.h>

#include <Ethernet2.h>

byte mac = {0x90, 0xA2, 0xDA, 0x0F, 0xDF, 0xAB};

byte ip = {139, 165, 27, 64};

char DEVID1 = “vEF115D082FD49CB”;

uint8_t pinDevid1 = 3;

int pinRelais = 7;

boolean etatRelais = 0; //etat du pin
boolean DEBUG = true;
char serverName = “api.pushingbox.com”;
boolean pinDevid1State = false;
boolean lastConnected = false;

EthernetServer serveur(80);
EthernetClient client;

void setup() {

pinMode(pinRelais, OUTPUT);
pinMode(pinDevid1, INPUT);

Serial.begin (9600);

Ethernet.begin (mac, ip);

Serial.print("*\n-> Le serveur est sur l’adresse : ");

Serial.println(Ethernet.localIP());

serveur.begin();

if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// no point in carrying on, so do nothing forevermore:
while(true);
}
else{
Serial.println(“Ethernet ready”);
// print the Ethernet board/shield’s IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
}

void loop() {

gestionClient();

if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON
{
if(DEBUG){Serial.println(“pinDevid1 is HIGH”);}
pinDevid1State = true;
//Sending request to PushingBox when the pin is HIGH
//sendToPushingBox(DEVID1);
}

if (digitalRead(pinDevid1) == LOW && pinDevid1State == true) // switch on pinDevid1 is OFF
{
if(DEBUG){Serial.println(“pinDevid1 is LOW”);}
pinDevid1State = false;
//Sending request to PushingBox when the pin is LOW
//sendToPushingBox(DEVID1);
}

if (client.available()) {
char c = client.read();
if(DEBUG){Serial.print(c);}
}
if (!client.connected() && lastConnected) {
if(DEBUG){Serial.println();}
if(DEBUG){Serial.println(“disconnecting.”);}
client.stop();
}
lastConnected = client.connected();
}

void sendToPushingBox(char devid){
client.stop();
if(DEBUG){Serial.println(“connecting…”);}

if (client.connect(serverName, 80)) {
if(DEBUG){Serial.println(“connected”);}

if(DEBUG){Serial.println(“sendind request”);}
client.print(“GET /pushingbox?devid=”);
client.print(devid);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(serverName);
client.println(“User-Agent: Arduino”);
client.println();
}
else {
if(DEBUG){Serial.println(“connection failed”);}
}
}

void gestionClient() {

EthernetClient client = serveur.available();

if (client) {

Serial.println(“Client en ligne”); //on le dit…

if (client.connected()) {

GET(client); //appel de la fonction de décodage

entete(client);

corps(client);

piedPage(client);

Serial.println(“Fin de communication avec le client\n”);

client.stop();

}

}

}

void entete(EthernetClient cl) {

cl.println(“HTTP/1.1 200 OK”);

cl.println(“Content-Type: text/html; charset=ascii”);

cl.println(“Connection: close”);

cl.println();

//balises d’entête

cl.println("");

cl.println("");

cl.println(“Relais”);

cl.println("

Relais P. DENEYE mars 2017



");

}

//fonction de fabrication du corps de page

void corps(EthernetClient cl) {

cl.println("
");

cl.print("
Relais ");

if (etatRelais) {

cl.print("ON ");

}

else {

cl.print("OFF ");

}

cl.print(" <a href=?");

cl.print(‘c’);

cl.println(" target=_self >Change
");

}

//fonction de fabrication du pied de page

void piedPage(EthernetClient cl) {

//balises de pied de page

cl.println("


");

cl.println("");

cl.println("");

}

//fonction décodage GET

void GET(EthernetClient cl) {

boolean lu = 0;

while (cl.available()) {

char c = cl.read();

delay(1); //delai de lecture

if (c == ‘?’ && lu == 0) {

c = cl.read();

if (c == ‘c’) {

etatRelais = !etatRelais;

digitalWrite(pinRelais, etatRelais);
Serial.println(etatRelais);

}

delay(10);

lu = 1;

}

}

}

Please read the "how to use the forum" stickies to see how to format and post code.