i can´t make array of objects(ClassName Objectname[n]) . I first made the class in a .cpp and .h file, worked fine for just one Object, but if i tried du make an array with more than one Object my Core starts blinking red. I also tried to make the class in the normal .ino file, works also with on Object but with more than one object same Problem.
Is this not possible ?
This is definitely possible so I am not sure what is going wrong.
What kind of blinking red LED are you getting? An SOS followed by 8 flashes followed by SOS means that you are out of memory, but there are other codes too. Does your object use a lot of RAM?
thx for reply. Well yeah i am out of memory than. My Code is not the best programming style, this class was made for testing which i wanted to change later …
#define LIB_DOMAIN "***.***.de"
class ES
{
public:
ES();
void wertEinlesen(); //changing later to read values of pins
void postStringErstellen(); //string for post request
void postRequest();
void postResponse(); //check if post was succesfull
void autoPlay();
String poststring;
TCPClient client;
double werte[60];
String postanswer;
String nullString;
};
void ES::wertEinlesen()
{
for(int i = 0; i<60;i++)
{
werte[i] = i;
}
}
void ES::postStringErstellen()
{
poststring.concat(String("status0="));
for(int i = 1;i<60;i++)
{
poststring.concat(werte[i-1]);
poststring.concat(String("&status"));
poststring.concat(("%s",i));
poststring.concat("=");
}
poststring.concat(werte[59]);
Serial.println("Poststringerstellen");
Serial.println(poststring);
}
void ES::postRequest()
{
client.connect(LIB_DOMAIN, 80);
client.println("POST /***/index2.php HTTP/1.1");
client.println("Host: " LIB_DOMAIN);
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(poststring.length());
client.println();
client.println(poststring);
Serial.println("postrequest");
Serial.println(poststring);
poststring=nullString;
}
void ES::postResponse()
{
if (client.available())
{
for(int i = 0;i<15;i++)
{
char c= client.read();
if(i==13||i==14)
{
postanswer.concat(c);
}
}
client.flush();
client.stop();
if(postanswer=="OK")
{
Serial.println("true");
}
else
{
Serial.println("false1");
}
}
else
{
Serial.println("false2");
}
Serial.println("postresponse");
Serial.println(postanswer);
postanswer = nullString;
Serial.println(postanswer);
}
void ES::autoPlay()
{
ES::wertEinlesen();
ES::postStringErstellen();
ES::postRequest();
ES::postResponse();
}
ES::ES(){}
ES test[2]; // ES test works fine as single object
void setup()
{
Serial.begin(9600);
delay(20000);
}
void loop()
{
test[1].autoPlay();
test[2].autoPlay();
delay(20000);
}
Well, i guess i will have to try another way cause i want to use youre RTC lbrary, too
Are you trying to instantiate multiple TCPClient objects? I am not sure that is working yet. Last time I check a few weeks ago, it was not. Can your array of objects all share one TCPClient?
Because you have a pointer to a class for both your String data members and your TCPClient, you need to use the other method syntax, so…
client.connect(LIB_DOMAIN, 80);
should be
client->connect(LIB_DOMAIN, 80);
My RTC library is good, but there is an RTC built into the core-firmware now that you might want to use instead. My library provides nice Arduino strings and daylight savings time but the built-in RTC has everything else. The doc for this is coming soon but you can preview it here: