PDA

View Full Version : Showing Internet download usage


Garfield
16 Apr 09, 03:23 PM
I have used the new E-Mail facilities in Colour C-Touch to display how much of our download allocation has been used. It works for Adam Internet, but changes may be required for other ISPs. Adam Internet can send an e-mail each day once you have used 50% of your monthly quota. The logic below reads this e-mail and displays the usage on a slider.

The steps are:
A. Get a separate e-mail account for your Colour C-Touch (this is important because it deletes all e-mails once they are read)
B. Put the e-mail account details in PICED
C. Add a system io variable called Download Usage
D. Add a slider to show the Download Usage value
E. Add the logic code below

{ constants }
EMailAccountNumber = 2;

{ variables }
EMailCount : integer;
EMailNumber : integer;
EMailSender : string;
EMailSubject : string;
PercentPos : integer;
PercentString : string;

{ module }

{ look for an e-mail containing the download usage from the ISP }
EMailCount := GetEMailCount(EMailAccountNumber);
for EMailNumber := 0 to EMailCount - 1 do
begin
GetEMailSender(EMailAccountNumber, 0, EMailSender);
LogMessage('E-Mail from ', EMailSender);
if pos('help@adam.com.au', EMailSender) > 0 then
begin
GetEMailSubject(EMailAccountNumber, 0, EMailSubject);
LowerCase(EMailSubject);
PercentPos := pos('%', EMailSubject);
if PercentPos > 0 then
begin
copy(PercentString, EMailSubject, PercentPos - 5, 2);
SetIntSystemIO("Download Usage", StringToInt(PercentString));
LogMessage('Download Usage = ',PercentString, '%');
end
else
begin
PercentPos := pos('over quota', EMailSubject);
if PercentPos > 0 then
begin
SetIntSystemIO("Download Usage", 100);
LogMessage('Download Usage = 100%');
end;
end;
end;
DeleteEMail(EMailAccountNumber, 0);
LogMessage('Delete E-Mail');
end;
{ reset at the start of the 28th day of the month }
once day = 28 then
SetIntSystemIO("Download Usage", 0);
delay(600);


Edited 23/8/09 due to change in the e-mail message format from Adam Internet.