Print HEX commands for ESP8266 4CH

How can i write hex commands? ESP8266 will communicate (on-off a relay) with other mcu by this serial command:
“0xA0 0x01 0x01 0xA2”

(lctech device : http://www.chinalctech.com/cpzx/1/333.html)

Working Arduino example:

byte relON[] = {0xA0, 0x01, 0x01, 0xA2};  //Hex command to send to serial for open relay
byte relOFF[] = {0xA0, 0x01, 0x00, 0xA1}; //Hex command to send to serial for close relay

int ledState = false;
unsigned long previousMillis = 0;
const long interval = 2000; //  2 seconds

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize serial:
  Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop()
{
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;   
    if (ledState == true) {
      Serial.write(relON, sizeof(relON));     // turns the relay ON
      ledState = false;
    } else {
      Serial.write(relOFF, sizeof(relOFF));   // turns the relay OFF
      ledState = true;
    }    
  }
}

Soo … what‘s your question ? Just do it :wink:

@hs2 ahhhh :slight_smile: it doesnt work…

Note that Arduino code is not Serial.print it is Serial.write

Tried these :

 while (1) {
        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 1);
        printf ("%#X", 162);
        vTaskDelay(200 / portTICK_PERIOD_MS);

        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 0);
        printf ("%#X", 161);
        vTaskDelay(200 / portTICK_PERIOD_MS);

        printf("%s", "0xA00x010x010xA2");
        vTaskDelay(200 / portTICK_PERIOD_MS);


        printf("%s", "0xA00x010x000xA1");
        vTaskDelay(200 / portTICK_PERIOD_MS);


        printf("%s", "0xA00x010x010xA2");
        printf("%s", "0xA00x010x010xA2");
        printf("%s", "0xA00x010x010xA2");
        vTaskDelay(200 / portTICK_PERIOD_MS);

        printf("%s", "0xA00x010x000xA1");
        printf("%s", "0xA00x010x000xA1");
        printf("%s", "0xA00x010x000xA1");
        vTaskDelay(200 / portTICK_PERIOD_MS);

        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 1);
        printf ("%#X", 162);
        fflush(stdout);
        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 1);
        printf ("%#X", 162);
        fflush(stdout);
        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 1);
        printf ("%#X", 162);
        fflush(stdout);
        vTaskDelay(200 / portTICK_PERIOD_MS);


        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 0);
        printf ("%#X", 161);
        fflush(stdout);
        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 0);
        printf ("%#X", 161);
        fflush(stdout);
        printf ("%#X", 160);
        printf ("%#X", 1);
        printf ("%#X", 0);
        printf ("%#X", 161);
        fflush(stdout);
        vTaskDelay(200 / portTICK_PERIOD_MS);

      }