Led on,off, with api and arduino

#include <BoltIoT-Arduino-Helper.h>
String val = "";
int led = 5;

void setup()
{
  pinMode(5, OUTPUT);
  boltiot.begin(Serial);
  Serial.begin(9600);
  boltiot.setCommandString("ON", ON);
  boltiot.setCommandString("OFF", OFF);
}
String ON(String *data) {
  val = data[0];
  val.trim();
  if (val.equals("O"))
  {
    digitalWrite(led, HIGH);
    Serial.println(val);
  }
  return val;
}
String OFF(String *data) {
  val = data[1];
  val.trim();
  if (val.equals("F"))
  {
    digitalWrite(led, LOW);
    Serial.println(val);
  }
  return val;
}
void loop() {
  boltiot.handleCommand();
  Serial.println(val);

}

i used this code,but my val string is not accepting any value.
please help.

@chpritampatro123
Elaborate your problem precisely what you are going to do.

My arduino is unable to receive the value sent by bolt wifi module

@chpritampatro123,
This is @prasanthsaikanumuri

To turn on or turn off on the LED follow these steps:

  • Click here to learn the syntax for using the BoltIoT remote API
  • Use the serial write API call to send the command “TurnOn” or “TurnOff” to the Arduino.
  • The command “TurnOn” will tell the Arduino to turn on the LED, whereas the command “TurnOff” will tell the Arduino to turn off the LED.
  • You can then use the serial read API call to get a response from the Arduino.
    *Click here to know how to “Send Serial Data Output” and “Read Incoming Serial Data”

Arduino Code To turn on or turn off on the LED.

#include <BoltIoT-Arduino-Helper.h>
#define TURN_ON_COMMAND  "TurnOn"
#define TURN_OFF_COMMAND "TurnOff"
#define LED_PIN       LED_BUILTIN
String turnOnLed(String *data){
  digitalWrite(LED_PIN,HIGH);
  return "Led turned on";
}
String turnOffLed(String *data){
  digitalWrite(LED_PIN,LOW);
  return "Led turned off";
}
void setup() {
  boltiot.setCommandString(TURN_ON_COMMAND,turnOnLed);
  boltiot.setCommandString(TURN_OFF_COMMAND,turnOffLed);
  boltiot.begin(Serial);
}
void loop() {
  boltiot.handleCommand();
}

http://cloud.boltiot.com/remote/myapi/serialWrite?data=ON&deviceName=myid
sorry but ur code didn’t worked.please help.

hey @chpritampatro123 this is the similar answer of this question. :slight_smile: