• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Sterowanie przekaźnikiem za pomocą SMS (Arduino UNO + moduł GSM)
#4
Witam, prawie mi się udało, problem jest taki, że działa tylko 2 razy po wgraniu programu do Arduino - to znaczy jednym sms mogą włączyć diodę a drugim wyłączyć. Ale wygaszenie diody i kolejne wysłanie smsa o treści "on" już nie powoduje załączenia się diody. Co robię nie tak?

Kod:
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

char remoteNumber[20];  // Holds the emitting number
char smsData[80]; //tablica do przechowania smsa
byte smsIndex = 0; //Then, you create an index into the array
char c;

void setup()
{
 // initialize serial communications
 Serial.begin(9600);

 Serial.println("SMS Messages Receiver");

 // 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(PINNUMBER)==GSM_READY)
     notConnected = false;
   else
   {
     Serial.println("Not connected");
     delay(1000);
   }
 }

 Serial.println("GSM initialized");
 Serial.println("Waiting for messages");

pinMode(13,OUTPUT);
digitalWrite (13, LOW);
 
}

void loop()
{
 // If there are any SMSs available()  
 if (sms.available())
 {
   Serial.println("Message received from:");

   // 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. Read and (effectively) throw away all but the last character from the message.
   while(c=sms.read())
   {
   smsData[smsIndex++] = c;}
        smsIndex = 0;
   //-Serial.println("\nEND OF MESSAGE");
   // delete message from modem memory
   sms.flush();
   Serial.println("MESSAGE DELETED");
if (strcmp(smsData, "on") == 0)
{Serial.println("OKAY");
digitalWrite (13, HIGH);
}
else
{Serial.println("NO");
digitalWrite (13, LOW);
}
 delay(1000);

 }}
 
Odpowiedź
  


Wiadomości w tym wątku
RE: Sterowanie przekaźnikiem za pomocą SMS (Arduino UNO + moduł GSM) - przez MarJanPol - 03-02-2018, 13:37

Skocz do:


Przeglądający: 1 gości