Case Sensitive Terminal Input

Hi.

Im very new to Blynk but loving it so far. In a very short time my projects have come on leaps and bounds.

I have created a relay controller and temperature monitor on an ESP8266 - NodeMCU.

Here is the code, I have commented it as best I can:

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * This example runs directly on ESP8266 chip.
 *
 * Note: This requires ESP8266 support package:
 *   https://github.com/esp8266/Arduino
 *
 * Please be sure to select the right ESP8266 module
 * in the Tools -> Board menu!
 *
 * Change WiFi ssid, pass, and Blynk auth token to run :)
 *
 **************************************************************
 * Hardware:
 * NodeMCU Module with ESP8266-10E.
 * TMP36 Temperature Sensor on Pin A0.
 * 4 Channel Relay Board connected to Pins D0, D1, D2 & D5.
 *
 **************************************************************/

#define BLYNK_PRINT Serial                                                            // Define Blynk serial debugging.
#include <ESP8266WiFi.h>                                                              // Include library.
#include <BlynkSimpleEsp8266.h>                                                       // Include library.
#include <SimpleTimer.h>                                                              // Include library.

WidgetTerminal terminal(V9);                                                          // Create instance of Terminal Widget.

#define D0 16                                                                         // Define the the GPIO pin to a Digital pin.
#define D1 5 // I2C Bus SCL (clock)                                                   // Define the the GPIO pin to a Digital pin.
#define D2 4 // I2C Bus SDA (data)                                                    // Define the the GPIO pin to a Digital pin.
#define D5 14 // SPI Bus SCK (clock)                                                  // Define the the GPIO pin to a Digital pin.
#define RELAY1_PIN D0  // D0                                                          // Define the relay pin.
#define RELAY2_PIN D1  // D1                                                          // Define the relay pin.
#define RELAY3_PIN D2  // D0                                                          // Define the relay pin.
#define RELAY4_PIN D5  // D1                                                          // Define the relay pin.

char auth[] = "ff1ccbb2e1444ea5b53b92d8a860c0a5";                                     // Blynk authorisation code.
bool isFirstConnect = true;                                                           // Keep this flag not to re-sync on every reconnection.

BLYNK_CONNECTED() {                                                                   // This function will run every time Blynk connection is established.
  if (isFirstConnect) {                                                               // Check if first connection.
    Blynk.syncAll();                                                                  // Request Blynk server to re-send latest values for all pins.  
    isFirstConnect = false;                                                           // Store first connect value as low.
  }                                                                                   // End of if statement.
}                                                                                     // End of Blynk Connected.

char ssid[] = "NetworkX7";                                                            // Name of WiFi network.                                                                                        
char pass[] = "colaboy74";                                                            // WiFi netork password.

SimpleTimer timer;                                                                    // Create an instance of the simple timer.

BLYNK_WRITE(1) {                                                                      // Receive data from app.
    if (param.asInt()) {                                                              // If statement to check incomming data.
  digitalWrite(RELAY1_PIN, HIGH);                                                     // Drive relay pin high.
    }                                                                                 // End of if statement.
    else {                                                                            // Else statement to check incomming data.
      digitalWrite(RELAY1_PIN, LOW);                                                  // Drive relay pin low.
    }                                                                                 // End of else statement.
  }                                                                                   // End of Blynk Write.

BLYNK_WRITE(2) {                                                                      // Receive data from app.
    if (param.asInt()) {                                                              // If statement to check incomming data.
  digitalWrite(RELAY2_PIN, HIGH);                                                     // Drive relay pin high.
    }                                                                                 // End of if statement.
    else {                                                                            // Else statement to check incomming data.
      digitalWrite(RELAY2_PIN, LOW);                                                  // Drive relay pin low.
    }                                                                                 // End of else statement.
  }                                                                                   // End of Blynk Write.

BLYNK_WRITE(3) {                                                                      // Receive data from app.
    if (param.asInt()) {                                                              // If statement to check incomming data.
  digitalWrite(RELAY3_PIN, HIGH);                                                     // Drive relay pin high.
    }                                                                                 // End of if statement.
    else {                                                                            // Else statement to check incomming data.
      digitalWrite(RELAY3_PIN, LOW);                                                  // Drive relay pin low.
    }                                                                                 // End of else statement.
  }                                                                                   // End of Blynk Write.

BLYNK_WRITE(4) {                                                                      // Receive data from app.
    if (param.asInt()) {                                                              // If statement to check incomming data.
  digitalWrite(RELAY4_PIN, HIGH);                                                     // Drive relay pin high.
    }                                                                                 // End of if statement.
    else {                                                                            // Else statement to check incomming data.
      digitalWrite(RELAY4_PIN, LOW);                                                  // Drive relay pin low.
    }                                                                                 // End of else statement.
  }                                                                                   // End of Blynk Write.

BLYNK_WRITE(5) {                                                                      // Receive data from app.
    if (param.asInt()) {                                                              // If statement to check incomming data.
  digitalWrite(RELAY1_PIN, HIGH);                                                     // Drive relay pin high.
  digitalWrite(RELAY2_PIN, HIGH);                                                     // Drive relay pin high.
  digitalWrite(RELAY3_PIN, HIGH);                                                     // Drive relay pin high.
  digitalWrite(RELAY4_PIN, HIGH);                                                     // Drive relay pin high.
    }                                                                                 // End of if statement.
  }                                                                                   // End of Blynk Write.

BLYNK_WRITE(6) {                                                                      // Receive data from app.
    if (param.asInt()) {                                                              // If statement to check incomming data.
  digitalWrite(RELAY1_PIN, LOW);                                                      // Drive relay pin low.
  digitalWrite(RELAY2_PIN, LOW);                                                      // Drive relay pin low.
  digitalWrite(RELAY3_PIN, LOW);                                                      // Drive relay pin low.
  digitalWrite(RELAY4_PIN, LOW);                                                      // Drive relay pin low.
    }                                                                                 // End of if statement.
  }                                                                                   // End of Blynk Write.

BLYNK_WRITE(9) {                                                                      // Receive data from app.
   if (String("help") == param.asStr()) {                                             // If statement to check incomming data.
    terminal.println("Commands Available:");                                          // Terminal print.
    terminal.println("Hardware");                                                     // Terminal print.
    terminal.println("Network");                                                      // Terminal print.
    terminal.println("status");                                                       // Terminal print.
    terminal.println("Uptime");                                                       // Terminal print.
    terminal.flush();                                                                 // Ensure terminal print has completed.
   }                                                                                  // End of if statement.
   if (String("hardware") == param.asStr()) {                                         // If statement to check incomming data.
    terminal.println("Hardware:");                                                    // Terminal print.
    terminal.println("NodeMCU - ESP8266-10F");                                        // Terminal print.
    terminal.println("TMP36 Temperature Sensor (A0)");                                // Terminal print.
    terminal.flush();                                                                 // Ensure terminal print has completed.
   }                                                                                  // End of if statement.
    if (String("network") == param.asStr()) {                                         // If statement to check incomming data.
    terminal.print("WiFi Netork: ");                                                  // Terminal print.
    terminal.println(WiFi.SSID());                                                    // Terminal print.
    terminal.print("Local IP Address: ");                                             // Terminal print.
    terminal.println(WiFi.localIP());                                                 // Terminal print.
    terminal.flush();                                                                 // Ensure terminal print has completed.
    }                                                                                 // End of if statement.
    if (String("status") == param.asStr()) {                                          // If statement to check incomming data.
    terminal.print("Relay 1: ");                                                      // Terminal print.
    terminal.println(digitalRead(RELAY1_PIN));                                        // Terminal print.
    terminal.print("Relay 2: ");                                                      // Terminal print.
    terminal.println(digitalRead(RELAY2_PIN));                                        // Terminal print.
    terminal.print("Relay 3: ");                                                      // Terminal print.
    terminal.println(digitalRead(RELAY3_PIN));                                        // Terminal print.
    terminal.print("Relay 4: ");                                                      // Terminal print.
    terminal.println(digitalRead(RELAY4_PIN));                                        // Terminal print.
    terminal.flush();                                                                 // Ensure terminal print has completed.
    }                                                                                 // End of if statement.
    if (String("uptime") == param.asStr()) {                                          // If statement to check incomming data.
    terminal.print("Uptime: ");                                                       // Terminal print.
    terminal.print(millis() / 60000);                                                 // Terminal print.
    terminal.println(" Minutes");                                                     // Terminal print.
    terminal.flush();                                                                 // Ensure terminal print has completed.
    }                                                                                 // End of if statement.
}                                                                                     // End of Blynk Write.

void sendSensorFive() {                                                               // Start of sendSensorFive Void.
  int sensorValue = analogRead(A0);                                                   // Read analog pin.
  float volt = (sensorValue / 1024.0) * 3.3;                                          // Temperature conversion.
  int tempC = (volt - 0.5) * 100;                                                     // Temperature conversion.
  Blynk.virtualWrite(V0, tempC);                                                      // Write temperature data to the app.
}                                                                                     // End of sendSensorFive Void.

void sendSensorThirty() {                                                             // Start of sendSensorThirty Void.
  int sensorValue = analogRead(A0);                                                   // Read analog pin.
  float volt = (sensorValue / 1024.0) * 3.3;                                          // Temperature conversion.
  int tempC = (volt - 0.5) * 100;                                                     // Temperature conversion.
  Blynk.virtualWrite(V7, tempC);                                                      // Write temperature data to the app.
}                                                                                     // End of sendSensorThirty Void.

void sendSensorSixty() {                                                              // Start of sendSensorSixty Void.
  int mins = millis() / 60000;                                                        // Convert millis to minutes.
   Blynk.virtualWrite(V8, mins);                                                      // Write minutes to the app.
}                                                                                     // End of sendSensorSixty Void.

void setup() {                                                                        // Start of Setup Void.
  Serial.begin(9600);                                                                 // Start the serial protocol.
  Blynk.begin(auth, ssid, pass);                                                      // Begin the Blynk protocol.
  timer.setInterval(5000L, sendSensorFive);                                           // Timer to trigger a void.
  timer.setInterval(30000L, sendSensorThirty);                                        // Timer to trigger a void.
  timer.setInterval(30000L, sendSensorSixty);                                         // Timer to trigger a void.
  pinMode(RELAY1_PIN,OUTPUT);                                                         // Setup the pin as an output.
  pinMode(RELAY2_PIN,OUTPUT);                                                         // Setup the pin as an output.
  pinMode(RELAY3_PIN,OUTPUT);                                                         // Setup the pin as an output.
  pinMode(RELAY4_PIN,OUTPUT);                                                         // Setup the pin as an output.
  digitalWrite(RELAY1_PIN, LOW);                                                      // Drive the pin low.
  digitalWrite(RELAY2_PIN, LOW);                                                      // Drive the pin low.
  digitalWrite(RELAY3_PIN, LOW);                                                      // Drive the pin low.
  digitalWrite(RELAY4_PIN, LOW);                                                      // Drive the pin low.
}                                                                                     // End of Setup Void.

void loop() {                                                                         // Start of the Loop Void.
  Blynk.run();                                                                        // Run the Blynk library code.
  timer.run();                                                                        // Run the Timer library code.
}                                                                                     // End of the Loop Void.

The code works great and very nearly does everything I want it to.
I just have a small question though.
In the code snippet below, I can input something in the Terminal Widget which will then return some data.

BLYNK_WRITE(9) {                                                                      // Receive data from app.
   if (String("help") == param.asStr()) {                                             // If statement to check incomming data.
    terminal.println("Commands Available:");                                          // Terminal print.
    terminal.println("Hardware");                                                     // Terminal print.
    terminal.println("Network");                                                      // Terminal print.
    terminal.println("status");                                                       // Terminal print.
    terminal.println("Uptime");                                                       // Terminal print.
    terminal.flush();                                                                 // Ensure terminal print has completed.
   }                                                                                  // End of if statement.
}

The code is searching for a specific string so it has to be case sensitive. Is there any way that I could make it search for either β€œhelp” or β€œHelp”?

Thanks in advance for any help.

Colaboy.

Hello. This is easy.

if (String("help").equalsIgnoreCase(param.asStr())) {
1 Like

Wow, that was quick!

Thank you so much.
I’ll try it straight away.

Thanks again.

Colaboy

1 Like