Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

How does the uploader recover a blocked CNL USB stick #261

Closed
ondrej1024 opened this issue Nov 22, 2019 · 16 comments
Closed

How does the uploader recover a blocked CNL USB stick #261

ondrej1024 opened this issue Nov 22, 2019 · 16 comments

Comments

@ondrej1024
Copy link

This is not a bug report but rather a question.

When experimenting with the CNL Python driver, I sometimes end up with the CNL USB stick completely hanging which means it is not not responding anymore to any request.

How do you deal with this situation in the Android uploader? Is there a way to automatically recover without unplugging the stick?

Thanks, Ondrej

@Pogman
Copy link
Collaborator

Pogman commented Nov 22, 2019

Oh boy... you don't want to know how long I've spend diagnosing and dealing with this particular issue. It got a tad obsessive... the CNL is temperamental and any hiccup will cause a E86 error that can only be reset by pulling power on the usb bus. This can't be done on Android or at least not for vanilla un-rooted devices and it requires a user to unplug / plug the CNL to get going again.

You may have option with rPi devices to shut power to the usb to reset. If you can't do that have a look at this code as it handles most of the important issues that catch and reduce the potential for glitches that can error the CNL. This is extensively stress tested and can run continuously, most CNL errors are now a result of a poor wobbly usb connection.

https://github.com/pazaan/600SeriesAndroidUploader/blob/master/app/src/main/java/info/nightscout/android/medtronic/message/ContourNextLinkMessage.java

@ondrej1024
Copy link
Author

Thanks for the pointer.

On the RPi3 I act on the USB event when the CNL is removed (which occurs when the stick locks up) and run this script to power down and up the USB port.

Unfortunately this cannot be done on the RPiZero which has the 5V hard wired to the USB port. So I am facing the same problem as on a smart phone. I might need to port your enhancements of the protocol handler to the Python driver to make this more reliable on the RPiZero 😟

@ondrej1024
Copy link
Author

I just tried the CNL Python driver on the RPi-Zero. While the driver is running quite reliably on an RPi3 (no hangups for a day or so) on the RPi-Zero I get only 1 good reading from the CNL. At the second attempt I get this error:

2019-11-23 19:20:52,206 WARNING [read_minimed_next24] Timeout waiting for message
2019-11-23 19:20:52,253 ERROR [read_minimed_next24]  ### checkControlMessage: Expected to get an 0x5 control character, got message with length 293 and control char 0x125

At the next reading I get:

2019-11-23 19:20:57,306 ERROR [read_minimed_next24] readDeviceInfo: Expected to get an ASTM message, but got 05 instead

and the CNL hangs up compeltely, which means it even disappears from the USB bus.

Any idea why the same driver would perform so much worse on the RPi-Zero?

@Pogman
Copy link
Collaborator

Pogman commented Nov 24, 2019

There may be an issue with the first read that looked successful. It's vital that the CNL be opened and closed in a controlled way or the next read can error. Check timing too, the CNL can send responses if things take too long and these need to be cleared from the input stream before any request sent.

@steve8x8
Copy link

Someone might invent a USB-controlled USB switch... (think smart socket, but for USB).
I'm sure there are many other applications for this - and actually it might yet exist somewhere?

@steve8x8
Copy link

Indeed there's such a device: https://www.yepkit.com/product/300115/YKUSHXS ...

@ondrej1024
Copy link
Author

Well, let's hope we can fix this in the CNL driver software so there is no need for additional HW.

@steve8x8
Copy link

@ondrej1024, re your report from Nov 24: apparently the next read attempt returns the 0x5 value the previous one was waiting for - would it help to see what's in the "extra data" that were provided before (the one with length 293)?

@ondrej1024
Copy link
Author

Yes, you are right. I didn't notice that. I need to debug this some more.

Apparently the current Python driver does not have all the optimizations that went into the Android version which was developed later. So I need some time to do the backport. But first I want to get the Nightscout upload support out.

@steve8x8
Copy link

steve8x8 commented Nov 28, 2019

Perhaps, in checkControlMessage(), if the control character doesn't match

  • dump the whole record (may give a clue what's going on)
  • instead of raising an error early, try to read yet another record (with a timeout exception handler in place)

Possibly it's the second sendMessage() that confuses the stick - if it still has some data ready from the previous one?

@ondrej1024
Copy link
Author

@steve8x8 : I think it would be perfect if you could do a bit of debugging regarding this issue. I am really tied up at the moment and don't have time to dedicate to this. Get yourself a RPi-Zero-W, it's just 10€ 😎

@steve8x8
Copy link

RPi0: I got two of them - but am lacking a CNL :'( that's why I'm limited to guesses

@akumpu
Copy link

akumpu commented Dec 9, 2019

Hi and FYI
I have already discussed about this one with steve8x8 in gitter.
This issue is permanent in my(actually my daughter's) setup.
I'll get E86 within ten or fifteen minutes from start, i.e. from the point when I have plugged CNL to android.
I tried to reproduce it with python driver, with Linux laptop.
But unfortunately the issue is not easy to reproduce with it. I have run several hundred read rounds without problems.

@steve8x8
Copy link

steve8x8 commented Feb 1, 2020

@akumpu and others: can you provide a logcat of the android device when e86 has happened? I'm afraid though this wouldn't help much - as long as we don't know what the contents of the unexpected response from the CNL are. Back to printf debugging?

@akumpu
Copy link

akumpu commented Feb 11, 2020

@steve8x8 : I have used CNL + uploader several months now without any issues (with my Galaxy J5).
But I'll follow it and I'll take the logs if possible

@ondrej1024
Copy link
Author

This issue is solved. After modifying the Python code I have it running on a battery powered RPi-Zero and downloading the pumps status information successfully for 24h without getting stuck.

Here is the modified Python CNL2.4 driver lib:
https://github.com/ondrej1024/ddguard/blob/comms_robustness_backport/cnl24driverlib.py

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

No branches or pull requests

4 participants