Hey everybody.
Im struggeling with some problems.
I am doing this seup as in the guide: https://create.arduino.cc/projecthub/Arduino_Genuino/control-two-relays-with-an-sms-7c0eb2 Of course everything OK so far.
To trig or change the relays the function are in an ascii number. I want to trig by a word instead. but it seems as i am missing something course my trigger word (snow) in these case wont trig relay 1.
So far my new code is: Any suggestions ?
#include "arduino_secrets.h"
#include <MKRGSM.h>
GSM gsmAccess;
GSM_SMS sms;
char PINNUMBER [] = SECRET_PINNUMBER;
String sender = SECRET_YOUR_NUMBER;
String KeyWord = "snow";
unsigned long Time_Relay_On = 3000; //in milliseconds
char senderNumber[20];
const int Relay_One = 2; //Relay 1 connected to Pin 2
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
bool connected = false;
// Start GSM connection
while (!connected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
pinMode(1,OUTPUT);
pinMode(0,OUTPUT);
}
void loop()
{
String c;
String texmsg = "";
// If there are any SMSs available()
if (sms.available()) {
Serial.println("Message received from: ");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
if (String(senderNumber) == sender) {
// An example of message disposal
// Any messages starting with # should be discarded
if (sms.peek() == '#') {
Serial.println("Discarded SMS");
sms.flush();
}
//read the first char of the message text to witch the respective relays on the shielkd
texmsg = sms.read();
if(texmsg == KeyWord){
digitalWrite(Relay_One, HIGH);
delay(Time_Relay_On);
}
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
} else {
sms.flush();
Serial.println("MESSAGE DELETED");
}
}
delay(1000);
}
Thanks a lot.