Hallo,
ich habe Probleme beim Empfangen von Daten des SIM808 Moduls.
Wenn ich zuviel Daten von websites abfrage kommen am Ende nicht mehr alle Daten durch.
Meine Funktion momentan sieht folgendermaßen aus:
void sendRead(String command, const int timeout){
char c;
String response1 = "";
sim.println(command);
long int time = millis();
int i = 0;
while( (time+timeout) > millis()){
while(sim.available() > 0){
c = sim.read();
response1+=c;
}
}
Serial.print(response1);
}
Das Problem ist vermutlich
String response1 = ""; welcher irgendwann voll ist und überläuft.
Was ich nun versuche ist folgendes:
#include <SoftwareSerial.h>
SoftwareSerial sim(2, 3); // RX, TX
const byte numChars = 256;
char receivedChars[numChars];
char end_c[1];
void setup()
{
end_c[0]=0x1a;
sim.begin(9600);
Serial.begin(9600);
getData("AT+CCID",1000);
}
void loop()
{
}
void getData(String command,int timeout){
char c;
int ndx = 0;
long int time = millis();
sim.println(command);
while( (time+timeout) > millis()){
while(sim.available() > 0){
c = sim.read();
receivedChars[ndx] = c;
ndx++;
}
}
Serial.println(receivedChars);
}
Hier schreibe ich jedes char welches ich empfange nach receivedChars[].
Beim zweiten Aufruf fange ich wieder beim receivedChars[0] an und überschreibe die alten Daten.
Somit hätte ich keinen überlauf mehr.
Leider hört mein Code nach 15 chars auf.
Kann mir hier bitte jemand weiterhelfen. Vielen Dank schonmal
Schönen Gruß
Bill