/***********************************************************************************************Author: Ngoc KhuuTac gia: Khuu Xuan NgocChỉnh sửa: Nguyễn Nguyệt PhươngMo ta: Dung dien thoai gui tin SMS voi noi dung phu hop voi tu khoa trong mang KeyWordON[x] de bat thiet bi x (Relay_pin[x]) hoac trong mang KeyWordOF[x] de tat thiet bi x (Relay_pin[x]).Decription: If SMS has content that match array KeyWordON or KeyWordOF, it will turn on or turn off relay.******
IMPORTAIN: - Make sure UPLOAD sketch "FirstUpLoad" first (Only 1 time), then run this sketch!********  - Replace delay [origin] by *.delay [example: HGSM.delay(1000)]
Tutorial:********
Code download:  https://github.com/Khuuxuanngoc/Hshopvn_GSMLink product:   http://hshop.vn/products/mach-gsmsim800ds-toch-hop-nguon-va-ic-dem
P/s: Remember SET country code if NOT in VietNam***********************************************************************************************/#include "SoftwareSerial.h"#include "Hshopvn_GSM.h"

SoftwareSerial sim800ds(2, 3);HshopGSM HGSM = HshopGSM(&sim800ds);
// Declare pin of relays:unsigned char Relay_pin[2] = {5,6};unsigned char Relay_active = 1; // 1 mean OFF or 0 volt, 0 mean ON or 5 volt. The Relay is active when LOW (0)String KeyWordPush[2] = {"dong", "cat"}, adminuser="84913909190", user1="84913332344";bool passOK = false, isadmin=false, isuser1=false;



void setup() {  // put your setup code here, to run once:  // Relay init:1  //Only show monitor  Serial.begin(9600);  Serial.println("Start!!");
  // Init Country code default: VietNam (+84)  HGSM.init(&GSM_Ready, 9600);}



void loop() {  // put your main code here, to run repeatedly:  HGSM.handle();}


void GSM_Ready() {  if (HGSM.getDataGSM() != "")   {    Serial.println(HGSM.getDataGSM());  //show data comming    if(HGSM.checkData(adminuser)) isadmin=true ; else if(HGSM.checkData(user1)) isuser1=true;else;
    if(isadmin or isuser1)      {      passOK = true;      Serial.println("You are authorized person");      } else;          for (unsigned char count_for = 0; count_for < 2; count_for++)       {      if (passOK && HGSM.checkData(KeyWordPush[count_for])) //// if Key word (PUSH) match        {             pinMode(Relay_pin[count_for], OUTPUT);        digitalWrite(Relay_pin[count_for], !Relay_active);    // Turn on relay        delay(1000);        digitalWrite(Relay_pin[count_for], Relay_active);    // Turn on relay        Serial.println("I have pushed relay: " + KeyWordPush[count_for+1]);
        if (isadmin=true)          {            HGSM.sendsms(adminuser,"I have pushed: "+ KeyWordPush[count_for+1]);           isadmin=false;           passOK = false;          } else if (isuser1=true)            {            HGSM.sendsms(adminuser,"I have pushed: "+ KeyWordPush[count_for+1]);             HGSM.sendsms(user1,"I have pushed: "+ KeyWordPush[count_for+1]);             isuser1=false;            passOK = false;            } else;                   } else;      }    } else;