• 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)
#1
Witam, czy mogę prosić o podpowiedź jak zmodyfikować poniższy kod, żeby konkretny sms np o treści ALARM powodował załączenie się przekaźnika na danym pinie? Chodzi mi o to jak te pojedyncze znaki w zmiennej char c wykorzystać w ifie do porównania z jakimś konkretnym wyrazem - zapewne po wyrażeniu (c = sms.read()). Jakoś nie potrafię sam wymyśleć jak zrobić tablicę, która by ściągała dane z sms.read() i  potem program porównujący znaki w tej tablizy z konkretnym wyrazem np. ALARM)


Kod:
// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];

void setup() {
 // initialize serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }

 Serial.println("SMS Messages Receiver");

 // connection state
 boolean notConnected = true;

 // Start GSM connection
 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");
}

void loop() {
 char c;

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

   // Get remote number
   sms.remoteNumber(senderNumber, 20);
   Serial.println(senderNumber);

   // An example of message disposal
   // Any 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()) {
     Serial.print(c);
   }

   Serial.println("\nEND OF MESSAGE");

   // Delete message from modem memory
   sms.flush();
   Serial.println("MESSAGE DELETED");
 }

 delay(1000);

}
 
Odpowiedź
  


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

Skocz do:


Przeglądający: 1 gości