forked from gonzalo123/gam-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testSerial.php
46 lines (40 loc) · 1.13 KB
/
testSerial.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require_once('Sms.php');
require_once('Sms/Interface.php');
require_once('Sms/Serial.php');
$pin = 1234;
try {
$serial = new Sms_Serial;
$serial->deviceSet("/dev/ttyS0");
$serial->confBaudRate(9600);
$serial->confParity('none');
$serial->confCharacterLength(8);
$sms = Sms::factory($serial)->insertPin($pin);
if ($sms->sendSMS(555987654, "test Hi")) {
echo "SMS sent\n";
} else {
echo "Sent Error\n";
}
// Now read inbox
foreach ($sms->readInbox() as $in) {
echo"tlfn: {$in['tlfn']} date: {$in['date']} {$in['hour']}\n{$in['msg']}\n";
// now delete sms
if ($sms->deleteSms($in['id'])) {
echo "SMS Deleted\n";
}
}
} catch (Exception $e) {
switch ($e->getCode()) {
case Sms::EXCEPTION_NO_PIN:
echo "PIN Not set\n";
break;
case Sms::EXCEPTION_PIN_ERROR:
echo "PIN Incorrect\n";
break;
case Sms::EXCEPTION_SERVICE_NOT_IMPLEMENTED:
echo "Service Not implemented\n";
break;
default:
echo $e->getMessage();
}
}