help with recieving messages from bluemix nodered

Firstly, if this is the wrong thread please feel free to suggest another(my first time using this in a long time).

Hi,
I am using the MKR1000 to connect to IBM Bluemix’s NodeRed using sample codes from heartratebluemix/oxigenarbluemix2016.ino at master · waltercoan/heartratebluemix · GitHub which uses the “WiFi101.h”. Instead of sensor values for testing I sent just a random number (22). I’ve tested and indeed my NodeRed when setup reads the value as expected. I want to send a command from NodeRed to the device, I saw the “messageReceived” and “client.onMessage(messageReceived)” in the arduino-mqtt/ArduinoWiFi101.ino at master · 256dpi/arduino-mqtt · GitHub example. I tried write code, but can’t see data received, so I don’t know how to receive a command such as “blink:{}” to turn off the on board LED kind of like from device-arduino/registered.ino at master · ibm-watson-iot/device-arduino · GitHub registered flow example.

My code attempt is below along with an extract from NodeRed. Btw I replaced password info for topics, ssid etc with templates. The connection is working for my code, just need to know how to receive the command.

#include <SPI.h>
#include <WiFi101.h>
#include <WiFiSSLClient.h>
#include <MQTTClient.h>

WiFiClient net;
MQTTClient client;
String topic="iot-2/evt/bpm/fmt/json";
int status = WL_IDLE_STATUS;     // the WiFi radio's status
char ssid[] = "ssid";     //  your network SSID (name)
char pass[] = "password";  // your network password

void connect() {
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.print("\nconnecting...");
  while (!client.connect("d:DevOrg:deviceType:deviceID","use-token-auth","tokenPassword")) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("\nconnected!");
  client.subscribe("iot-2/cmd/+/fmt/string");
}
void setup() {
  Serial.begin(115200);
  while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
  }
  client.begin("DevOrg.messaging.internetofthings.ibmcloud.com", 1883, net);
  connect();
  pinMode(6, OUTPUT); //on board led
}
void loop(){
  client.loop();
  //String json = buildJson();
  //client.publish(topic,"{\"name\":\"test\",\"data\":\"" + String(22)+"\"}");
   client.onMessage(messageReceived);
 delay(5000);
}
String buildJson() {
  String data = "{";
  data+="\n";
  data+= "\"d\": {";
  data+="\n";
  data+="\"Volts\": 10"; // Note: wrap like \"10\" for a string, this is a number we are sending.
  data+="\n";
  data+="}";
  data+="\n";
  data+="}";
  return data;
}
void messageReceived(String &topic, String &payload) {
  Serial.println("message recieved");
  if(topic== "iot-2/cmd/blink") {
      Serial.print("Command IS Supported : ");
      Serial.print(payload);
      Serial.println("\t.....\n");
      //Blink
      for(int i = 0 ; i < 2 ; i++ ) {
        digitalWrite(6, HIGH);
        delay(1000);
        digitalWrite(6, LOW);
        delay(1000);
      }
    } 
    else {
      Serial.println("Command Not Supported:");            
    }
}

commandNode.PNG

injectNode.PNG

nodeRed.PNG