Websocket SimpleWebSocket ArduinoHttpClient.h cannot process string

Hi all,

I’m trying to do decision making over the information received from a websocket string

I’m using MKR1000 and ArduinoClient.h edited the SimpleWebSocket to fit my pourposes but dont seam to get the hangs of it.

  Simple WebSocket client for ArduinoHttpClient library
  Connects to the WebSocket server, and sends a hello
  message every 5 seconds

  note: WiFi SSID and password are stored in config.h file.
  If it is not present, add a new tab, call it "config.h"
  and add the following variables:
  char ssid[] = "ssid";     //  your network SSID (name)
  char pass[] = "password"; // your network password

  created 28 Jun 2016
  by Sandeep Mistry

  this example is in the public domain
#include <ArduinoHttpClient.h>
#include <WiFi101.h>
#include "config.h"

char serverAddress[] = "";  // server address
int port = 8000;

WiFiClient wifi;
WebSocketClient client = WebSocketClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
int count = 0;

void setup() {
  pinMode(6, OUTPUT);

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

void loop() {
  Serial.println("starting WebSocket client");

  while (client.connected()) {
    int messageSize = client.parseMessage();

    if (messageSize > 0) {
      String test = client.readString();
      if (client.readString() == "off") {
        digitalWrite(6, LOW);
      else {
        digitalWrite(6, HIGH);


As you can see I’m trying several way to process the “client” readString() method but there is not way of putting it in a variable. Ultimately what I’m trying to achieve is:

if (client.readString() == "off")

but it never gets in to the condition, dont know why, any ideas?

Kind regards.

I figure out the problem was that I could only read the incomming data buffer once and the it deletes whatever is there apparently,

so I store the the read.String() on a String object variable and that worked.

if (messageSize > 0) { //Serial.println(client.readString()); String input = client.readString(); Serial.println(input);