Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: caller ID Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
seattlechris
Groupie
Groupie


Joined: June 29 2002
Location: United States
Online Status: Offline
Posts: 49
Posted: December 22 2004 at 21:18 | IP Logged Quote seattlechris

In case anyone wants to add caller ID to their powerhome capabilities, it's easy enough with the right kind of modem. You'll need powerhome 1.03.4.3 or later. The modem has to support caller ID, and has to act as if it communicates via a serial port (even internal PCI card modems usually do this-- check it's properties in the control panel).

The following is real sloppy programming, but it works.

In the STARTUP macro, open the serial port via a formula like ph_comopen( 4, 3, 9600, "N", 8, 1, 1, 0, 0, 1, 0, 1, 1, "?", "CHECKPHONELOG" ). This is for port 3 and a caller ID macro called CHECKPHONELOG. Then enable caller ID; this will vary from modem to modem (try this example or seek help on the web): ph_comsendstring(4, "AT+VCID=1\013" ).

When a call arrives, CHECKPHONELOG will execute. My sloppy version of CHECKPPHONELOG builds up the report from the modem character by character then strips out extra "RING" messages, leaving a date, time, phone number, and name:

Set Global   PHONE_LOG   ""

Label next

Set System [LOCAL1] ph_comrecvchar( 4 )

Set System [LOCAL2] string("[LOCAL1]")

Jump if("[LOCAL2]"="-3",3,1)

Set Global PHONE_LOG "{PHONE_LOG}" + char(integer("[LOCAL1]"))

Goto Label "next"

Set Global PHONE_LOG
ph_replaceall( "{PHONE_LOG}", "RING", "" )

Jump if(match("{PHONE_LOG}","DATE"),1,999)

Now do whatever you want with PHONE_LOG-- email it, TTS it, log it, add it to a web page...
Back to Top View seattlechris's Profile Search for other posts by seattlechris
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 22 2004 at 21:48 | IP Logged Quote TonyNo

Outstanding! Looks too simple to work!

I'll have to play with this. I was trying to unfold my brain from my VB CID code, but, I knew I could not see the forest for the trees.

I'll have to add the big features that I depend on: TTS announcements and logging calls to an HTML file.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 22 2004 at 22:51 | IP Logged Quote dhoward

Chris,

That is awesome. Really appreciate you posting this for all to play with.

With this and Tony's code, I'll definately look into adding this within PowerHome.

Thanks,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 23 2004 at 17:24 | IP Logged Quote TonyNo

My system seems to wipe out the CID info when the modem sends RING strings after the CID data is received. Anyone else see this?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 23 2004 at 21:13 | IP Logged Quote dhoward

Tony,

I looked through Chris's code and the "RING" would indeed wipe out the {PHONE_LOG} GV. His CHECKPHONELOG macro is called everytime characters are received from the modem and he resets the GV at the start of his macro. His very last line is a "Jump" command 1 line down if the GV contains the string "DATE" (for verification of a valid CID line) and 999 if it doesnt. In this very next line, I believe he is assuming that you will write it to more permanent storage such as a file, eventlog, etc.

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
seattlechris
Groupie
Groupie


Joined: June 29 2002
Location: United States
Online Status: Offline
Posts: 49
Posted: December 23 2004 at 21:31 | IP Logged Quote seattlechris

Correct Dave, the assumption was that one would append the email command or logging or TTS at the bottom of the macro. That's what I meant in my post, sorry if it wasn't clear.

BTW, because the {PHONE_LOG} isn't designed to be permanent, you could gain some efficiency by using a [TEMPx] variable instead, bypassing the database. The character by character extraction could also be rewritten to grab the whole pending string-- it's character by character with bizarre conversions because I was trouble-shooting the com functions at the time. Finally, the macro assumes that the entire string with date/time/phone-number comes quickly enough so that the whole thing is pending when the macro is executed-- this turns out to be a valid assumption in my case.

If anyone wants to clean it up, by all means repost your results. I just had no motivation to do so (and no pride ).
Back to Top View seattlechris's Profile Search for other posts by seattlechris
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 23 2004 at 23:39 | IP Logged Quote TonyNo

Ah, got it now!

The other thing I forgot about was that my current CID code also checks against a text file of names and numbers and uses the listed name instead of what the phone company sends.

Much work to do!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 24 2004 at 08:49 | IP Logged Quote TonyNo

In the mean time, here are two other AT commands to turn on the CID feature...

"at#cid=1\013", "AT#CLS=8#CID=1\013"
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 24 2004 at 14:02 | IP Logged Quote TonyNo

Building on what Chris has done, I've modified this to support the reading of an INI file to replace the name sent by the phone company with whatever you want. I also switched over to using TEMP variables. Next comes logging to a file...

Set System [TEMP1] ""
Label Next
Set System [LOCAL1] ph_comrecvchar( 4 )
Set System [LOCAL2] string( "[LOCAL1]" )
Jump if( "[LOCAL2]" = "-3", 3, 1)
Set System [TEMP1] "[TEMP1]" + char( integer( "[LOCAL1]" ))
Goto Label "Next"
Set System [TEMP1] ph_replaceall( "[TEMP1]", "RING", "" )
Get rid of all <CR><LF>'s
Set System [TEMP3] ph_replaceall( "[TEMP1]", char(13) + char(10), " " )
Set System [TEMP1] pos( "[TEMP3]", "NAME = " ) + 7
Set System [TEMP2] pos( "[TEMP3]", "NMBR = ")
Get Name
Set System [LOCAL1] mid( "[TEMP3]", [TEMP1], [TEMP2] - 2 - [TEMP1] )
Get Number
Set System [LOCAL2] mid( "[TEMP3]", [TEMP2] + 7, 10 )
Replace name sent with name listed in cid.ini file, if it exists, if not, use name sent.
Set System [TEMP1] profilestring ( "c:\program files\powerhome\cid.ini", "names", "[LOCAL2]", "" )
Set System "[LOCAL1]" if( "[TEMP1]" = "", "[LOCAL1]", "[TEMP1]")
Announce call
TTS "[LOCAL1]" + ". call from " + "[LOCAL1]"

Create an ini file called "cid.ini" in the PH directory with a section called [names], and add items like "3125551212=Joe's Cell". If PH is not installed in the default location, change the path specified in the profilestring() line.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 24 2004 at 18:25 | IP Logged Quote TonyNo

Here is the logging macro. It actually writes to two files: a raw log (cid.log), and a formatted log, which uses a template file (cidlog.txt). The template can have anything in it, as long as there is a <CID> tag somewhere. The way I use it is to automatically generate a web page with the caller id info (cidlog.psp).

Another requirement of this macro is that the caller id info has been loaded into the global variable {CID} by the main cid macro.


Write last caller info to raw log file (create the file if not there).
Formula ph_writefile( "c:\program files\powerhome\cid.log", if( ph_fileexists( "c:\program files\powerhome\cid.log") = 1, 0, 1), "{CID}" + "<br><br>" )
Load template file
Set System [LOCAL1] ph_readfile( "c:\program files\powerhome\cidlog.txt")
Load log file
Set System [LOCAL2] ph_readfile( "c:\program files\powerhome\cid.log")
Insert log data into template file
Set System [LOCAL1] ph_replaceall ( "[LOCAL1]", "<CID>", "[LOCAL2]" )
Write data to formatted log
Formula ph_writefile( "c:\program files\powerhome\web\cidlog.psp", 1, "[LOCAL1]" )
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 30 2004 at 18:04 | IP Logged Quote dhoward

Really appreciate your efforts Tony. So, have you completely integrated CID within PH now?

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: December 30 2004 at 18:42 | IP Logged Quote TonyNo

No problem. Yep, all done! I don't think much has changed since those posts were done. I was ready to start my vacation and got on a roll.

Set up the logging macro (I called it CIDLOG), and add these to the end of the main CID macro...

Format phone number
Set System [LOCAL2] string ( number("[LOCAL2]"), "###-###-####" )

Load into {CID} with date & time
Set Global {CID} "[LOCAL1]" + " " + "[LOCAL2]" + " " + string( today(), "mm/dd/yy h:mm am/pm")

Call logging macro
Macro CIDLOG Post


Here is an example template file...

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="Content" content="CIDLog auto-generated web page">
<meta name="Author" content="Tony at home.earthlink.net/~tonyno">
<title>CID Log</title>
</head>

<p align="center"><font face="Verdana" size="5"><b>CID Log...</b>
<p align="center"><font face="Verdana" size="5">
<% case(ph_getwebauth() when 2 then "<CID>" else "<font color='#FF0000' face='Arial' size='10'>Access not authorized!</font><br>") %>
</p>

<a name="end" id="end"></a>
<p align="center"><font size="3">Generated with "CIDLog" by <a href= "http://home.earthlink.net/~~tonyno">TonyNo</a></font>

</body>
</html>


For anyone else wondering, to get a plus sign to show up in this forum, you need to type "& #43". No space, though, between the ampersand and the pound sign.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: February 17 2005 at 07:27 | IP Logged Quote TonyNo

I'm having a problem with this CID implementation. It seems that, after a while, the macro is not being called when data hits the COM port. I noticed this before when a call came in, but, it was not announced. When I check the COM buffer, there are usually many characters in there (once it was 700 something). Manually running the CID macro makes it "catch up".

Anyone else seeing this?

Thanks!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 13 2005 at 22:52 | IP Logged Quote TonyNo

Update

I have also caught the COM port closing (ph_combuffercount(x) returns -2).

Anyone else?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: July 27 2005 at 20:52 | IP Logged Quote TonyNo

Well, I never found a fix, so I added a timed event to check the status every so often and reopen the port, if necessary.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 15 2006 at 16:24 | IP Logged Quote smarty

This macro works like a champ.

Question, is there any way to "block" unwanted calls from making the phone ring?

Back to Top View smarty's Profile Search for other posts by smarty
 
npavkov
Groupie
Groupie


Joined: February 29 2004
Location: United States
Online Status: Offline
Posts: 91
Posted: June 15 2006 at 21:47 | IP Logged Quote npavkov

can one of you guys post the FULL code to do this???? it looks from the forum to have gone thru numerous changes. please post any macros, code, or dependancies that this function requires, would appreciate it.... thanks
Back to Top View npavkov's Profile Search for other posts by npavkov
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 15 2006 at 23:35 | IP Logged Quote TonyNo

Let me know if it was too late for me to do this!

CID Macro Components

Global Variables: CID, CIDCOUNT

In SETUP macro (COM3):

Formula Post ph_comopen( 4, 3, 9600, "N", 8, 1, 1, 0, 0, 1, 0, 1, 1, "?", "CID" )      
Formula Post     ph_comsendstring( 4, "at#cid=1\013" )


CID Macro:

insert into macroheader values ('CID','CALLER ID',0,0,1);
insert into macrodetail values ('CID',1,15,'[TEMP1]',NULL,'""',0,'');
insert into macrodetail values ('CID',2,26,'',NULL,'Next',0,'');
insert into macrodetail values ('CID',3,15,'[LOCAL1]',NULL,'ph_comrecvchar( 4 )',0,'');
insert into macrodetail values ('CID',4,15,'[LOCAL2]',NULL,'string( "[LOCAL1]" )',0,'');
insert into macrodetail values ('CID',5,16,'',NULL,'if( "[LOCAL2]" = "-3", 3, 1)',0,'');
insert into macrodetail values ('CID',6,15,'[TEMP1]',NULL,'"[TEMP1]" + char( integer( "[LOCAL1]" ))',0,'');
insert into macrodetail values ('CID',7,27,'',NULL,'"Next"',0,'');
insert into macrodetail values ('CID',8,15,'[TEMP1]',NULL,'ph_replaceall( "[TEMP1]", "RING", "" )',0,'');
insert into macrodetail values ('CID',9,16,'',NULL,'if( match( "[TEMP1]", "DATE"), 1, 999)',0,'');
insert into macrodetail values ('CID',10,37,'',NULL,'Get rid of all <CR><LF>''s',0,'');
insert into macrodetail values ('CID',11,15,'[TEMP3]',NULL,'ph_replaceall( "[TEMP1]", char(13)+char(10), " " )',0,'');
insert into macrodetail values ('CID',12,15,'[TEMP1]',NULL,'pos( "[TEMP3]", "NAME = " ) + 7',0,'');
insert into macrodetail values ('CID',13,15,'[TEMP2]',NULL,'pos( "[TEMP3]", "NMBR = ")',0,'');
insert into macrodetail values ('CID',14,37,'',NULL,'Get Name',0,'');
insert into macrodetail values ('CID',15,15,'[LOCAL1]',NULL,'mid( "[TEMP3]", [TEMP1], [TEMP2] - 2 - [TEMP1] )',0,'');
insert into macrodetail values ('CID',16,37,'',NULL,'Get Number',0,'');
insert into macrodetail values ('CID',17,15,'[LOCAL2]',NULL,'mid( "[TEMP3]", [TEMP2] + 7, 10 )',0,'');
insert into macrodetail values ('CID',18,37,'',NULL,'Replace name sent with name listed in cid.ini file, if it exists, if not, use name sent.',0,'');
insert into macrodetail values ('CID',19,15,'[TEMP1]',NULL,'profilestring ( "c:\program files\powerhome\cid.ini", "names", "[LOCAL2]", "" )',0,'');
insert into macrodetail values ('CID',20,15,'[LOCAL1]',NULL,'if( "[TEMP1]" = "", "[LOCAL1]", "[TEMP1]")',0,'');
insert into macrodetail values ('CID',21,38,'',1,'ph_macroparm ( "ANNOUNCE", "[LOCAL1]" + ". call from " + "[LOCAL1]", 5, 0, 0, 0 )',0,'');
insert into macrodetail values ('CID',22,15,'[LOCAL2]',NULL,'string ( number("[LOCAL2]"), "###-###-####" )',0,'');
insert into macrodetail values ('CID',23,10,'CID',NULL,'"[LOCAL1]" + " " + "[LOCAL2]" + " " + string( today(), "mm/dd/yy h:mm am/pm") ',0,'');
insert into macrodetail values ('CID',24,10,'CIDCOUNT',NULL,'{CIDCOUNT}+1',0,'');
insert into macrodetail values ('CID',25,1,'CIDLOG',1,'',0,'');


CIDLOG Macro:

insert into macroheader values ('CIDLOG','LOG CID INFO',0,0,1);
insert into macrodetail values ('CIDLOG',1,37,'',NULL,'Write last caller info to raw log file (create the file if not there).',0,'');
insert into macrodetail values ('CIDLOG',2,38,'',0,'ph_writefile( "c:\program files\powerhome\cid.log", if( ph_fileexists( "c:\program files\powerhome\cid.log") = 1, 0, 1), "{CID}" + "<br><br>" )',0,'');
insert into macrodetail values ('CIDLOG',3,37,'',NULL,'Load template file',0,'');
insert into macrodetail values ('CIDLOG',4,15,'[LOCAL1]',NULL,'ph_readfile( "c:\program files\powerhome\cidlog.txt")',0,'');
insert into macrodetail values ('CIDLOG',5,37,'',NULL,'Load log file',0,'');
insert into macrodetail values ('CIDLOG',6,15,'[LOCAL2]',NULL,'ph_readfile( "c:\program files\powerhome\cid.log")',0,'');
insert into macrodetail values ('CIDLOG',7,37,'',NULL,'Insert log data into template file',0,'');
insert into macrodetail values ('CIDLOG',8,15,'[LOCAL1]',NULL,'ph_replaceall ( "[LOCAL1]", "<CID>", "[LOCAL2]" )',0,'');
insert into macrodetail values ('CIDLOG',9,37,'',NULL,'Write file to formatted log',0,'');
insert into macrodetail values ('CIDLOG',10,38,'',0,'ph_writefile( "c:\program files\powerhome\web\cidlog.psp", 1, "[LOCAL1]" )',0,'');


cid.ini Format:

[Names]
1235551212=Tony
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 16 2006 at 09:18 | IP Logged Quote smarty

Tony,
While my CID macro works as is, I always look at you stuff to see what other/better ideas you might have (thanks!).

What I don't understand is text before each PH macro line => "insert into macroheader values".

What does this text mean? I know that this is not PH macro language. Is is an artifact from writing in SQL or something along those lines? Sorry for this very basic questions, but I have ZERO programming experience (unless you count BASIC and Fourtran 77).
Back to Top View smarty's Profile Search for other posts by smarty
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 16 2006 at 13:44 | IP Logged Quote TonyNo

That is the output from exporting the macro. You can copy that text, paste it into the PowerHome MultiEditor set for SQL (Edit|Language|SQL), hit the Run button, and the macro will be installed on your system.

BASIC counts!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum