Working gammu adapter

This commit is contained in:
OsaAjani 2020-01-12 23:57:24 +01:00
parent 47e4f5a900
commit 99bb1bd46c
3 changed files with 91 additions and 2 deletions

View File

@ -166,6 +166,36 @@
{
return [];
}
$command_parts = [
PWD . '/bin/gammu_get_unread_sms.py',
escapeshellarg($this->datas['config_file']),
];
$return = $this->exec_command($command_parts);
if ($return['return'] != 0)
{
return [];
}
$smss = [];
foreach ($return['output'] as $line)
{
$decode = json_decode($line, true);
if ($decode === null)
{
continue;
}
$smss[] = [
'at' => $decode['at'],
'text' => $decode['text'],
'origin' => $decode['number'],
'destination' => $this->number,
];
}
return $smss;
}
@ -250,8 +280,6 @@
$return_var = null;
exec($command, $output, $return_var);
var_dump($output);
return ['return' => (int) $return_var, 'output' => $output];
}

56
bin/gammu_get_unread_sms.py Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# vim: expandtab sw=4 ts=4 sts=4:
#
from __future__ import print_function
import gammu
import sys
import json
def main():
state_machine = gammu.StateMachine()
if len(sys.argv) < 2:
sys.exit(1)
else :
state_machine.ReadConfig(Filename=sys.argv[1])
del sys.argv[1]
state_machine.Init()
status = state_machine.GetSMSStatus()
remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed']
start = True
try:
while remain > 0:
if start:
sms = state_machine.GetNextSMS(Start=True, Folder=0)
start = False
else:
sms = state_machine.GetNextSMS(
Location=sms[0]['Location'], Folder=0
)
remain = remain - len(sms)
for m in sms :
if m['State'] != 'UnRead' :
continue
print(json.dumps({
'number': m['Number'],
'at': str(m['DateTime']),
'status': m['State'],
'text': m['Text'],
}))
except gammu.ERR_EMPTY:
#do noting
return True
if __name__ == '__main__':
main()

View File

@ -81,6 +81,7 @@ namespace controllers\internals;
$adapter = new $adapter_classname($phone['number'], $phone['adapter_datas']);
//Try send a message
/*
$destination = '+33669529042';
$text = "Coucou c'est pour un test !";
$flash = false;
@ -89,8 +90,12 @@ namespace controllers\internals;
if (!$uid)
{
echo "Cannot send message to $destination\n";
return false;
}
echo "Send a message to $destination with uid $uid \n";
*/
$smss = $adapter->read();
var_dump($smss);
}
}