readLine()


Description

Reads line based data from the server the client is connected to.
The line based data means data are finished to CR(0x0d) and LF(0x0a).

Syntax

client.readLine()
client.readLine(buf, size)

Parameters

buf - buffer to store reading data
size - length(bytes) of buffer

Returns

the length of line - on success
0 - on failure

Example

#include <Phpoc.h>

PhpocServer server(80);

char slideName;
int slideValue;

void setup() {
  Serial.begin(9600);
  while(!Serial)
    ;

  // initialize PHPoC [WiFi] Shield:
  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  //Phpoc.begin();

  // start WebSocket server
  server.beginWebSocket("remote_slide");

  // print IP address of PHPoC [WiFi] Shield to serial monitor:
  Serial.print("WebSocket server address : ");
  Serial.println(Phpoc.localIP());
}

void loop() {
  // wait for a new client:
  PhpocClient client = server.available();

  if (client) {
    // read a string that is terminated by a carriage return and a newline
    // characters:
    String slideStr = client.readLine();

    if(slideStr)
    {
      // when an user moves a slider on web app, web app sends a string to
      // Arduino. The first character of string is slide name, followed by slide
      // value and terminated by a carriage return and a newline characters.
      slideName = slideStr.charAt(0);
      slideValue = slideStr.substring(1).toInt();

      Serial.print(slideName);
      Serial.print('/');
      Serial.println(slideValue);
    }
  }
}