rasProject_01 / weSweetHome  R. 240
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
homeDoorPhone.c File Reference

Process control program for door bells IP phones etc. More...

#include "arch/config.h"
#include "homeDoor.h"
#include "weUtil.h"
#include "weStateM.h"
#include <getopt.h>
#include "weLockWatch.h"

Functions

void bellsButChg (uint8_t status)
 Reaction to bell button presses. More...
 
void doorOpTimChg (state_t *const me)
 Door opener was activated timer state change. More...
 
void doorUnlckChg (state_t *const me)
 Door opener activation state change. More...
 
int main (int argc, char **argv)
 The program. More...
 
void mlBellButChg (state_t *const me)
 Middle and lower bell state change. More...
 
void mlBellTimChg (state_t *const me)
 Middle and lower bell was rung timer state change. More...
 
void * processIOthread (void *args)
 The task of controlling process IO. More...
 
void resOpCoupChg (state_t *const me)
 Reserve optocoupler state change. More...
 
void upBellButChg (state_t *const me)
 Upper bell state change. More...
 
void upBellTimChg (state_t *const me)
 Upper bell was rung timer state change. More...
 

Variables

char const *const astDoor
 Ring the door bell phones (fritzbox broadcast nummer). More...
 
state_t doorOpTimer
 Door opener was activated timer. More...
 
state_t mlBellTimer
 Middle and lower bell was rung timer. More...
 
char const *const prepDoor
 Prepare ringing by file copy.
 
char const prgNamPure []
 The pure program name. More...
 
char const prgSVNdat []
 The complete SVN date string. More...
 
char const prgSVNrev []
 The complete SVN revision string. More...
 
state_t upBellTimer
 Upper bell was rung timer. More...
 

Detailed Description

Process control program for door bells IP phones etc.

The program's tasks is to monitor door bells and a door opener and to control at least one IP phone *) via an Asterisk server on the same Pi. It will log door bell events and signal door bell ringing by calling other phones (via Asterisk and a Fritz.box).

Note *): This requires that the Pi with Asterisk is made an IP phone in the home phone system (i.e. Fritz.box).
For making a phone call by something equivalent to

cp /home/pi/asteriskFiles/callDphon.txt /var/spool/asterisk/outgoing

write acces to /asterisk/outgoing/ is required for this program, e.g. by

sudo chmod -R a+rwx /var/spool/asterisk/outgoing

The program runs on a Raspberry Pi 4 with head-less (no graphics) Raspbian lite hosting an Asterisk telephone server and also an Apache web server. The Pi 4 seems more than sufficient.

Copyright (c) 2020 2024 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 265 5.10.2024
Rev. 223 18.06.2020 : new
Rev. 224 26.06.2020 : door bell rung timers and LEDs
Rev. 228 20.07.2020 : 50 Hz have wave optocoupler input filter enhanced
Rev. 230 31.07.2020 : program data handling partly to weRasp\sysBasic
Rev. 239 08.03.2021 : log system() file handling errors
Rev. 264 22.09.2024 : gn LEDs dimmed
Rev. 265 03.10.2024 : three states gn right LED door opener

Communication

HTTP (via Apache) is used for offering the log files and other information. In future a web GUI may be implemented like those for the other process control applications, cf. hometersControl.

HTTPS is not used as all LAN communication is in guarded private home or laboratory networks. Hence, the Pi can't get a Let's Encrypt certificate in the usual way. And self signed ones aren't worth the toils in a very small user community.

A VoIP phone is used to signal events to other telephones. This phone is emulated by the Asterisk server on the same Pi and registered in the site's or home's telephone system, like fritz.box.

Calling phone(s) mechanism

When this programme detects event (door bell) to be reported by a phone call it moves a command file from ~/asteriskFiles/ to /var/spool/asterisk/outgoing/. Asterisk monitors that directory and executes command files found and deletes them (no matter success or failure).
The file is moved and not copied to /var/spool/asterisk/outgoing/ to avoid the execution of partly copied files. Hence the file to be moved will be prepared by local copy (within ~/asteriskFiles/). Content, e.g.:

Channel: SIP/629

Server functions

This program handles and fills error and log files to record events. Those can be accessed and viewed via http. Door bell rings are forwarded to a set of phones via Asterisk (and fritz.box).

Library usage

The program uses some standard libraries plus own libraries in weRasp/..c and include/..h, namely weGPIOd, sysUtil etc..

cross-compile by:

make PROGRAM=homeDoorPhone TARGET=pi4Ast clean all

program by:

make PROGRAM=homeDoorPhone TARGET=pi4Ast FTPuser=pi:piPa progapp

or due to some bugs in make use winscp and IP directly by:

winscp.com /script=progTransWin /parameter pi:piPa l.e.p.i bin homeDoorPhone

Function Documentation

◆ bellsButChg()

void bellsButChg ( uint8_t  status)

Reaction to bell button presses.

This function organises the reaction to the OR of all (two as of 7'2020) bell button presses. This is
a) a beeper and b) make the telephone(s) in question ring.

Parameters
statusthe calling bell's changed button state

◆ upBellTimChg()

void upBellTimChg ( state_t *const  me)

Upper bell was rung timer state change.

It turns the left red LED ON when rung respectively OFF after 4 hours or when the door opener was activated.

Parameters
mepointer to the pump timer

◆ upBellButChg()

void upBellButChg ( state_t *const  me)

Upper bell state change.

This function controls the respective LED, controls the ORed bells state and triggers the "upper bell was rung" reminder timer.

◆ mlBellTimChg()

void mlBellTimChg ( state_t *const  me)

Middle and lower bell was rung timer state change.

It turns the left yellow red LED ON when rung respectively OFF after 4 hours or when the door opener was activated.

Parameters
mepointer to the lower bell timer

◆ mlBellButChg()

void mlBellButChg ( state_t *const  me)

Middle and lower bell state change.

This function controls the respective right yellow LED, controls the bells state and triggers the "middle and lower bell was rung" reminder timer.

◆ doorOpTimChg()

void doorOpTimChg ( state_t *const  me)

Door opener was activated timer state change.

It turns the right green LED ON dimmed to signal the door opener was inactive for more than 4 hours. On bright means inactive for less than 4 hours.when rung respectively

Parameters
mepointer to the lower bell timer

◆ doorUnlckChg()

void doorUnlckChg ( state_t *const  me)

Door opener activation state change.

This function controls the respective LED and ends the "bell was rung unnoticed" timers.

◆ resOpCoupChg()

void resOpCoupChg ( state_t *const  me)

Reserve optocoupler state change.

This optocoupler input is not used (as of July 2020) or powered. This function just logs the (de-bounced) On state (which should not occur).

◆ processIOthread()

void * processIOthread ( void *  args)

The task of controlling process IO.

This thread controls almost all processIO: 1 relay output, 6 LEDs, four digital inputs to be filtered (half wave AC via optocouplers), one beeper.

It is the 1 ms cycle and takes every forth step to sample an input. This gives five times per 50 Hz period. 2 of three will be active (LO) when the optocoupler sees an AC signal.

◆ main()

int main ( int  argc,
char **  argv 
)

The program.

run by: homeDoorPhone [options

For options see longOptions and :: optHlpTxt.

Variable Documentation

◆ prgNamPure

char const prgNamPure[]

The pure program name.

To be provided in the application's / program's source.

See also
progNam() progNamB()

◆ prgSVNrev

char const prgSVNrev[]

The complete SVN revision string.

To be provided in the application's / program's source.

See also
progRev()

◆ prgSVNdat

char const prgSVNdat[]

The complete SVN date string.

To be provided in the application's / program's source.

See also
progDat()

◆ astDoor

char const* const astDoor

Ring the door bell phones (fritzbox broadcast nummer).

fritz.box configuration (27.06.2020): TĒ¬rklingel **887 Sammel-Nr Asterisk call file:

Channel: SIP/629

Start ringing by file move.

◆ upBellTimer

state_t upBellTimer

Upper bell was rung timer.

This timer is running as reminder that the bell was rung.

◆ mlBellTimer

state_t mlBellTimer

Middle and lower bell was rung timer.

This timer is running as reminder that the bell was rung.

◆ doorOpTimer

state_t doorOpTimer

Door opener was activated timer.

This timer is running as reminder that door was opened.