Hello,
my script with which I want to connect my Sim 800l with the gsm always stops by it self.Did someone know wy it do this?
#include <SoftwareSerial.h>
#define SIM800_TX 8
#define SIM800_RX 9
SoftwareSerial mySerial(SIM800_TX, SIM800_RX);
int start = 0;
int zustand = 0;
int error_z = 0;
unsigned long Millis;
unsigned long Intervall;
enum ZKom : byte { SENDEN, EMPFANGEN };
ZKom zustandKom = SENDEN;
#define ZEILENTRENNZEICHEN 13
char* receiveBuffer() {
static char lineBuffer[40];
static byte counter = 0;
char c;
if (mySerial.available() == 0) return NULL;
if (counter == 0) memset(lineBuffer, 0, sizeof(lineBuffer));
c = mySerial.read();
if (c == ZEILENTRENNZEICHEN)
{
counter = 0;
return lineBuffer;
}
else if (c >= 32)
{
lineBuffer[counter] = c;
if (counter < sizeof(lineBuffer) - 2) counter++;
}
return NULL;
}
void setup() {
Serial.begin(9600);
while (!Serial);
mySerial.begin(9600);
while (!mySerial);
Serial.println("Bereit");
}
void loop() {
if (zustandKom == SENDEN) {
if (start == 0) {
zustand = Serial.read();
if (zustand > 48 ) {
start = 1;
Serial.println(zustand);
}
}
switch (zustand) {
case 49:
Serial.println("Case 1");
while (!mySerial);
mySerial.println("AT");
zustand = 50;
zustandKom = EMPFANGEN;
break;
case 50:
Serial.println("Case 2");
while (!mySerial);
mySerial.println("AT+SAPBR=3,1,Contype,GPRS");
zustand = 51;
zustandKom = EMPFANGEN;
break;
case 51:
Serial.println("Case 3");
while (!mySerial);
mySerial.println("AT+SAPBR=3,1,APN,web.vodafone.de");
zustand = 52;
zustandKom = EMPFANGEN;
break;
case 52:
Serial.println("Case 4");
while (!mySerial);
mySerial.println("AT+SAPBR=3,1,USER,vodafone");
zustand = 53;
zustandKom = EMPFANGEN;
break;
case 53:
Serial.println("Case 5");
while (!mySerial);
mySerial.println("AT+SAPBR=3,1,PWD,vodafone");
zustand = 54;
zustandKom = EMPFANGEN;
break;
case 54:
Serial.println("Case 6");
while (!mySerial);
mySerial.println("AT+SAPBR=1,1");
zustand = 55;
zustandKom = EMPFANGEN;
break;
case 55:
Serial.println("Case 7");
while (!mySerial);
mySerial.println("AT+SAPBR=2,1");
zustand = 56;
zustandKom = EMPFANGEN;
break;
case 56:
Serial.println("Verbindung fertig");
start = 0;
break;
}
}
if (zustandKom == EMPFANGEN) {
char* text = receiveBuffer();
if (text != NULL) {
if (strcmp(text, "OK") == 0 ) {
Serial.println(text);
delay(1000);
zustandKom = SENDEN;
} else if (strcmp(text, "ERROR") == 0 ) {
Serial.println(text);
error_z++;
//Serial.println(error_z);
if (error_z <= 2) {
zustand--;
zustandKom = SENDEN;
} else {
}
} else {
Serial.println(text);
}
}
}
}
Sorry for my english it was very bad, but i try to was better.