Socket Server Pin Control


i getting unexpected behavior. happening first time send data socket both relay's turn on. want send string pin6l, or pin6h testing purposes trying use single digit.

ideally want send many items p6ld2p7h translated to:
pin6 low delay 2000 pin7high

but can not seem make simple integer work this. appreciated.
code: [select]

// when client sends first byte, hello:
  if (client) {
    if (!alreadyconnected) {
      // clead out input buffer:
      client.flush();
      serial.println("we have new client");
      client.println("hello, client!");
      alreadyconnected = true;
    }

    if (client.available() > 0) {
      // read bytes incoming client:
      int thischar = client.read();
      // echo bytes client:
      server.write(thischar);
      // echo bytes server well:
      serial.write(thischar);
      if (thischar == 1){
        digitalwrite(relay[0], low);
      }
      if (thischar = 2){
        digitalwrite(relay[0], high);
      }     
      if (thischar = 3){
        digitalwrite(relay[1], low);
      }
      if (thischar = 4){
        digitalwrite(relay[1], high);
      }           
    }
  }
}

code: [select]
      serial.write(thischar);
why using binary function send data serial port? data going?

why on earth use char in name of variable of type int?

the stream-based read() functions return int can tell you tried read data isn't there, if that. data returned in low order byte. if never try read data isn't there, can store returned value in byte or char variable, , never lose data.

if did that, you'd see char variable contained '1', not 1.


Arduino Forum > Using Arduino > Programming Questions > Socket Server Pin Control


arduino

Comments