Turning on LED with command read in terminal

I’m having trouble turning on my LED with a command that is received from my server. To simplify things, I’ve made a “1” printed in the terminal turn the LED on and a “0” turn the LED off.

My WiFly shield is able to retrieve my 1 or 0 from a text file running on the server. It is read and gets printed which can be seen using the terminal. This is the result that I get:

LED Activated

connected
0

disconnecting.
-96

The “0” that is printed above comes from the server as the command. However, when “0” is printed the LED is activated as seen above and the variable that I used to document the “0” is printed as “-96.” I would like val = 0 if “0” is printed in the terminal as read on client and use the conditional statement to either turn on or off the LED. Can anyone make a suggestion?

Thanks,

Andrew

This is my code:

// (Based on Ethernet's WebClient Example)

#include "WiFly.h"


#include "Credentials.h"


byte server[] = { 66, 96, xxx, xx }; // Google

//Client client(server, 80);

Client client("xxxxxxx.com", 80);

void setup() {

  Serial.begin(9600);

  WiFly.begin();

  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
    
  }
    Serial.println("Can u reach me ?");
    Serial.print("IP: ");
    Serial.println(WiFly.ip());
  

  Serial.println("connecting...");
int ledpin = 13;
 
  pinMode(ledpin, OUTPUT);      // declare LED as output   
  Serial.begin(9600);  
  Serial.print("LED Program Initiated\n");  
 

  }
char a;
char c;
int ledpin = 49;
char val;

void loop() {
for(;;){
     client.connect();
     client.println("GET http://xxxxxxx.com/newfile.php");
     delay(1000);
          if(client.connected())
          {
            Serial.println();
            Serial.println("connected");
	    while(client.available() > 0)
            {
           
             c = client.read();
             Serial.print(c);
         
            }
          }
           while(Serial.available()){
 
           val = Serial.read();
            }
     Serial.println();
     client.stop();
     Serial.println("disconnecting.");
     delay(2500);

  
    Serial.println(val,DEC);
    if (val = 1) {
      digitalWrite(ledpin, HIGH);
      Serial.print("LED Activated\n");
    } else {
      digitalWrite(ledpin, LOW);
      Serial.print("LED Deactivated\n");
    }
}
}

Perhaps there is some confusion as to the 1 and 0 being numbers or characters.

for(;;){

It really isn't necessary to run an infinite loop inside an infinite loop.

    if (val = 1) {

You are assigning the value 1 to the variable val. The assignment operator returns a value equal to the value assigned (1). You most likely want to use the equality operator (==) here, not the assignment operator (=).

Why are you mixing client input and serial input? Where do you want the value to turn the LED on to come from? The client or the serial port?

If it is from the serial port, and the data on the port comes from the Serial Monitor, the value received will be '1', not 1.