Salut à tous, petite description rapide:
Je m'appelle Killians, 23ans.
Je travail dans une imprimerie, on possède un espace libre service, avec des photocopieurs/imprimantes.
Nous avons un tableau de bord (datant des année 80/90, donc ultra archaïque) avec des switchs pour activer/désactiver les appareils, et également un Compteur analogique relier a chacune d'entre elle afin de comptabiliser le nombre total de feuille sortie par les client. (remis a Zero manuellement pour le client suivant).
Mon projet, c'est avec un Arduino Mega 2560, et un shield ethernet, faire un interface graphique avec toutes les imprimantes a l'écran, un bouton toggle Activer/Désactiver pour chaque machine, et son compteur associé, ainsi que le tarif total du par le client pour la machine qu'il a utilisé.
J'ai fait une maquette avec un Switch manuel pour tester, et ce, pour une Imprimante.
Tout fonctionne.
Cependant, je bloque totalement sur la façon dont je dois m'y prendre pour répété ceci pour mes 15 Appareils !
Pour le moment j'ai une Arduino Mega 1280, et un ethernet "petit model" (sans port SD), ce qui me complique un peu la vie...
Mais je ne pense pas que ça soit la cause de mon principale problème, donc en attendant de recevoir ma commande avec tout mon équipement final, j'essaye de trouver une solution...
Je joint mon code, si quelqu'un pourrait me mettre sur la voie ?
Merci d'avance !
#include <UIPEthernet.h>
#include <UIPServer.h>
#include <UIPClient.h>
/*DEBUT CONFIG VARIABLES INCREMENTATION - COMPTEUR*/
const int buttonPin = 13;
int buttonState;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
int counter = -1;
/*DEBUT CONFIG VARIABLES INCREMENTATION - COMPTEUR*/
/*DEBUT CONFIG VARIABLES IMPRIMANTE - COPIES - TARIF*/
int copie;
float prix = 0.50;
float total;
/*FIN CONFIG IMPRIMANTE - COMPTEUR*/
/*DEBUT CONFIG ETHERNET*/
static byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static byte ip[] = { 192, 168, 0, 17 }; // ROUTER HOME
//static byte ip[] = { 169, 254, 56, 1 }; // LOCAL ETH
// static byte ipdns[] = { 89, 2, 0, 1 }; ROUTER HOME
static byte ipdns[] = { 89, 2, 0, 1 }; // LOCAL ETH
EthernetServer server(80);
/*FIN CONFIG ETHERNET*/
String HTTP_req; // Stocker la requette HTTP ADD
void setup() {
/*OUVERTURE PORT SERIE ET SERVEUR*/
Serial.begin(57600);
pinMode(buttonPin, INPUT_PULLUP); // Déclaration Boutton Incrementation toujous a 1 - incrementation lorsque relié a la masse.
pinMode(buttonPin, HIGH);
Ethernet.begin(mac, ip, ipdns);
server.begin();
/*PORT SERIE ET SERVEUR*/
/*CALCULS DES VARIABLES*/
/*CALCULS DES VARIABLES*/
}
void loop() {
/*INCREMENTATION de counter*/
boolean pressed = debounce();
if (pressed == true) {
counter++;
Serial.write(counter);
}
copie = counter; //copie prends la valeur du compteur
total = copie*prix; //Total = Nombre de copie multiplié par le prix d'une copie, tronqué a 2 chiffres apres la virgule
/*FIN COUNTER*/
/*DEBUT ECRITURE PAGE WEB*/
EthernetClient client = server.available();
if (client) {
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
HTTP_req += c; // Enregistrement Req HTTP un char a la fois
if (c == '\n' && current_line_is_blank) {
// Toujours introduire les page avec ceci: HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: keep-alive"); //ADD
client.println();
// requet AJAX pout l'etat switch
if (HTTP_req.indexOf("ajax_switch") > -1) {
// lecture etat switch et envoie approprié
GetSwitchState(client);
}
else { // HTTP request for web page
// Envoie Page web - contenant JS et AJAX
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<title>Arduino Compteur Impression AJAX</title>");
client.println("<script>");
client.println("function GetSwitchState() {");
client.println("nocache = \"&nocache=\" \+ Math.random() * 1000000;");
client.println("var request = new XMLHttpRequest();");
client.println("request.onreadystatechange = function() {");
client.println("if (this.readyState == 4) {");
client.println("if (this.status == 200) {");
client.println("if (this.responseText != null) {");
client.println("document.getElementById(\"switch_txt\")\.innerHTML = this.responseText;");
client.println("}}}}");
client.println(
"request.open(\"GET\", \"ajax_switch\" + nocache, true);");
client.println("request.send(null);");
client.println("setTimeout('GetSwitchState()', 1000);");
client.println("}");
client.println("</script>");
client.println("</head>");
client.println("<body onload=\"GetSwitchState()\">");
client.println("<h1>Imprimante 1:</h1>");
client.println(
"<p id=\"switch_txt\">Etat du switch non demandé...</p>");
client.println("</body>");
client.println("</html>");
}
// Affichage de la RequetteHTTP dans le port Serie
Serial.print(HTTP_req);
HTTP_req = ""; // On vide la variable contenant la Requette HTTP
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
current_line_is_blank = true;
}
else if (c != '\r') {
// a text character was received from client
current_line_is_blank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
// Envoie etat switch dans le navigateur
void GetSwitchState(EthernetClient cl)
{
if (digitalRead(13)) {
cl.print("Etat du Bouton d'incremetnation: OFF
");
}
else {
cl.print("Etat du Bouton d'incremetnation: ON
");
}
cl.print("Nombre de Copie(s) = <b>");
cl.print(copie);
cl.print("</b>
");
cl.print("Total = <b>");
cl.print(total);
cl.print(" €</b>
");
cl.stop();
}
/*DEBUT DEBOUNCE POUR INCREMENTATION*/
boolean debounce() {
boolean retVal = false;
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
retVal = true;
}
}
}
lastButtonState = reading;
return retVal;
}
/*FIN DEBOUNCE POUR INCREMENTATION*/