아두이노에 이더넷 쉴드를 사용하여 TCP/IP 통신으로 HITACHI 프로젝터를 제어하는 방법입니다.

 

각각의 프로토콜을 통해 전원을 켜고 끌 수 있으며, 현재 전원 상태 및 램프 수명 시간을 얻을 수 있습니다.

 

#include <SPI.h>
#include <Ethernet.h>

int p_Button = 6;
bool b_Power = false;

/// Projector Protocol
char SetPowerOn[]  = { 0xBE, 0xEF, 0x03, 0x06, 0x00, 0xBA, 0xD2, 0x01, 0x00, 0x00, 0x60, 0x01, 0x00 };
char SetPowerOff[] = { 0xBE, 0xEF, 0x03, 0x06, 0x00, 0x2A, 0xD3, 0x01, 0x00, 0x00, 0x60, 0x00, 0x00 };
char GetStatus[]   = { 0xBE, 0xEF, 0x03, 0x06, 0x00, 0x19, 0xD3, 0x02, 0x00, 0x00, 0x60, 0x00, 0x00 };
char GetLampTime[] = { 0xBE, 0xEF, 0x03, 0x06, 0x00, 0xC2, 0xFF, 0x02, 0x00, 0x90, 0x10, 0x00, 0x00 };
char getData[3];
int strLen;
int len;

/// UDP Variable
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server(192,168,0,171);
IPAddress local_IP(192,168,0,56);
unsigned int localPort = 23;

EthernetClient client;

void setup() {
  // put your setup code here, to run once:
  Ethernet.begin(mac, local_IP);
  Serial.begin(9600);
  pinMode(p_Button, INPUT_PULLUP);

  if(client.connect(server, 23)){
    Serial.println("Connected 1st projector");
    //client.write(GetStatus, sizeof(GetStatus));
  }
  else
  {
    Serial.println("connection failed");
  }
   
}

void loop() {
  if (!client.connected())
  {
    if (client.connect(server, 23))
    {
      Serial.println("reconnected");
      delay(500);
      client.write(GetStatus, sizeof(GetStatus));
    }
    else
    {
     Serial.println("reconnection failed"); 
     delay(500);
    }
  }
  else
  {
    if (digitalRead(p_Button) == LOW)
    {
      client.write(GetStatus, sizeof(GetStatus));
      Serial.print("Get Status : ");

      String getData = "";
      delay(100);
      while (client.available() > 0)
      {
        int8_t tmpData = client.read();
        getData += tmpData;
        Serial.print(tmpData, HEX);
        Serial.print(" ");
      }
      if (sizeof(getData) > 0)
      {
        Serial.print(sizeof(getData));
        Serial.println(getData);
      }

      if (getData.charAt(2) == '1')
      {
        Serial.println("1st Projector is opened");
      }
      else if (getData.charAt(2) == '0')
      {
        Serial.println("1st Projector is closed");
      }
      else
      {
        Serial.println("1st Projector is cooling down");
      }
      
    }
    delay(100);
//    Serial.println(tmpData[1]);
  }
  
}

+ Recent posts