SMS Server Tools 3
This site is hosted by Kekekasvi.com
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. Please login or register. Sat Nov 25, 2017 11:32
SMSTools3 Community » Feature requests Bottom

better handling of disappering devices

Login and Post Reply

Page:  1

Author Post
Member
Registered:
May 2017
Location: Vienna, Austria
Hi,

this is somewhat related to this post:
http://smstools3.kekekasvi.com/topic.php?id=825

I'm on OpenWRT/LEDE (using custom built 3.1.21 package) and my modem has 3 devices:
/dev/ttyUSB[0-2] by default. I'm using ttyUSB2.

On the smsd side everything works fine, but the HW is used in an industrial environment with lots of EMI. This causes the usb bus to disconnect/reconnect the modem every now and then. (It can be simulated by unplugging/repluging the modem, I think.)

When this happens smsd recieves EIO, but insists on using the non-existent device. Ie I get a line of


every second without smsd ever recovering.

And what's even worse: It seems since ttyUSB2 is still "in use" after reconnecting the modem, the linux kernel assigns the modem to the devices ttyUSB0, ttyUSB1 and ttyUSB3.

I managed to work around this with an alarmhandler, that detects the EIO error and a startup script that links /dev/modem to the right device node, but it is clumsy and has some annoying side effects. I think smsd could handle this much better:

* do something sane on EIO - probably closing the device and following the usual startup procedure
* maybe also provide an option to use the highest number ttyUSB*, whatever it might be.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
In the case of disappeared modem smsd should give up faster. I may change this in the next version.

Currently there are several settings which will help in your kind of environment:

devices = GSM

# Use small errorsleeptime to get rid of EIO faster:
errorsleeptime = 1

# Use an alarmhandler which will adjust the symlink to the device
alarmhandler = /usr/local/bin/smsd_alarmhandler.sh

[GSM]
# Use symlink:
device = /dev/modem

# Close the modem when it is not used:
keep_open = no

# When opening fails and alarmhandler was called, sleep less than 30 seconds:
device_open_errorsleeptime = 3

# Other relevant settings where the default value is ok:
# device_open_alarm_after = 0
# device_open_retries = 1

 
'smsdconf' Syntax Highlight powered by GeSHi


Here is the alarmhandler which I think is self explaining:

#!/bin/bash

echo "$2 $3,$4, $5: $6" >> /var/log/smstools/alarm.log

if [ "$5" == "GSM" ]; then
  if echo "$6" | grep "Couldn't open" >/dev/null; then

    DEVICE="/dev/modem"

    if [ ! -e "$DEVICE" ]; then
      echo "Device does not exist: $(readlink "$DEVICE")"

      while [ ! -e "$DEVICE" ]; do

        # Customize these as necessary:
        if [ -e /dev/ttyUSB3 ]; then
          ln -sf /dev/ttyUSB3 "$DEVICE"

        elif [ -e /dev/ttyUSB2 ]; then
          ln -sf /dev/ttyUSB2 "$DEVICE"

        else
          sleep 3
        fi

      done

      echo "Now using: $(readlink "$DEVICE")"
    fi
  fi
fi
 
 
'bash' Syntax Highlight powered by GeSHi


I just noticed that device_open_errorsleeptime had been forgotten in the documentation. It will be updated.

The solution is external because there are different systems and not all possibilities are reasonable or even possible inside the smsd.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
As an addition, if you want that the device is always checked and set before opening, make the following change to the code: Edit src/modeminit.c, search for int openmodem and you are on the line 2347:

int openmodem()
{
  int retries = 0;

  // 3.1.7:
  //modem_handle = open(DEVICE.device, O_RDWR | O_NOCTTY | O_NONBLOCK);
 
'c' Syntax Highlight powered by GeSHi


Add highlighted lines as shown:

int openmodem()
{
  int retries = 0;

  char *DEVICE_device_open_preparator = "/usr/local/bin/smsd_preparator.sh"; // Change this as necessary.

  // 3.1.22: Run device_open_preparator if defined:
  if (DEVICE_device_open_preparator[0])
  {
    char cmdline[PATH_MAX + PATH_MAX + 32];
    int i;
    char *EXEC_DEVICE_OPEN_PREPARATOR = "device_open_preparator";

    snprintf(cmdline, sizeof(cmdline), "%s %s \"%s\" \"%s\"",
             DEVICE_device_open_preparator, DEVICE.name, DEVICE.device, DEVICE.description);

    if ((i = my_system(cmdline, EXEC_DEVICE_OPEN_PREPARATOR)) != 0)
      writelogfile(LOG_CRIT, 0, "Device_open_preparator script %s returned %i.", DEVICE_device_open_preparator, i);
  }

  // 3.1.7:
  //modem_handle = open(DEVICE.device, O_RDWR | O_NOCTTY | O_NONBLOCK);
 
'c' Syntax Highlight powered by GeSHi


With this change the preparator script could be like this:

#!/bin/bash

DEVICE="$2"

if [ ! -e "$DEVICE" ]; then
  echo "Device does not exist: $(readlink "$DEVICE")"

  while [ ! -e "$DEVICE" ]; do
    if [ -e /dev/ttyUSB3 ]; then
      ln -sf /dev/ttyUSB3 "$DEVICE"
    elif [ -e /dev/ttyUSB2 ]; then
      ln -sf /dev/ttyUSB2 "$DEVICE"
    else
      sleep 3
    fi
  done

  echo "Now using: $(readlink "$DEVICE")"
fi
 
'bash' Syntax Highlight powered by GeSHi


With this additional feature no alarmhandler is needed, but the setting keep_open = no is mandatory.

Member
Registered:
May 2017
Location: Vienna, Austria
Topic owner
Thanks for your input. The setup was already in production, when I read this, so I couldn't test this yet. I will come back to this when there is an opporunity (the setup needs maintainance or I get a new modem).

One unrelated request though: There is a patch in OpenWRT to compile smstools3:
https://github.com/haraldg/packages/blob/smstools3/utils/smstools3/patches/002-Makefile.patch

I don't think the current patch is the best way to handle this, but maybe you can improve the Makefile of smstools instead of me improving the patch in OpenWRT.

Thanks for your help,
Harald

Login and Post Reply

Page:  1

SMSTools3 Community » Feature requests Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.