Witam. Mam zrobiony układ alarmujący sms-em pojawienie się wody w pomieszczeniu. Mam kartę PLAY za 5 zł na rok jest tylko warunek że trzeba zadzwonić lub wysłać smsa choć jednego w miesiącu. Nie wiem jak to rozwiązać aby wysłał smsa testowego raz w miesiącu bo jak wystąpi zalanie lub jak układ startuje to już mam. Nie chciałbym dodawać jakiegoś układu czasowego. Pozdrawiam wszystkich i czekam na pomoc.
A znalazłem coś takiego ale nie mam pojęcia jak można to przerobić aby nie ustawiało czasu w 1307 tylko właśnie odliczało i wysyłało smsa.
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int day,month,year,minute,second,hour;
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void setup(){
Serial.begin(9600); // only for debug the results .
Sim800l.begin(); // initializate the library.
// the parameter to send is UTC of your country
Sim800l.updateRtc(); //
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
}
void loop(){
Sim800l.RTCtime(&day,&month,&year,&hour,&minute,&second);
//at this moment the variables have the real time.
// Serial.print(day);
// Serial.print('/');
// Serial.print(month);
// Serial.print('/');
// Serial.print(year);
// Serial.print(' ');
// Serial.print(hour);
// Serial.print(':');
// Serial.print(minute);
// Serial.print(':');
// Serial.print(second);
// Serial.println();
byte monthday=day;
Wire.beginTransmission(0x68);
Wire.write(0x00); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(day));
Wire.write(decToBcd(monthday));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(0x00); //start
Wire.endTransmission();
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
=========================================================================
A to program który wysyła smsa o zalaniu:
:
#include <BareBoneSim800.h>
BareBoneSim800 sim800; //
//BareBoneSim800 sim800("your APN"); //needed for gprs funtionality
int koniec = 0;
void setup() {
Serial.begin(9600);
sim800.begin();
while(!Serial);
pinMode(5, INPUT);
Serial.println("Test GSM modul SMS ");
delay(8000);
Serial.println("Should be ready by now");
bool deviceAttached = sim800.isAttached();
if (deviceAttached)
Serial.println("Device is Attached");
else
Serial.println("Not Attached");
const char* number = "+48xxxxxxxxx";
// char* message = "UWAGA!!! WODA!!! w lazience !!!!.";
char* message2 = "GSM dziala poprawnie. SMS testowy";
delay(2000);
bool messageSent = sim800.sendSMS(number, message2);
if(messageSent)
Serial.println("Message Sent");
else
Serial.println("Not Sent, Something happened");
}
void loop() {
if ((digitalRead(5) == LOW)&&(koniec == 0)) { //Jeśli sygnał z czujnika wody
bool messageSent = sim800.sendSMS("+48xxxxxxxxx","UWAGA!!! WODA w lazience. Szybko sprawdz.");
// bool messageSent = sim800.sendSMS(number, message2);
if((messageSent)&&(koniec==0))
koniec = 1;
else
Serial.println("Not Sent, Something happened");
}
if (digitalRead(5) == HIGH) {
koniec = 0;
}
delay(8000);
}
A znalazłem coś takiego ale nie mam pojęcia jak można to przerobić aby nie ustawiało czasu w 1307 tylko właśnie odliczało i wysyłało smsa.
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int day,month,year,minute,second,hour;
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void setup(){
Serial.begin(9600); // only for debug the results .
Sim800l.begin(); // initializate the library.
// the parameter to send is UTC of your country
Sim800l.updateRtc(); //
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
}
void loop(){
Sim800l.RTCtime(&day,&month,&year,&hour,&minute,&second);
//at this moment the variables have the real time.
// Serial.print(day);
// Serial.print('/');
// Serial.print(month);
// Serial.print('/');
// Serial.print(year);
// Serial.print(' ');
// Serial.print(hour);
// Serial.print(':');
// Serial.print(minute);
// Serial.print(':');
// Serial.print(second);
// Serial.println();
byte monthday=day;
Wire.beginTransmission(0x68);
Wire.write(0x00); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(day));
Wire.write(decToBcd(monthday));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(0x00); //start
Wire.endTransmission();
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
=========================================================================
A to program który wysyła smsa o zalaniu:
:
#include <BareBoneSim800.h>
BareBoneSim800 sim800; //
//BareBoneSim800 sim800("your APN"); //needed for gprs funtionality
int koniec = 0;
void setup() {
Serial.begin(9600);
sim800.begin();
while(!Serial);
pinMode(5, INPUT);
Serial.println("Test GSM modul SMS ");
delay(8000);
Serial.println("Should be ready by now");
bool deviceAttached = sim800.isAttached();
if (deviceAttached)
Serial.println("Device is Attached");
else
Serial.println("Not Attached");
const char* number = "+48xxxxxxxxx";
// char* message = "UWAGA!!! WODA!!! w lazience !!!!.";
char* message2 = "GSM dziala poprawnie. SMS testowy";
delay(2000);
bool messageSent = sim800.sendSMS(number, message2);
if(messageSent)
Serial.println("Message Sent");
else
Serial.println("Not Sent, Something happened");
}
void loop() {
if ((digitalRead(5) == LOW)&&(koniec == 0)) { //Jeśli sygnał z czujnika wody
bool messageSent = sim800.sendSMS("+48xxxxxxxxx","UWAGA!!! WODA w lazience. Szybko sprawdz.");
// bool messageSent = sim800.sendSMS(number, message2);
if((messageSent)&&(koniec==0))
koniec = 1;
else
Serial.println("Not Sent, Something happened");
}
if (digitalRead(5) == HIGH) {
koniec = 0;
}
delay(8000);
}