Hallo Leute,
ich bastel gerade an einem Melder. Die Kommunikation zwischen dem Arduino und des SIM800L-Modules laufen über SoftwareSerial und AT-Command. Ich habe nun folgendes Problem: Bei Senden der SMS wird die Nachricht nur Teiweise übermittelt. Wenn ich die AT-Commands einzeln und "manuell" einegebe funktioniert es, jedoch mit weiterm Code tritt immer dieseer Fehler auf.
(RTC is NOT running! --> habe ich zurzeit nicht angeschlossen)
Serieller Monitor:
RTC is NOT running!
Alarmmeldung wurde abgesetzt!
AT
OK
AT+CMGF=1
OK
AT+CMGS="+4915232709044"
abcdefghij
ERROR
Arduino Code:
//RTC
#include "RTClib.h"
RTC_DS1307 rtc;
//SIM800l
#include <SoftwareSerial.h>
//SIM800 TX to Arduino D8
#define SIM800_TX_PIN 8
//SIM800 RX to Arduino D7
#define SIM800_RX_PIN 7
SoftwareSerial sim800l(SIM800_TX_PIN, SIM800_RX_PIN);
//Integer
int WeckzeitStd = 8;
int WeckzeitMin = 00;
int i = 0;
//Stings
String Zustand = "Zu";
String MeldungAbgesetzt = "Nein";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// put your setup code here, to run once:
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(19200);
while(!Serial);
//Being serial communication witj Arduino and SIM800
sim800l.begin(19200);
while(!sim800l);
//Pin OUTPUT/ INPUT
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);
//pinMode(3, INPUT_PULLUP);
//RTC Überprüfen
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
//SIM800l Überprüfen
// if ( sim800l.available()) {
// Serial.println("Sim800 ist ONLINE");
// }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// put your main code here, to run repeatedly
Watchdog();
TagesMeldung();
//Serieller Monitor
if(sim800l.available()){
Serial.write(sim800l.read());
}
if(Serial.available()){
sim800l.write(Serial.read());
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Watchdog(){
//int Z = digitalRead(2);
if (digitalRead(2) == HIGH && Zustand != "Tuer wurde Geoeffnet" && MeldungAbgesetzt == "Nein"){
Zustand = "Tuer wurde Geoeffnet!";
AlarmMeldung();
//Serial.println("\tAlarmmeldung wurde abgesetzt!");
}
else if (MeldungAbgesetzt == "Ja")
{
}
else
{
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void AlarmMeldung(){
sim800l.println("AT\n");
delay(50);
//Set SMS Mode
sim800l.println("AT+CMGF=1\n");
delay(50);
//Send new SMS command and message number
sim800l.print("AT+CMGS=\"+4915232709044\"\n");
delay(50);
//Nachricht
//sim800l.print(Zustand);
sim800l.print("abcdefghijklmnopqrstuvwxyz");
delay(50);
//SMS absenden
sim800l.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
delay(50);
MeldungAbgesetzt = "Ja";
Serial.println("\tAlarmmeldung wurde abgesetzt!");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void TagesMeldung(){
DateTime now = rtc.now();
if (now.hour() == WeckzeitStd && now.minute() == WeckzeitMin && Zustand == "Zu"){
CheckSMS();
if (Serial.available()) {
Serial.println("\tTägliche Meldung abgesetzt.");
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CheckSMS(){
DateTime now = rtc.now();
sim800l.print("AT\n");
delay(200);
//Set SMS Mode
sim800l.print("AT+CMGF=1\n");
delay(200);
//Send new SMS command and message number
sim800l.print("AT+CMGS=\"+4915232709044\"\n");
delay(200);
//Nachricht
sim800l.print(Zustand);
// sim800l.print(", Wurde schon eine Meldung abgesetzt?:");
// sim800l.print(MeldungAbgesetzt);
// sim800l.print(", Ührzeit: ");
// sim800l.print(now.hour(), DEC);
// sim800l.print(':');
// if (now.minute() <= 9)
// sim800l.print("0");
// sim800l.print(now.minute(), DEC);
// sim800l.print(':');
// if (now.second() <= 9)
// sim800l.print("0");
// sim800l.print(now.second(), DEC);
// sim800l.println();
//SMS absenden
sim800l.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
}
Hat jemand eine Idee woran es liegen könnte und kann mir dabei helfen?
LG Motwin