Hello everyone,
I’m trying to make class method which operates on arrays (one is array of int, another char). Unfortunatelly I’m getting several errors/warnings
as an output from compiler. Can someone help ? I’m mainli asking about errors: " invalid types ‘int[int]’ for array subscript"
Thanks in advance
compiler output:
In function 'void loop()':
warning: invalid conversion from 'int (*)[10]' to 'int' [-fpermissive]
handleClient.parseRequest(incomming,&conParameters,&netParameters);
^
sketch\handleClient.h:17:10: note: initializing argument 2 of 'void handleClient::parseRequest(char*, int, char)'
void parseRequest(char parametersArray[], int connectionParameters, char networkParameters);
^
warning: invalid conversion from 'char (*)[2]' to 'char' [-fpermissive]
handleClient.parseRequest(incomming,&conParameters,&netParameters);
^
sketch\handleClient.h:17:10: note: initializing argument 3 of 'void handleClient::parseRequest(char*, int, char)'
void parseRequest(char parametersArray[], int connectionParameters, char networkParameters);
^
sketch\handleClient.cpp: In member function 'void handleClient::parseRequest(char*, int, char)':
handleClient.cpp:71: error: invalid types 'int[int]' for array subscript
connectionParameters[conParArrayIndex]=atoi(command);
^
handleClient.cpp:76: error: invalid types 'int[int]' for array subscript
connectionParameters[conParArrayIndex]=atoi(input);
^
handleClient.cpp:79: error: invalid types 'char[int]' for array subscript
networkParameters[conParArrayIndex]=input;
^
exit status 1
invalid types 'int[int]' for array subscript
main.ino (snipped)
#include "handleClient.h"
#define NUMBER_OF_INCOMMING 115
char incomming[NUMBER_OF_INCOMMING];
int conParameters[10];
char netParameters[2];
if(!handleClient.isSubmitted()){
WiFiEspClient client = server.available(); // listen for incoming clients
if (client) {
int index=0;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if(index<numberOfIncomming){
incomming[index]=c;
index++;
}
if (c=="\n") {
handleClient.parseRequest(incomming,&conParameters,&netParameters);
break;
}
}
}
}
}
handleClient.h
#include "Arduino.h"
class handleClient
{
public:
handleClient();
bool isSubmitted();
void parseRequest(char parametersArray[], int connectionParameters, char networkParameters);
private:
bool _submitted=false;
};
handleClient.cpp
#include "Arduino.h"
#include "handleClient.h"
handleClient::handleClient()
{
}
bool handleClient::isSubmitted(){
return _submitted;
}
void handleClient::parseRequest(char parametersArray[], int connectionParameters, char networkParameters){
char *input = parametersArray;
String parameters[6]; //only 6 params can be injected to client
char *token,*token2,*token3,*token4,*saved1,*saved2,*saved3,*saved4;
token = strtok_r(input, "?",&saved1);
while (token != NULL) {
token2=strtok_r(token," ",&saved2);
if(token2!=NULL){
while(token2!=NULL){
if(strcmp("/submit",token2)==0)
_submitted=true;
token3=strtok_r(token2,"&",&saved3);
while(token3!=NULL){
if(strstr(token3,"selfIp")!=NULL)
parameters[0]=token3;
if(strstr(token3,"selfPort")!=NULL)
parameters[1]=token3;
if(strstr(token3,"hubIp")!=NULL)
parameters[2]=token3;
if(strstr(token3,"hubPort")!=NULL)
parameters[3]=token3;
if(strstr(token3,"newSsid")!=NULL)
parameters[4]=token3;
if(strstr(token3,"newPass")!=NULL)
parameters[5]=token4;
token3=strtok_r(NULL,"&",&saved3);
}
token2=strtok_r(NULL," ",&saved2);
}
}
token = strtok_r(NULL,"?",&saved1);
}
if(_submitted){
int conParArrayIndex=0;
for(int i=0;i<6;i++){
int len=(parameters[i].substring(parameters[i].indexOf("=")+1).length())+1;
String par=parameters[i].substring(parameters[i].indexOf("=")+1);
char input[len];
par.toCharArray(input,len);
if(i==0 || i==2){ //self IP || hubIP
char* command = strtok(input, ".");
while (command != NULL){
connectionParameters[conParArrayIndex]=atoi(command);
conParArrayIndex++;
command = strtok(NULL, ".");
}
}else if(i==1 || i==3){//selfPort || hubPort
connectionParameters[conParArrayIndex]=atoi(input);
conParArrayIndex++;
}else if(i==4 || i==5){ //ssid || pass
networkParameters[conParArrayIndex]=input;
conParArrayIndex++;
}
}
}
}