| 
 | 
6#
 
 
 樓主 |
發表於 2011-9-2 10:08:12
|
只看該作者
 
 
 
各位大大,想請問一下,我現在想要做個網路型的紅外線解碼器,想請問一下,我要怎麼把解到的碼送到網頁上,因為我在loop裡,有去看user是否有送參數進來,如果是我要的參數,它就會開會去收外紅線,只是收到了以後,我要怎麼讓它一直丟上網頁? 
 
 
 
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x3A, 0xB3 }; //physical mac address 
byte ip[] = { 192, 168, 111, 50 };            // ip in lan 
byte gateway[] = { 192, 168, 111, 254 };            // internet access via router 
byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask 
Server server(80);                                      //server port 
byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC) 
String readString = String(30); //string for fetching data from address 
 
IRsend irsend;                           // 定義 IRsend 物件來發射紅外線訊號 
 
const int irReceiverPin = 2;             // 紅外線接收器 OUTPUT 訊號接在 pin 2 
IRrecv irrecv(irReceiverPin);            // 定義 IRrecv 物件來接收紅外線訊號 
decode_results results;                  // 解碼結果將放在 decode_results 結構的 result 變數裏 
 
int input_nu; 
String string_temp; 
char to_int_temp[1]; 
 
// 顯示紅外線協定種類 
void showIRProtocol(decode_results *results)  
{ 
  Serial.print("Protocol: "); 
   
  // 判斷紅外線協定種類 
  switch(results->decode_type) { 
   case NEC: 
     Serial.print("NEC"); 
     break; 
   case SONY: 
     Serial.print("SONY"); 
     break; 
   case RC5: 
     Serial.print("RC5"); 
     break; 
   case RC6: 
     Serial.print("RC6"); 
     break; 
   case DISH: 
     Serial.print("DISH"); 
     break; 
   case SHARP: 
     Serial.print("SHARP"); 
     break; 
   default: 
     Serial.print("Unknown encoding");   
  }   
 
  // 把紅外線編碼印到 Serial port 
  Serial.print(", irCode: ");             
  Serial.print(results->value, HEX);    // 紅外線編碼 
  Serial.print(",  bits: ");            
  Serial.println(results->bits);        // 紅外線編碼位元數     
} 
 
 
void setup() 
{ 
  Ethernet.begin( mac, ip, gateway, subnet );            //start Ethernet 
  Serial.begin(9600); 
  irrecv.enableIRIn();                                   // 啟動紅外線解碼 
} 
 
void loop()  
{  
   
// Create a client connection 
Client client = server.available(); 
  if (client) { 
    while (client.connected()) { 
   if (client.available()) { 
    char c = client.read(); 
    //read char by char HTTP request 
    if (readString.length() < 30)  
      { 
        //store characters to string  
        readString += c; 
      }   
        //output chars to serial port 
        //Serial.print(c); 
        //if HTTP request has ended 
        if (c == '\n') { 
               if(readString.substring( 6, 7 ) == 'L')  
               { 
                 string_temp = readString.substring( 8, 9 ); 
                 to_int_temp[0] = string_temp[0]; 
                 input_nu = atoi(to_int_temp); 
                 switch(input_nu) 
                 { 
                   case 1: 
                   for(int i = 0; i < 5000; i ++) 
                   { 
                        if(irrecv.decode(&results)) 
                        {                  
                          showIRProtocol(&results);                         
                          irrecv.resume();  
                        } 
                        delay(1); 
                   }   
                     break; 
                   default: 
                     break;                    
                 } 
               } 
          input_nu = 0;   
  
  
          // now output HTML data starting with standart header 
          client.println("HTTP/1.1 200 OK"); 
          client.println("Content-Type: text/html"); 
          client.println(); 
          //set background to yellow 
          client.print("<body style=background-color:yellow>"); 
          //send first heading 
          client.println("<font color='red'><h1>Netown test IR control html</font></h1>"); 
         
          client.println("</body></html>"); 
          //clearing string for next read 
          readString=""; 
          //stopping client 
          client.stop(); 
           
            } 
          } 
        } 
      } 
       
} |   
 
 
 
 |