Character detection in C ++ stream char

I am working on a piece of arduino code that uses a version of BlackWidow with built-in Wi-Fi. Using the WiServer.h library, I use the SimpleClient.pde example with mods to send a call to a web server, which will simply return an integer - 0, 1 or 2. The final goal is to turn on the pin for the correct red, green or yellow brake light . Integers represent the cumulative state of our Hudson CI.

I'm the lazy bastard of PHP, and pointers scare me. The code I'm working with

// Function that prints data from the server
void printData(char* data, int len) {

  // Print the data returned by the server
  // Note that the data is not null-terminated, may be broken up into smaller packets, and 
  // includes the HTTP header. 
  while (len-- > 0) {
    Serial.print(*(data++));
  }
}

printData () is a callback to a web server, and when it starts, it sends the following to the serial monitor (these are three loops, a new line before a new exit):

HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:37 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html

0HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:45 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html

0HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:58 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html

0

The part I need to identify is 0, which can also be 1 or 2.

printData() turnOnAppro Light() - , HIGH. .

, , , . * (Data ++) - , , ... , char . , .

arduino and 4-relay boardenter image description here

+3
3

,

Serial.print(data[len-1])

,

+2

, :

data[len - 1]
+1

: Content-Type:.

C- ++ std::string, find_first .

std::istringstream "0" 0.

0
source

Source: https://habr.com/ru/post/1791280/


All Articles