gammu receive sms message python fails
Question: I have found a script on this website
<http://wammu.eu/docs/manual/smsd/run.html>

    
    
     #!/usr/bin/python
    import os
    import sys
    
    numparts = int(os.environ['DECODED_PARTS'])
    
    # Are there any decoded parts?
    if numparts == 0:
      print('No decoded parts!')
      sys.exit(1)
    
    # Get all text parts
    text = ''
    for i in range(1, numparts + 1):
      varname = 'DECODED_%d_TEXT' % i
      if varname in os.environ:
        text = text + os.environ[varname]
    
    # Do something with the text
    f = open('/home/pi/output.txt','w')
    f.write('Number %s have sent text: %s' % (os.environ['SMS_1_NUMBER'], text))
    

And i know that my gammu-smsd is working fine, because i can turn of my
ledlamp on raspberry by sending sms to the raspberry, but my question is why
is this script failing? nonthing is happening. and when I try to run the
script by it self it also fails.

What I would like to do is just receive the sms and then read the content and
save the content and phonenumber which sent the sms to a file.

I hope you understand my issue. Thank you in advance, all the best.


Answer: In the gammu-smsd config file, you can use the file backend which does this
for you automatically.

See this example from the gammu documentation
<http://wammu.eu/docs/manual/smsd/config.html#files-service>

    
    
    [smsd]
    Service = files
    PIN = 1234
    LogFile = syslog
    InboxPath = /var/spool/sms/inbox/
    OutboPpath = /var/spool/sms/outbox/
    SentSMSPath = /var/spool/sms/sent/
    ErrorSMSPath = /var/spool/sms/error/
    

Also see options for the file backend to tailor to your needs.
<http://wammu.eu/docs/manual/smsd/config.html#files-backend-options>

Hope this helps :)

