Re: [souliss] Alarm system with automatic and Souliss mode

156 views
Skip to first unread message
Message has been deleted

Di Maio, Dario

unread,
May 4, 2016, 2:47:24 PM5/4/16
to sou...@googlegroups.com

Hi Adrian,

use mInput(slot)=...; to set an input to a Logic (typical) of Souliss, you can find in the wiki the input values to use in order to arm and disable the alarm logic.

Let me know,
Dario.

From Mobile.

On 3 May 2016 16:17, "Adrián Sanz Rodrigo" <adriansa...@gmail.com> wrote:
Dear friends,

I've just programmed a new alarm system with Arduino which inlcudes a keyboard, a LCD 20X4, a buzzer and PIR sensor. This works fine in automatic mode (without Soulis) but now I want to introduce Souliss to my system. So all I want to do is that my alarm system works in both modes: If I introduce the PIN and activate the alarm, in the app has to be shown the alarm is activated, and the same if motion is detected..etc. Of course the same working in the reverse process( If I activate the alarm in the app, it is also shown in the LCD display).

I set the condition to be activated in automatic mode as ""PIN well introduced"", so if I activate the alarm from Souliss should be in that step (due to is mpossible to set a PIN security in Souliss app) and if motion is detected by pir sensor the buzzer will sound, notifying me in my mobile phone. With the next code I'll show you I only get the notification if I previously activated the alarm in automatic mode typing the PIN and also activating it in application, but I cant see the changes at real time between the 2 modes (if i activate by enetring the PIN isn't shown inthe app that alarm is activated) so..How would it be? Thank you very much.

#include "SoulissFramework.h"
#include "bconf/StandardArduino.h"          
#include "conf/ethW5100.h"                 
#include "conf/Gateway.h"                   
#include "EEPROM.h"
#include "conf/IPBroadcast.h"
#include <SPI.h>
#include "Souliss.h"

//SLOTS
#define ALARMA 0
#define SENSOR 1

//PINES
#define PirSensor 2
#define buzzer 11
#define ledrojo 13
#define ledverde 12

// Direccion IP fija del Gateway
uint8_t ip_address[4]  = {192, 168, 1, 77};

uint8_t subnet_mask[4] = {255, 255, 255, 0};

uint8_t ip_gateway[4]  = {192, 168, 1, 1};

#define Gateway_address 0x6501                                                        
#define Peer_address    0x6502

#define myvNet_address  ip_address[3]      
#define myvNet_subnet   0xFF00
#define myvNet_supern   Gateway_address


#include <Password.h> 
#include <Keypad.h> 
#include <LiquidCrystal_I2C.h> 
#include <Wire.h>
 
Password password = Password("1234"); 
byte dlugosc = 4;                      
int alarmActive = 0;
LiquidCrystal_I2C lcd(0x27,20,4); 

int alarmStatus = 0;
byte ilosc; 
const byte ROWS = 4; 
const byte COLS = 4; 

char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {
  9, 8, 7, 6};    
byte colPins[COLS] = {
  5, 4, 3, 2};    
 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
 
void setup()
{
  Serial.begin(9600);


  Initialize();

    GetIPAddress();  
   
    Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);    
    SetAsGateway(myvNet_address);                                  
    Souliss_SetAddress(Gateway_address, myvNet_subnet, myvNet_supern);    
    SetAsPeerNode(Peer_address, 1); 

    Set_Antitheft_Main(ALARMA);    // Slot para el sistema de alarma
  Set_DigitalInput(SENSOR);         
 
 pinMode (ledrojo, OUTPUT);
 pinMode (ledverde, OUTPUT);
 pinMode (buzzer, OUTPUT);
pinMode(PirSensor, INPUT_PULLUP);

  keypad.addEventListener(keypadEvent);  

  digitalWrite(ledrojo, HIGH);
  digitalWrite(ledverde, LOW);
  
   lcd.init();
  lcd.begin(20, 4);
   lcd.backlight();
lcd.setCursor(0,0);
  lcd.print("Enter PIN:");
  lcd.setCursor(0,2);
  lcd.print("Welcome to DomoSanz");
  lcd.setCursor(0,3);
  lcd.print("By Adrian Sanz");
}
 
void loop()
{
  
EXECUTEFAST()
  {
    UPDATEFAST();
      
    FAST_510ms()
    {
      LowDigIn(PirSensor, Souliss_T4n_Alarm, ALARMA); // Lee la entrada del PIR SENSOR, si pasa de 1 a cero activa el slot Alarma
      Logic_Antitheft_Main(ALARMA);            // Activa/Desactiva la alarma y verifica el estado de la misma
      nDigOut(ledverde, Souliss_T4n_Antitheft, ALARMA);    // Enciende/Apaga LEDverde si la alarma está activada/desactivada       
      nDigOut(alarmActivSouliss_T4n_Antitheft, ALARMA); 
      DigIn2State(SENSOR,Souliss_T1n_OnCmd, Souliss_T1n_OffCmd,PirSensor);
      Logic_DigitalInput(PirSensor);
      

    } 
    FAST_210ms() 
    {
     LowDigIn(PirSensor,Souliss_T13, SENSOR); 
    
    }
FAST_GatewayComms();
  }

  if (Logic_Antitheft_Main(ALARMA)) {
    alarmActive == 1;
  }

  
  keypad.getKey();

//Condition to buzzer sound :Function "alarmActive==1 + motion detected by PIR Sensor)

   if (alarmActive == 1){ 
    if (digitalRead(PirSensor) == HIGH)
    {
      alarmTriggered(); 

//souliss

      LowDigIn(PirSensor, Souliss_T4n_Alarm, ALARMA); // read PIR SENSOR input,if goes from 1 to 0 activates Alarm slot
      Logic_Antitheft_Main(ALARMA);            // Activate/dectivatethe alarm and verifies its state
      nDigOut(ledverde, Souliss_T4n_Antitheft, ALARMA);    // Turn on/off Green led if alarm is activated/deactivated
      nDigOut(buzzer, Souliss_T4n_Antitheft, ALARMA);  
      
      DigIn2State(SENSOR,Souliss_T1n_OnCmd, Souliss_T1n_OffCmd,PirSensor);
      Logic_DigitalInput(PirSensor);

      
    }
   }
}

//FUNCTIONS

void displayCodeEntryScreen()    
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Enter PIN:");
  lcd.setCursor(0,2);
  lcd.print("Welcome to DomoSanz");
  lcd.setCursor(0,3);
  lcd.print("By Adrian Sanz");
}

void keypadEvent(KeypadEvent eKey)
{
  switch (keypad.getState())
  {
    case PRESSED:
   
   int i;
for( i = 1; i <= 1; i++ )
{
  digitalWrite(buzzer, HIGH);  
            
  digitalWrite(buzzer, LOW);  
     
}    
 
switch (eKey)
{

default:
ilosc=ilosc+1;
password.append(eKey);
}
 
if(ilosc == 1)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("*_");
}
if(ilosc == 2)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("**_");
}
if(ilosc == 3)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("***_");
}
if(ilosc == 4)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("****_");
}
if(ilosc == 5)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("*****_");
}
if(ilosc == 6)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("******_");
}
if(ilosc == 7)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("*******_");
}
if(ilosc == 8)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("   < PIN >");
lcd.setCursor(0,1);
lcd.print("********");
}
 
if(ilosc == dlugosc)
{
delay(250);
checkPassword();
ilosc = 0;
}
}

}

void activate()   
{
 lcd.setCursor(0,1);
    lcd.print("ACTIVATING IN 5....."); 
    delay(1000);
    lcd.setCursor(0,1);
    
    lcd.print("ACTIVATING IN 4....."); 
    delay(1000);
    lcd.setCursor(0,1);
    
     lcd.print("ACTIVATING IN 3....."); 
    delay(1000);
    lcd.setCursor(0,1);
    
    lcd.print("ACTIVATING IN 2....."); 
    delay(1000);
    lcd.setCursor(0,1);
    
    lcd.print("ACTIVATING IN 1....."); 
    
    lcd.clear();
   digitalWrite(ledrojo, LOW);
    digitalWrite(ledverde, HIGH);
    lcd.setCursor(0,2);
    lcd.print("**ALARM ACTIVATED**"); 
    alarmActive = 1;
  
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("_-SYSTEM ACTIVE-_");
  lcd.setCursor(0,3);
  lcd.print("DomoSanz");
    password.reset();
   
  }
  
  void deactivate()
{
  alarmStatus = 0;
 digitalWrite(ledrojo, HIGH);
    digitalWrite(ledverde, LOW);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("ALARM DISABLED!");
  digitalWrite(sirena, LOW);
  alarmActive = 0;
  password.reset();
 


  displayCodeEntryScreen();
}

void invalidCode()    
{
  password.reset();
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("INVALID CODE!");
  lcd.setCursor(0,3);
  lcd.print("TRY AGAIN!");
 
  displayCodeEntryScreen();
}

void invalidCode2()    
{
  digitalWrite(sirena, HIGH);
  password.reset();
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("INVALID CODE!");
  lcd.setCursor(0,2);
  lcd.print("TRY AGAIN TO");
  lcd.setCursor(0,3);
  lcd.print("TURN ALARM OFF");
 
}

void alarmTriggered(){
 
  digitalWrite(buzzer, HIGH);
 
  password.reset();
  alarmStatus = 1;
  // alarmActive = 0;
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("MOTION DETECTED!");
  lcd.setCursor(0,2);
  lcd.print("Calling to");
   lcd.setCursor(0,3);
  lcd.print("HomeOwners");
  

}   

void checkPassword()
{
  if (password.evaluate())
  {
   int i;
      for( i = 1; i <= 3; i++ )
      {
      digitalWrite(buzzer, HIGH);  
      delay(120);            
      digitalWrite(buzzer, LOW);  
      delay(70);      
       }    
    ilosc = 0;
    password.reset();
 
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("<<CORRECT PIN>>");
    lcd.clear();
 if(alarmActive == 0 && alarmStatus == 0)
    {
      activate();
    } 
    else if( alarmActive == 1 || alarmStatus == 1) {
      deactivate();
    }
 
  }  
  else  
  {
 
if(alarmActive == 0 && alarmStatus == 0){
 
     invalidCode();
  }
  else if(alarmActive == 1 || alarmStatus == 1) {
      invalidCode2();
    }
      
  }

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/3e8ec052-6f5b-4a52-aec3-5c91c27dcc4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Di Maio, Dario

unread,
May 6, 2016, 1:24:28 AM5/6/16
to sou...@googlegroups.com

Likely your code is faster than your fingers :) and you enter in the digRead if more than once.

Use DigIn of Souliss instead of digRead and it will work.

Dario.

From Mobile.

On 5 May 2016 09:22, "Adrián Sanz Rodrigo" <adriansa...@gmail.com> wrote:
Thanks Dario, I just finished that step correctly, I'll post later the results. But now my final step is to place a pushbotton that with one press turns off the LCD screen and with another one turns on the screen(of course as a toggle switch). I know the commands to use are lcd.backlight() and lcd.nobacklight() and I got a small code to make it with the pushbutton, but when I introduce the code in void loop() is always turning on/off the screen each time souliss updates (each 0.5s) and is impossible for me to find a solution because I want that this option works independently of Souliss.. Other option is to use a time with the screen on and then itself turns off... Here's the code:

int Button = 0; //This is the default "Button Off" and 1 is "Button On"
int OldButton = 0;



void setup(){

pinMode(33, INPUT);
}

void loop () {

if(digitalRead(33) == HIGH) { //If Pin 2 is high (At 5 Volts)
   Button = 1 - Button; //If Button is set as 0 then Button = 1 - 0 (=1) and if Button is 1 then Button=1 - 1 (=0)
 }
 
 if(Button == 1 && OldButton == 0) { //If Button is 1 and OldButton is 0 (This means basically means "If the button was just pressed"
     lcd.backlight();
    delay(500); //Delay for half a second
 }
 
 if(Button == 0 && OldButton == 1) {
   lcd.noBacklight();
   delay(500); //Delay for half a second
 }
OldButton = Button; //The data is now old

}




--
You received this message because you are subscribed to a topic in the Google Groups "souliss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/souliss/ADovlq_q2-w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to souliss+u...@googlegroups.com.

To post to this group, send email to sou...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+u...@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages