Problem with Array

Hello!

I writed a simple code for string to array conversion.
The raw command send perfectly, but the esp board restarts, without http response.
What is the problem with my code?
I worked a lot of hours with this.
I write in php language.
In php, this function is very simple... but in this program language is very difficult.

My unworked code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <IRsend.h>
#include <IRremoteESP8266.h>


#define IR_SEND_PIN D2


IRsend irsend(IR_SEND_PIN);

const char* ssid = "ssid";
const char* password = "pass";
IPAddress ip(192, 168, 0, 168);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

ESP8266WebServer server(80);

uint16_t rawcommand[]={};

void hexsend() {}

void rawsend()
{
  int kovetkezoindex;
  int nextindex;
  long szamok;

  String message;
  String command1=server.argName(0);
  String value1=server.arg(0);
  String command2=server.argName(1);
  String value2=server.arg(1);



  int elsoindex = value2.indexOf(',');
  String cmd = value2.substring(0, elsoindex);
  szamok = cmd.toInt();
  rawcommand[0] = szamok;
  message += rawcommand[0];
  message += "\n";
  
  int rawszama = value1.toInt();

for (int i=1; i < rawszama; i++)
{

  if (i==1)
  {
    kovetkezoindex = value2.indexOf(',', elsoindex+1);
    int utolsoindex = kovetkezoindex-elsoindex;
    String cmd = value2.substring(utolsoindex, kovetkezoindex);
    nextindex = kovetkezoindex+1;
    szamok = cmd.toInt();
    rawcommand[i] = szamok;
    message += rawcommand[i];
    message += "\n";
   
  }
  else if(i==rawszama-1)
  {
    kovetkezoindex = value2.lastIndexOf(',');
    String cmd = value2.substring(kovetkezoindex+1);
    szamok = cmd.toInt();
    rawcommand[i] = szamok;
    message += rawcommand[i];
    message += "\n";

  }
  else
  {
    kovetkezoindex = value2.indexOf(',', nextindex);
    String cmd = value2.substring(nextindex, kovetkezoindex);
    nextindex = kovetkezoindex+1;
    szamok = cmd.toInt();
    rawcommand[i] = szamok;
    message += rawcommand[i];
    message += "\n";

  }

}
irsend.sendRaw(rawcommand, rawszama, 38);

server.send(200, "text/plain", message);       //Response to the HTTP request

}

void setup() {
  irsend.begin();
  
  // Initialize serial port
  Serial.begin(9600);
  while (!Serial) continue;
    WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS Responder Started");
  }

  server.begin();
  Serial.println("HTTP Server Started");


server.on("/rawsend", rawsend);
server.on("/hexsend", hexsend);
}


void loop() {
  server.handleClient();
}

The probe request:

http://192.168.0.168/rawsend?rawszama=19&value=1304,1188,494,1210,2100,1206,1306,1188,2144,1188,2144,1188,472,1206,464,2028,472,2020,492

you don't appear to specify a size for the array

uint16_t rawcommand[]={};

if you make assignments to array elements you will be overwriting memory which leads to unpredictable behaviour

horace:
you don't appear to specify a size for the array

uint16_t rawcommand[]={};

if you make assignments to array elements you will be overwriting memory which leads to unpredictable behaviour

But, how can i put the size value in a global variable(array)?
irsend function works only with global variables.

Thanks!

It works, when i put a static value, i hope this is enough.

uint16_t rawcommand[100]={};

Can i unset the array or trunk after the loop?

Zolee:
Thanks!

It works, when i put a static value, i hope this is enough.

uint16_t rawcommand[100]={};

it needs to be of sufficient size to store your largest data set
you can always put in a check, e.g. assuming the array has 100 elements and i is the index to the array

if(i>99)
  { Serial.println("array overflow!"); i =99; }

the advantage of C#, Java, etc is that array overflow checking is built in
however, there is an overhead at run time

Zolee:
Can i unset the array or trunk after the loop?

no it is a static array of fixed size
you can dynamically allocate arrays
C dynamic arrays
C++ dynamic arrays

however, unless you know what you are doing avoid such techniques when programming microcontrollers
the overheads can cost more than the saving

assuming the array has 100 elements and i is the index to the array

if(x>99)

{ Serial.println("array overflow!"); i =99; }

Just out of curiosity, if i is the index, why do you compare x to 99?

PaulS:
Just out of curiosity, if i is the index, why do you compare x to 99?

typo! it should read

if(i>99)
  { Serial.println("array overflow!"); i =99; }

also fixed original!
when writing documentation, tutorials, etc I always said run code, no matter how small, thru a compiler! otherwise it will have faults

when writing documentation, tutorials, etc I always said run code, no matter how small, thru a compiler! otherwise it will have faults

But, you don't practice what you preach? 8)

I don't either.