15-03-2020, 16:14
Cześć, trochę poprawiłem kod i usunąłem większość delay()
Ale nadal nie mam pomysłu jak ogarnąć załączanie alarmu i jednoczesne odbieranie smsów.
Musze pokombinować i jakoś ułożyć to sobie w głowie
Powoli małymi krokami
Ale nadal nie mam pomysłu jak ogarnąć załączanie alarmu i jednoczesne odbieranie smsów.
Musze pokombinować i jakoś ułożyć to sobie w głowie
Powoli małymi krokami
Kod:
#include <GSM.h>
GSM gsmAccess;
GSM_SMS sms;
char remoteNumber[20]; // Holds the emitting number
char phone[20] = "XXXXXXXXX";
String txtMsg = "";
void setup()
{
Serial.begin(9600);
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin()==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
smsSend(phone,"START SYSTEMU");
}
void loop()
{
char c;
// If there are any SMSs available()
if (sms.available())
{
// Get remote number
sms.remoteNumber(remoteNumber, 20);
Serial.println(remoteNumber);
// This is just an example of message disposal
// Messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
// Read message bytes and print them
while(c=sms.read())
txtMsg += c;
Serial.println(txtMsg);
// delete message from modem memory
sms.flush();
}
delay(1000);
}
void smsSend(char phone[20], String message)
{
// send the message
sms.beginSMS(phone);
sms.print(message);
sms.endSMS();
}