View Single Post
Eski 18-02-2012, 22:48   #19
Potasyum
Ağaçsever
 
Giriş Tarihi: 10-02-2012
Şehir: Glasgow
Mesajlar: 58
Deneme,Gelistirme - YouTube

Cok basit ve ucuz bir sistem kontrol ve ethernet kiti bir kac roleler birazda c++ biliyorsan bunu herkez ama herkez yapabilir artik.Endustiriyel olanlarin tek farki pahali, yapilma suresinde cok para ve zaman harcanmasi olmalari.Bu kitler cinden turkiyedende de elde edilir.Tek mesele kuracaginiz sistem icin harcayaniz zaman ve para hesabidir.Isi ucuz degil, ekonomik yapabilmektir.

Ben ucuz alacak/yapacak kadar zengin degilim .!? ucuz is zaman ve para kaybi koca yaristayiz iste sperm gibi.

Firavun;Karuna soyleyin camur tuglalardan bana yuksek kule yapsin ki goklere cikip musanin tanrisini goreyim. ipod ile aydaki oyuncaklari yerkureden kontrol etmek hayal degil artik.Marsta kumdaki organik maddeleri tespid edebiliyorsun dunyadan.

Herneyse bu sistemi androide uyarlayabilirsem kodu paylasacagim.Kode su anlik bu surecte.

Kod:
/*
 Une application pour controler des prises de courant via une interface web.

Inspiré de l'exemple proposé par le SDK Arduino "WebServer"
 */

/******************************************************/
/* init des variables */
/******************************************************/
#include <SPI.h>
#include <Ethernet.h>

/******************************************************/
/* CONSTANTES */
/******************************************************/
#define MARCHE           'm'
#define ARRET            'a'
#define NB_MAX_SWITCHES   6
#define NB_SWITCHES       6
#define HTTP_PORT        80

/******************************************************/
/* init des variables */
/******************************************************/
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x42, 0x49 };
byte ip[] = { 192,168,1,66 };

boolean endRequest = false;
boolean currentLineIsBlank = false;

// Name of the switch
boolean pickUpTheName = false;
boolean gotName = false;
int plugName = 0;

// State of the switch
boolean pickUpTheState = false;
boolean gotState = false;
char plugState = ARRET;

// States of all the switches
char tabPlugNameState[NB_MAX_SWITCHES];

// Pins of all the switches
int pinSwitch[NB_MAX_SWITCHES];


// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
Server server(HTTP_PORT);

/******************************************************/
/* Setup */
/******************************************************/
void setup()
{
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  
  // STATUT des switchs au départ
  tabPlugNameState[0] = ARRET;
  tabPlugNameState[1] = ARRET;
  tabPlugNameState[2] = ARRET;
  tabPlugNameState[3] = ARRET;
  tabPlugNameState[4] = ARRET;
  tabPlugNameState[5] = ARRET;
  
  // PINS utilisées pour les switchs
  // PINS dispos : 0,1,3,4,5,6,7,8,9
  pinSwitch[0] = 4;
  pinSwitch[1] = 5;
  pinSwitch[2] = 6;
  pinSwitch[3] = 7;
  pinSwitch[4] = 8;
  pinSwitch[5] = 13;
  
  
  plugName = 0;
  plugState = ARRET;
  
  
  for (int pin=0; pin < NB_SWITCHES; pin++)
    {
    tabPlugNameState[pin] = ARRET;  
    pinMode(pinSwitch[pin], OUTPUT);
    }

}

/******************************************************/
/* Main (loop) */
/******************************************************/
void loop()
{
  // listen for incoming clients

  Client client = server.available();

  if (client) {

    // init des variables de boucle
    currentLineIsBlank = true;
    endRequest = false;
    gotName=false;
    gotState=false;
    pickUpTheName=false;
    pickUpTheState=false;
    plugName = 0;
    plugState = ARRET;
  
    // client connecté + available = request HTTP arrivée donc à traiter
    while (!endRequest && client.connected()) {
      if (client.available()) {
         char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        
        // on récupère les données si dispo
        if (pickUpTheName) {
          pickUpTheName = false;
          gotName=true;
          plugName = (int)c - (int)'0';
          }
          
        if (pickUpTheState) {
          pickUpTheState = false;
          gotState=true;
          plugState = c;
          }
        
        // gestion du caractère (de fin, ?, =)
        // si '\n' + currentLineIsBlank = "\n\r\n\r", fin de la request
        if (c == '\n' && currentLineIsBlank) {
            endRequest = true;
        }
        // si '?', le caractère suivant = name du switch
        else if (c == '?') {
          pickUpTheName = true;

        }
        // si '=', le caractère suivant = state du switch
        else if (c == '=') {
          pickUpTheState = true;

        }    
        // si '\n', ligne vide
        else if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        // si '\r', ignorer
        //else if (c != '\r') {
          // you've gotten a character on the current line
          //currentLineIsBlank = false;
        //}

      } // FIN IF client.available
    } // FIN WHILE client.connected && not endRequest
    
    // Inscription de l'état de la prise dans le tableau des états des prises
    if (gotName && gotState)
      {
      tabPlugNameState[plugName-1] = plugState; 
   
      // Application des états aux pins
      if (plugState == MARCHE)
        {
        digitalWrite(pinSwitch[plugName-1], HIGH);
        }
      else
        {
        digitalWrite(pinSwitch[plugName-1], LOW);
        }
      }
    
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html\n");
    client.println("<html><title>  Kontrol Dugmeleri </title><body><br />");
    client.println("<fieldset STYLE=\"border-radius: 10px;margin-left: 30%;font-family: verdana,arial, sans-serif ;width:300px;\"><legend> MuRaT's Androit Kontrol Dugmeleri</legend>");
    client.println("<div STYLE=\"text-align: center;background-color: white; width:300px;\">");
    for (int i = 0; i<NB_SWITCHES ; i++) {
        client.println("<form name=\"myform\" method=\"GET\">");
        client.print("<div STYLE=\"border-radius: 10px;font-family: arial, sans-serif ; background-color: grey ; font-size: 12pt ; color: white;\">");
        client.print("<label>ROLE ");
        client.print(i+1);
        client.print(" | <span ");
        if (tabPlugNameState[i] == MARCHE) { client.print("STYLE=\"color:yellow;\"");}
        client.print("> </span> | AC </label>");
        client.print("<input type=\"radio\" name=\"");
        client.print(i+1);
        client.print("\"value=\"m\" ");
        if (tabPlugNameState[i] == MARCHE) { client.print(" checked "); }
        client.print("/> KAPAT");
        client.print("<input type=\"radio\" name=\"");
        client.print(i+1);
        client.print("\" value=\"a\" ");
        if (tabPlugNameState[i] == ARRET) { client.print(" checked "); }
        client.print("/>");
        client.println("<button type=\"submit\">ONAY TUSU</button></div></form>");      
        }
    client.println("</div>");
    client.println("</fieldset>");
    
    /*** DEBUG ****/
    /* LOG sur serial du tableau des switchs *
    client.print("<hr/>");
    for (int s = 0; s<NB_SWITCHES ; s++) {
      client.print("Switch ");
      client.print(s+1);
      client.print(" : ");
      
      client.print(tabPlugNameState[s]);
      client.print(" : ");
      client.print(pinSwitch[s]);      
      client.println("\n<br/>\n");
    }
    * END DEBUG */
    
    client.println("</body></html>");
    
    // give the web browser time to receive the data
    delay(5);

    // close the connection:
    client.stop();

  } // FIN IF CLIENT

} // FIN LOOP

Eklenen Resimler
  

Düzenleyen Potasyum : 19-02-2012 saat 00:04
Potasyum Çevrimdışı   Alıntı Yaparak Cevapla Başa Dön