Read adn save 0 and 1 through IP / Ethernet

Hello,

I am trying to read '0' and '1' 50 bit data through ethernet

Eg: http://192.168.1.1/DAT=100010000100001

I need to diplay this in serial.

I tried using

while (client.connected()) {      
      if (client.available()) {
        //
        if( finder.find("DAT") ) {
          unsigned char value = finder.getValue();
          Serial.println(value);
        }

Result printed is : 1161

          unsigned char value = finder.getValue();

That is going to store ONE character in value. "100010000100001" hardly looks like ONE character.

What is finder? What does the getValue() method REALLY return?

PaulS:
What is finder? What does the getValue() method REALLY return?

I am trying to understand, as I know it saves numeric value
I refered to this :
http://playground.arduino.cc/Code/TextFinder

I am reading and learning.

Need links to sites where I can read and get example codes.

I am trying to understand, as I know it saves numeric value

It does. But, what range of numeric values can you store in an unsigned char?

Sorry, for confusing grammer..

I will explain:

PC is connected to Arduino, PC sends binary number to arduino through ethernet interface.

http://192.168.1.10/DIGIT=0101010101

Arduino code has to extract only 0 & 1 from URL.

then calculate bit, i.e number of 0 and 1 recived,

store bit count and binary value in different variables.

Below code is mix of code I got through google search.

if (client) {
 unsigned char digitdata[15] ;
  // TextFinder  finder(client);
  while (client.connected()) {
    if (client.available()) {
      char c = client.read(); //gets byte from ethernet buffer
      if (c != '\n' && c != '\r' ) {
        clientline[index] = c;
        index++;
        continue;
        clientline[index] = 0;
      }
      if (strstr(clientline, "/WIEG=") != 0) {
        char * pch;
        char *filename;
        pch=strrchr(clientline,'WIEG=');
        if (pch!=NULL)    {
          Serial.println(pch+1);
        }
      }
      delay(1);
      client2.stop();
    }
  }
}

[\code]


output of this code is 0101010101 HTTP/1.1


Check number of bit received, it received between 10 bit to 15 bit.

Need to save binary value in  digitdata[15]

Arduino code has to extract only 0 & 1 from URL.

Which 0 or 1? That URL does NOT contain only 0 or 1.

It contains a string that contains only 0s and 1s, but that is not the same thing. At all.

After you store the whole URL, in a char array, locating the = sign is trivial. Once you know where that is, the number of bits is trivial to calculate. You know how many characters you stored. You know how many are not in the value part of the URL. The difference is the number of characters that ARE in the value part.

As for making a binary value from the value portion, you have NOT explained whether the bit pattern represents the high bits of the value or the low bits. If you know that, then comparing the chars in the array, and using bitSet() will easily allow you to populate a variable with the "binary string" that you inefficiently send.

PaulS:
Which 0 or 1? That URL does NOT contain only 0 or 1.

It contains a string that contains only 0s and 1s, but that is not the same thing. At all.

After you store the whole URL, in a char array, locating the = sign is trivial. Once you know where that is, the number of bits is trivial to calculate. You know how many characters you stored. You know how many are not in the value part of the URL. The difference is the number of characters that ARE in the value part.

As for making a binary value from the value portion, you have NOT explained whether the bit pattern represents the high bits of the value or the low bits. If you know that, then comparing the chars in the array, and using bitSet() will easily allow you to populate a variable with the "binary string" that you inefficiently send.

  1. yes URL contins characters, as 0 and 1, and other html code.

  2. Yes, 1 represents high, and 0 represents low. below is code for another program which reads from serial port.

  3. I am not able to figure out how to store only 0 and 1 , between DIGIT= and HTML

Eg: GET /DIGIT=10000100011 HTTP/1.1

Eg. code to read from serial port.

 if (Serial.available() > 0 ) {
    incomingByte = Serial.read();
    if ( incomingByte == 48 ){ // DECIMAL 0 
    bitCount++;
    flagBit = 0;
  } 
  else if ( incomingByte == 49 ){ // DECIMAL 1
    databits[bitCount] = 1;
    bitCount++;
    flagBit = 0;
  } 
[\code]
[code]
unsigned char i;
  for (i=0; i<bitCount ; i++ ) { 
    binaryValue <<=1;
    binaryValue |= databits[i];
  }

[\code]

[/code]

    if ( incomingByte == 48 ){ // DECIMAL 0

or

    if ( incomingByte == '0' ){ // No useless comment needed

Which do you prefer?

How is databits defined? Initialized? Why are you not storing the 0s too?

How do YOU think reading data from the serial port differs from reading it from a client instance? The correct answer is that it does not differ AT ALL.

PaulS:
How do YOU think reading data from the serial port differs from reading it from a client instance? The correct answer is that it does not differ AT ALL.

Serial port: I am able to send only 0 and 1 , no additional data.

Ethernet: Web page is sending data, it has html contents, so storing as character.

I am new to CPP / Arduino programing, I see example codes, documentations and then use part of code required.

Serial port: I am able to send only 0 and 1 , no additional data.

Actually, you can not send 0 and/or 1. You CAN send '0' and/or '1'.

Ethernet: Web page is sending data, it has html contents, so storing as character.

The data coming from the serial port is character, too.

I did not realize! thanks..

Now the Question is, how to exrtact only required '0' and '1' from html codes, containing.

GET /DIGIT=0101010101 HTML/1.1

Need only '0' and '1' between "DIGIT=" and "HTML/", then store the result in array[],
count no of '0' and '1' received.

technofreek:
I did not realize! thanks..

Now the Question is, how to exrtact only required '0' and '1' from html codes, containing.

GET /DIGIT=0101010101 HTML/1.1

Need only '0' and '1' between "DIGIT=" and "HTML/", then store the result in array[],
count no of '0' and '1' received.

Eg. code to read from serial port.

What happens when you use THAT code, changing Serial to client?