Esp8266 proogram code

I have a program to run 3leds from webpage. the command is posted to the serial port but the lights do go on. I have posted the code. grateful for your help

`#define MAX_TOKENS 40
#define MAX_INPUT_LENGTH 30

#include <ESP8266HTTPClient.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WebSerial.h>
#include "html.h"

AsyncWebServer server(80);

#define ARRSIZE(x) sizeof(x)/sizeof(x[0])
#define MAX_TOKENS 40
#define MAX_INPUT_LENGTH 30
const char* ssid = "";          // Your WiFi SSID
const char* password = "";  // Your WiFi Password


//const char* ssid = "" // Write here your router's username
//const char* password = ""; // Write here your router's password



const char* validCommands[] = { "zhag", "pri", "ya" };
size_t maxCommandLength; // size of the longest command, here it will be 4 for goat
const byte commandCount = sizeof validCommands / sizeof validCommands[0];
const char* separators = " ,.;:/+-&\t";
void zhagCommand();
void priCommand();
void yaCommand();

void (*funcPtrs[])() = { &zhagCommand, &priCommand, &yaCommand };

static_assert((commandCount == sizeof funcPtrs / sizeof funcPtrs[0]), "Error: command list and functoin list not matching");

char inputBuffer[MAX_INPUT_LENGTH];
char* tokens[MAX_TOKENS];
byte tokenIndex = 0;

//const char* validCommands[] = { "zhag", "pri", "ya",};
//void (*funcPtrs[ARRSIZE(validCommands)])() = { &zhagCommand, &priCommand, &yaCommand,};

#define blueLed 12
#define whiteLed 14
#define redLed 16

void getInput() {
  while (!Serial.available());
  Serial.readBytesUntil('\n', inputBuffer, MAX_INPUT_LENGTH);
}
void getCommand(AsyncWebServerRequest *request) {

  // GET request for "/process?command=<message>"
  if (request->hasParam("command")) {
    parseCommands(request->getParam("command")->value().c_str());
    request->send(200, "text/html", webPage);
  }
}
void notFound(AsyncWebServerRequest *request) {
  request->send(404, "text/plain", "Not found");
}
void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  pinMode(12, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(16, OUTPUT);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.printf("WiFi Failed!\n");
    while (true) yield();
  }
  Serial.println("IP Address: ");
  Serial.println(WiFi.localIP());
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(200, "text/html", webPage);
  });
  server.on("/process", HTTP_GET, getCommand);
  server.onNotFound(notFound);
  server.begin();
  Serial.println("recognized commands: ");
  for (auto && s : validCommands) {
    maxCommandLength = max(maxCommandLength, strlen(s));
    Serial.print("  - "); Serial.println(s);
  }
  Serial.println("Web site ready.");

}
void tokeniseInput() {
  char* token = strtok(inputBuffer, " ,.-");
  while (token != NULL && tokenIndex < MAX_TOKENS) {
    tokens[tokenIndex++] = token;
    token = strtok(NULL, " ,.-");
    if (tokenIndex >= MAX_TOKENS)
      Serial.println(" ERR! Max Tokens Reached");
  }
}

void printTokens() {
  for (byte i = 0; i < tokenIndex; i++) {
    Serial.print("Token Stored: ");
    Serial.println(tokens[i]);
  }
}

void reset() {
  for (byte i = 0; i < MAX_INPUT_LENGTH; i++)
    inputBuffer[i] = NULL;
  for (byte i = 0; i < MAX_TOKENS; i++)
    tokens[i] = nullptr;
  tokenIndex = 0;
}

void processCommand(const char* aCommand) {
  size_t commandIndex;
  if (strlen(aCommand) > 0) {
    for (commandIndex = 0; commandIndex < commandCount; commandIndex++) {
      if (strcmp(validCommands[commandIndex], aCommand) == 0) {
        funcPtrs[commandIndex]();
        break;
      }
    }
    if (commandIndex >= commandCount) {
      Serial.print("Command not recognized : "); Serial.println(aCommand);
    }
  }
}
void parseCommands(const char* aCommandList) {
  bool error = false;
  char commandBuffer[maxCommandLength + 1];
  commandBuffer[maxCommandLength] = '\0';

  const char * startPtr = aCommandList;
  const char * endPtr;
  if (strlen(aCommandList) > 0)
    do {
      endPtr = strpbrk(startPtr, separators);
      if (endPtr == nullptr) {
        if (strlen(startPtr) > maxCommandLength) error = true;
        else strncpy(commandBuffer, startPtr, maxCommandLength);
      } else {
        size_t nbChars = endPtr - startPtr;
        if (nbChars > maxCommandLength) error = true;
        else {
          strncpy(commandBuffer, startPtr, nbChars);
          commandBuffer[nbChars] = '\0';
        }
      }
      if (error) {
        Serial.print("Error parsing "); Serial.print(startPtr); Serial.println(". Continue.");
      } else processCommand(commandBuffer);
      error = false;
      startPtr = endPtr + 1;
    } while (endPtr != nullptr);
}


void zhagCommand() {
  Serial.println("zhag");
  digitalWrite(12, HIGH);
  delay(1000);
  digitalWrite(12, LOW);
  delay(1000);
  digitalWrite(14, HIGH);
  delay(1000);
  digitalWrite(14, LOW);
  delay(1000);
  digitalWrite(16, HIGH);
  delay(1000);
  digitalWrite(16, LOW);
  delay(1000);
}
void priCommand() {
  Serial.println("pri");
  //  digitalWrite(12, HIGH);
  //  delay(1000);
  //  digitalWrite(12, LOW);
  //  delay(1000);
  digitalWrite(14, HIGH);
  delay(1000);
  digitalWrite(14, LOW);
  delay(1000);
  digitalWrite(16, HIGH);
  delay(1000);
  digitalWrite(16, LOW);
  delay(1000);
}
void yaCommand() {
  Serial.println("ya");
  digitalWrite(12, HIGH);
  delay(1000);
  digitalWrite(12, LOW);
  delay(1000);
  //  digitalWrite(14, HIGH);
  //  delay(1000);
  //  digitalWrite(14, LOW);
  //  delay(1000);
  digitalWrite(16, HIGH);
  delay(1000);
  digitalWrite(16, LOW);
  delay(1000);
}
void loop() {
  if (Serial.available()) {
    Serial.write(Serial.read());
  }
  getInput();
  tokeniseInput();
  printTokens(); // Uncomment for debugging
  //processCommand();
  WebSerial.println(" ");
  delay(2000);
  reset();
}

@james114, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

This code uses function-pointers. This is a pretty advanced programming technology.
I'm a somehow advanced hobby-coder. I have never used function-pointers yet.
I would not recommend using such a code as the first project.

This tutorial offers some insight about controlling IO through a webinterface but not about the very basic stuff.

If you are very new to programming you should first learn the basics.

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

thanks

I would like to welcome you to the forum, but I am a poor ambassador. I would like to understand your code, but the dearth of comments leaves me guessing what you intend to happen.

Hi,Steve

When a command is executed I want the LEDs to respond in the sequence I have programmed it. That is all I want. Thanks
Jaames

Even for the best coding expert reading down a few **normal-word-**sentences is easier than analysing code.

So you should explain in normal words what you have programmed the LEDs to do.
best regards Stefan

my program is expected to light up LRDs in matrix sequence when a command is executed. ie. if I type zhag, LEDs 12, 14 and 16 should light up for 1 second with a 1 second delay for off before the other led lights up.
Thanks Rgds

So this means you type the letters "zhag" into the serial monitor and then LEDs 12,14,16 light up for 1 second. Then switch off
1 second later another LED (which IO-pin ?) is switched on and stays on forever?

best regards Stefan

At the top of loop() you are throwing away an input character by echoing it to Serial Monitor. You then call 'getInput()' to read any remaining characters. Doesn't your debug output show that the first character of your command is missing? I'm not surprised that the command is not recognized.

12 (1000)
delay
14(1000)
delay
16(1000)
delay
In this sequence or similar such sequence for other commands
thanks n rgds

can you please explain where and how. Thanks

Where:

How:

I tried removing debugging options from webserial .cpp from librry files it is not working. can you please help. thanks

I tried removing debugging options from webserial .cpp from librry files it is not working. can you please help. thanks