Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udev symlink problem on raspberry pi / ti usb not working on raspberry pi's #52

Open
PieterGit opened this issue Nov 6, 2016 · 5 comments

Comments

@PieterGit
Copy link

PieterGit commented Nov 6, 2016

when i use the udev rules i end up with a symlink like this:

pi@pi0$ ls -al /dev/mmeowlink
lrwxrwxrwx 1 root root 15 Nov  6 11:17 /dev/mmeowlink -> bus/usb/001/006

instead of a symlink to ttyACM.

Communicating is not possible and give various errors, such as



 $ openaps use pump model
Traceback (most recent call last):
  File "/usr/local/bin/openaps-use", line 63, in <module>
    app( )
  File "/usr/local/lib/python2.7/dist-packages/openaps/cli/__init__.py", line 51, in __call__
    self.run(self.args)
  File "/usr/local/bin/openaps-use", line 57, in run
    output = app(args, self)
  File "/usr/local/lib/python2.7/dist-packages/openaps/uses/__init__.py", line 92, in __call__
    return self.method.selected(args)(args, app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/uses/__init__.py", line 31, in __call__
    return self.method(args, app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/uses/use.py", line 44, in __call__
    self.before_main(args, app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 63, in before_main
    self.check_session(app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 140, in check_session
    self.session = self.get_session_info( )
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 103, in get_session_info
    fields = self.create_session( )
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 128, in create_session
    self.pump.power_control(minutes=minutes)
  File "/home/pi/src/mmeowlink/mmeowlink/handlers/stick.py", line 212, in power_control
    status = repeater(self.command, repetitions=500, ack_wait_seconds=20)
  File "/home/pi/src/mmeowlink/mmeowlink/handlers/stick.py", line 191, in __call__
    self.wait_for_ack()
  File "/home/pi/src/mmeowlink/mmeowlink/handlers/stick.py", line 83, in wait_for_ack
    buf = link.read( timeout=timeout )
  File "/home/pi/src/mmeowlink/mmeowlink/vendors/subg_rfspy_link.py", line 191, in read
    return self.get_packet(timeout)['data']
  File "/home/pi/src/mmeowlink/mmeowlink/vendors/subg_rfspy_link.py", line 185, in get_packet
    return self.handle_response(resp)
  File "/home/pi/src/mmeowlink/mmeowlink/vendors/subg_rfspy_link.py", line 154, in handle_response
    decoded = FourBySix.decode(resp[2:])
  File "/home/pi/src/mmeowlink/mmeowlink/fourbysix.py", line 86, in decode
    raise InvalidPacketReceived("Error decoding FourBySix packet")
mmeowlink.exceptions.InvalidPacketReceived: Error decoding FourBySix packet

or

 $ openaps use pump model
Traceback (most recent call last):
  File "/usr/local/bin/openaps-use", line 63, in <module>
    app( )
  File "/usr/local/lib/python2.7/dist-packages/openaps/cli/__init__.py", line 51, in __call__
    self.run(self.args)
  File "/usr/local/bin/openaps-use", line 57, in run
    output = app(args, self)
  File "/usr/local/lib/python2.7/dist-packages/openaps/uses/__init__.py", line 92, in __call__
    return self.method.selected(args)(args, app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/uses/__init__.py", line 31, in __call__
    return self.method(args, app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/uses/use.py", line 44, in __call__
    self.before_main(args, app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 63, in before_main
    self.check_session(app)
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 140, in check_session
    self.session = self.get_session_info( )
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 103, in get_session_info
    fields = self.create_session( )
  File "/usr/local/lib/python2.7/dist-packages/openaps/vendors/medtronic.py", line 128, in create_session
    self.pump.power_control(minutes=minutes)
  File "/home/pi/src/mmeowlink/mmeowlink/handlers/stick.py", line 212, in power_control
    status = repeater(self.command, repetitions=500, ack_wait_seconds=20)
  File "/home/pi/src/mmeowlink/mmeowlink/handlers/stick.py", line 191, in __call__
    self.wait_for_ack()
  File "/home/pi/src/mmeowlink/mmeowlink/handlers/stick.py", line 84, in wait_for_ack
    resp = Packet.fromBuffer(buf)
  File "/home/pi/src/mmeowlink/mmeowlink/packets/rf.py", line 97, in fromBuffer
    raise InvalidPacketReceived
mmeowlink.exceptions.InvalidPacketReceived

When I change the symlink to /dev/ttyACM<x> i can communiate with the pump.

@PieterGit PieterGit changed the title udev symplink problem on pi zero / ti usb not working on pi zero udev symlink problem on pi zero / ti usb not working on pi zero Nov 6, 2016
@PieterGit
Copy link
Author

Linux kernel 4.4.30+ #919 Tue Nov 1 16:52:58 GMT 2016 armv6l GNU/Linux
TI firmware 0.8
Same TI stick works fine with pi3.

pi@pi0:/etc/udev/rules.d $ cat 90-mmeowlink.rules
# symlink for TI Dongle flashed with subg_rfspy firmware
ATTR{idVendor}=="1d50", ATTR{idProduct}=="8001", MODE="0664", GROUP="plugdev", SYMLINK+="mmeowlink", RUN+="/usr/local/bin/mmt.sh"

the mmt.sh script does a mmtune

/usr/local/bin/mmtune.py --subg_rfspy --radio_locale WW --port /dev/ttyACMX --serial 123456 

@PieterGit
Copy link
Author

PieterGit commented Nov 6, 2016

I found a workaround

$ cat /etc/udev/rules.d/90-mmeowlink.rules
# symlink for TI Dongle flashed with subg_rfspy firmware
ATTR{idVendor}=="1d50", ATTR{idProduct}=="8001", MODE="0664", GROUP="plugdev", SYMLINK+="mmeowlink", RUN+="/usr/local/bin/mmt.sh"

and $cat /usr/local/bin/mmt.sh contains:

#!/bin/sh
echo `date ` mmtune start >> /var/log/openaps/mmtune.log
echo 'change link from ' >> /var/log/openaps/mmtune.log
ls -al /dev/mmeowlink >> /var/log/openaps/mmtune.log
d=`/home/pi/src/oref0/bin/oref0-find-ti-usb-device.sh`
sudo rm -rf /dev/mmeowlink
echo "to:"
sudo ln -s /dev/$d /dev/mmeowlink
ls -al /dev/mmeowlink  >> /var/log/openaps/mmtune.log
/usr/local/bin/mmtune.py --subg_rfspy --radio_locale WW --port /dev/mmeowlink --serial 123456 >> /var/log/openaps/mmtune.log
echo `date ` mmtune end >> /var/log/openaps/mmtune.log

and

$ cat /home/pi/src/oref0/bin/oref0-find-ti-usb-device.sh
#!/bin/sh
usbid=`dmesg | grep "idVendor=1d50, idProduct=8001" | tail -n 1 | sed -e 's/^.*usb \([0-9\.\-]*\):.*$/\1/g'`
device=`dmesg | grep "cdc_acm $usbid" | tail -n 1 | sed -e 's/^.*: \(tty[A-Z0-9]*\): USB.*$/\1/g'`
echo  $device

If there is anything I can do to fix this without the mmt.sh script I would be thankfull. Please let me know if I can help to fix this.

I think this also fix the serial.serialutil.SerialException: Could not configure port: (25, 'Inappropriate ioctl for device'). For example reported here: https://gitter.im/nightscout/intend-to-bolus?at=57ad0ac3613cc180367ba884 by @bfaloona

@PieterGit PieterGit changed the title udev symlink problem on pi zero / ti usb not working on pi zero udev symlink problem on raspberry pi / ti usb not working on raspberry pi's Nov 6, 2016
@oskarpearson
Copy link
Owner

Hi Pieter. Currently worldwide pump support is problematic. The way we do it is that we run mmtune every time openaps runs - rather than in the udev rules. The radio frequency of the pump/ti stick change as temperature changes, for example. By doing things in udev rules, you're only running the tune once - when the ti stick is inserted or when the device is rebooted.

If you change things so that you run mmtune --radio_locale WW as part of your loop it'll re-tune as the day goes by and as the radio frequency drifts.

There's an existing issue for WW pump support here: #51 If it's ok, I'd like to close this as a duplicate of that item?

I don't think that the 'Inappropriate ioctl for device' issue is related to the WW pump issue. That might be a different bug, though. We'd need more information on where /dev/ttyACM0 or similar pointed at, and how it varied vs /dev/mmeowlink

@PieterGit
Copy link
Author

PieterGit commented Nov 7, 2016

@oskarpearson thanks for responding. I don't think this specific issue is WW only. I have seen quite some serial.serialutil.SerialException: Could not configure port: (25, 'Inappropriate ioctl for device') reports by people on https://gitter.im/nightscout/intend-to-bolus

Strange thing is that @mawhit reports it on a PI3 and I have no problems with the TI-stick on my PI3, but do have problems with a PI0.

Perhaps @bfaloona and @mawhit can let us know if they are using a worldwide (WW) or US pump. They both had serialutil.SerialException: Could not configure port: (25, 'Inappropriate ioctl for device') because the SYMLINK option of udev chose to bind it to /dev/usb/x/y instead of /dev/ttyACMx for some unknown reason.

@mawhit
Copy link

mawhit commented Nov 7, 2016

I'm using a US pump - MMT723. Not having any issues at the moment though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants