Smart coffee machine with facial recognition and remote control

Dependencies:   Camera_LS_Y201 EthernetInterface EthernetNetIf HTTPClient SRF05 TextLCD mbed-rtos mbed-src

Committer:
projetmacintel
Date:
Wed Jan 15 11:09:52 2014 +0000
Revision:
0:43669f623d43
dep?t final PAO Macintel

Who changed what in which revision?

UserRevisionLine numberNew contents of line
projetmacintel 0:43669f623d43 1 #include "ethernet.h"
projetmacintel 0:43669f623d43 2
projetmacintel 0:43669f623d43 3 //const char* ECHO_SERVER_ADDRESS = "194.254.15.213/reco/";
projetmacintel 0:43669f623d43 4 const char* ECHO_SERVER_ADDRESS = "192.168.1.40";
projetmacintel 0:43669f623d43 5 const int ECHO_SERVER_PORT = 4242;
projetmacintel 0:43669f623d43 6
projetmacintel 0:43669f623d43 7 EthernetInterface eth;
projetmacintel 0:43669f623d43 8 TCPSocketConnection socket;
projetmacintel 0:43669f623d43 9 HTTPClient http;
projetmacintel 0:43669f623d43 10 int timeOut = HTTP_CLIENT_DEFAULT_TIMEOUT;
projetmacintel 0:43669f623d43 11
projetmacintel 0:43669f623d43 12 bool preparationEthernet()
projetmacintel 0:43669f623d43 13 {
projetmacintel 0:43669f623d43 14 afficherAuCentreDeLEcran("Preparation :", "Ethernet (1/2)");
projetmacintel 0:43669f623d43 15 wait(0.5);
projetmacintel 0:43669f623d43 16
projetmacintel 0:43669f623d43 17 if(eth.init() == 0)
projetmacintel 0:43669f623d43 18 //if( eth.init("192.168.1.67", "255.255.255.0", ECHO_SERVER_ADDRESS) == 0) // Test en local (Sans DHCP)
projetmacintel 0:43669f623d43 19 {
projetmacintel 0:43669f623d43 20 afficherAuCentreDeLEcran("Preparation :", "Ethernet (2/2)");
projetmacintel 0:43669f623d43 21
projetmacintel 0:43669f623d43 22 if(eth.connect() == 0)
projetmacintel 0:43669f623d43 23 {
projetmacintel 0:43669f623d43 24 afficherAuCentreDeLEcran("Machine", "connectee");
projetmacintel 0:43669f623d43 25 allumerLed(1);
projetmacintel 0:43669f623d43 26 return true;
projetmacintel 0:43669f623d43 27 }
projetmacintel 0:43669f623d43 28
projetmacintel 0:43669f623d43 29 else
projetmacintel 0:43669f623d43 30 afficherAuCentreDeLEcran("Erreur :", "Ethernet (2/2)");
projetmacintel 0:43669f623d43 31 }
projetmacintel 0:43669f623d43 32
projetmacintel 0:43669f623d43 33 else
projetmacintel 0:43669f623d43 34 afficherAuCentreDeLEcran("Erreur :", "Ethernet (1/2)");
projetmacintel 0:43669f623d43 35
projetmacintel 0:43669f623d43 36 wait(2);
projetmacintel 0:43669f623d43 37 afficherAuCentreDeLEcran("Err ethernet", eth.getMACAddress());
projetmacintel 0:43669f623d43 38
projetmacintel 0:43669f623d43 39 allumerLed(2);
projetmacintel 0:43669f623d43 40 return false;
projetmacintel 0:43669f623d43 41 }
projetmacintel 0:43669f623d43 42
projetmacintel 0:43669f623d43 43 void deconnexionEthernet()
projetmacintel 0:43669f623d43 44 {
projetmacintel 0:43669f623d43 45 eth.disconnect();
projetmacintel 0:43669f623d43 46 afficherAuCentreDeLEcran("Machine", "deconnectee");
projetmacintel 0:43669f623d43 47 }
projetmacintel 0:43669f623d43 48
projetmacintel 0:43669f623d43 49 bool connexionSocket()
projetmacintel 0:43669f623d43 50 {
projetmacintel 0:43669f623d43 51 /*int i = 0;
projetmacintel 0:43669f623d43 52 while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
projetmacintel 0:43669f623d43 53 {
projetmacintel 0:43669f623d43 54 printf("Unable to connect to (%s) on port (%d)\r\n\r", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
projetmacintel 0:43669f623d43 55 wait(1);
projetmacintel 0:43669f623d43 56 i++;
projetmacintel 0:43669f623d43 57 if(i>5)
projetmacintel 0:43669f623d43 58 {
projetmacintel 0:43669f623d43 59 return 0; // Échec
projetmacintel 0:43669f623d43 60 }
projetmacintel 0:43669f623d43 61 }
projetmacintel 0:43669f623d43 62 return 1;*/
projetmacintel 0:43669f623d43 63 for(int i = 0 ; i < 4 ; i ++)
projetmacintel 0:43669f623d43 64 {
projetmacintel 0:43669f623d43 65 if(socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
projetmacintel 0:43669f623d43 66 {
projetmacintel 0:43669f623d43 67 afficherAuCentreDeLEcran("Serveur", "injoignable", "sur", ECHO_SERVER_ADDRESS);
projetmacintel 0:43669f623d43 68 wait(3);
projetmacintel 0:43669f623d43 69 }
projetmacintel 0:43669f623d43 70
projetmacintel 0:43669f623d43 71 else
projetmacintel 0:43669f623d43 72 return true;
projetmacintel 0:43669f623d43 73 }
projetmacintel 0:43669f623d43 74
projetmacintel 0:43669f623d43 75 return false;
projetmacintel 0:43669f623d43 76 }
projetmacintel 0:43669f623d43 77
projetmacintel 0:43669f623d43 78 void deconnexionSocket()
projetmacintel 0:43669f623d43 79 {
projetmacintel 0:43669f623d43 80 socket.close();
projetmacintel 0:43669f623d43 81 }
projetmacintel 0:43669f623d43 82
projetmacintel 0:43669f623d43 83 bool envoyerRequete(char complement_url[200], char *reponse, int longueur_reponse)
projetmacintel 0:43669f623d43 84 {
projetmacintel 0:43669f623d43 85 char url[500];
projetmacintel 0:43669f623d43 86 sprintf(url, "http://asi-12-cafetiere.insa-rouen.fr/mbed/%s", complement_url);
projetmacintel 0:43669f623d43 87 //sprintf(url, "http://192.168.1.10/mbed/%s", complement_url);
projetmacintel 0:43669f623d43 88 HTTPResult retour = http.get(url, reponse, longueur_reponse);
projetmacintel 0:43669f623d43 89
projetmacintel 0:43669f623d43 90 if(retour != HTTP_OK)
projetmacintel 0:43669f623d43 91 {
projetmacintel 0:43669f623d43 92 afficherAuCentreDeLEcran("ECHEC", "Envoi requete");
projetmacintel 0:43669f623d43 93 wait(1);
projetmacintel 0:43669f623d43 94 }
projetmacintel 0:43669f623d43 95
projetmacintel 0:43669f623d43 96 return retour == HTTP_OK; // Succès
projetmacintel 0:43669f623d43 97 }
projetmacintel 0:43669f623d43 98
projetmacintel 0:43669f623d43 99 bool envoyerRequete(char complement_url[200])
projetmacintel 0:43669f623d43 100 {
projetmacintel 0:43669f623d43 101 char reponse_vide[1];
projetmacintel 0:43669f623d43 102 return envoyerRequete(complement_url, reponse_vide, 1);
projetmacintel 0:43669f623d43 103 }
projetmacintel 0:43669f623d43 104
projetmacintel 0:43669f623d43 105 void envoyerChaineSocket(char *chaine, int taille_chaine, char *reponse, int longueur_reponse_max)
projetmacintel 0:43669f623d43 106 {
projetmacintel 0:43669f623d43 107 int m;
projetmacintel 0:43669f623d43 108 socket.send_all(chaine, taille_chaine);
projetmacintel 0:43669f623d43 109 m = socket.receive(reponse,longueur_reponse_max);
projetmacintel 0:43669f623d43 110 reponse[m] = '\0';
projetmacintel 0:43669f623d43 111 }
projetmacintel 0:43669f623d43 112
projetmacintel 0:43669f623d43 113