Sporadic disconnect

209 views
Skip to first unread message

JP

unread,
Jun 28, 2012, 2:54:36 PM6/28/12
to ioio-...@googlegroups.com
Hi!

My wind meter app which reads wind speed and wind direction from a wind vane and send it to a web server suffers from a sporadic connection problem. Once in a while the IOIO board connection is lost and does not come back. When this happens the app just hangs but if the app is paused (by going back to the phone's home screen) and then resumed, the connection is restored and everything works again. Sometimes the app runs just fine for several weeks and all of a sudden the connection is lost. Sometimes this happens more often.

I have tried to design the code so that it should recover gracefully if the IOIO connection is lost but it does not seem to work. In order to figure out what's going on I have inserted some trace statement in the code but I don't really understand the information that I get from logcat.

Please find the source code and a logcat dump attached. Does anyone have any suggestion on what's causing this problem and how to proceed?

IOIO version:

Hardware ID: SPRK0016
Bootloader ID: IOIO0300
Firmware ID: IOIO0310

Android device:
HTC Magic with Android 2.2

Best regards,
JP
logcat.txt
windmeter.java

Ytai Ben-Tsvi

unread,
Jun 30, 2012, 5:09:07 PM6/30/12
to ioio-...@googlegroups.com
I don't see anything special about your logcat - it looks normal.
What I'd try first is to upgrade the IOIO app firmware to the lastest (3.23) and see if the problem persists.
Another thing: are you using Bluetooth or USB?
And last: can you reproduce this problem with one of the example applications or any other kind of super-simple application?


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/LZGWwa68mz0J.
To post to this group, send email to ioio-...@googlegroups.com.
To unsubscribe from this group, send email to ioio-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ioio-users?hl=en.

JP

unread,
Jul 1, 2012, 4:14:45 PM7/1/12
to ioio-...@googlegroups.com
Can you see some flaws in the design of my code?

I have ordered a second ioio board from Sparkfun so that I can test it with the latest firmware and some simple application for a while at home. I don't have the same Android phone at home so I can't test the exact setup but hopefully this will get me something more to work with.

JP

unread,
Jul 1, 2012, 4:15:51 PM7/1/12
to ioio-...@googlegroups.com
I forgot to write that I am using USB.
Message has been deleted

Ytai Ben-Tsvi

unread,
Jul 1, 2012, 6:48:47 PM7/1/12
to ioio-...@googlegroups.com
Your code doesn't use the standard IOIOActivity structure (for no good reason I believe). It would become a lot shorter, and possibly more reliable if you convert it. Note that even before upgrading your firmware, you can use the App-IOIO0323 Android software, which will be compatible with your firmware.

You haven't answered my question on whether the sample apps also exhibit this behavior. This will help us tell whether it is something specific to your code or something about the IOIO software / firmware.

Ytai

On Sun, Jul 1, 2012 at 2:15 PM, JP <jp.su...@gmail.com> wrote:
I forgot to write that I am using USB.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/DE5UVzBWGPMJ.
Message has been deleted

JP

unread,
Jul 2, 2012, 2:40:36 AM7/2/12
to ioio-...@googlegroups.com
I didn't use the convenience class and wrote my own code just to get a better understand of how it works (being new to Android, Java and IOIO). I haven't tried to run any of the example applications continuously so I don't know if the problem is present for these as well.

Once I get my new board I will try the latest firmware and lib and switch to IOIOActivity and run my app for some weeks to see if the problem is still there.

JP

unread,
Aug 13, 2012, 12:49:17 PM8/13/12
to ioio-...@googlegroups.com
Hi!

I'm trying to convert my app to make use of IOIOActivity instead of implementing everything from scratch. In my previous implementation I created a new thread which took care of the cyclic measurements of the pulses from the anemometer. I used a timer to interrupt the thread after 2 sec.

When using the IOIOActivity the timer code doesn't work anymore (see my code snippet below). I'm a Java / Android newbie and haven't found a way to solve this. Is it possible to interrupt the thread somehow using a timer or do I need to create a new thread or something else?

Thanks in advance!

        @Override
        public void loop() throws ConnectionLostException {
            TimerTask t = new TimerTask() {
                public void run() {
                    interrupt();     // Syntax error! The method interrupt() is undefined for the type new TimerTask(){}
                    Thread.currentThread().interrupt();  // The while loop is never interrupted
                }
            };

            timer.schedule(t, 2000);
           
            try {
                pulses = 0;
                dirRead = aInput.getVoltage();
                while (true) {
                    dInput.waitForValue(false);
                    dInput.waitForValue(true);
                    pulses++;
                    Thread.sleep(5);
                }
            } catch (InterruptedException ex) {
                // Interrupted by the timer
                trace("Interrupted");

Ytai Ben-Tsvi

unread,
Aug 13, 2012, 8:05:28 PM8/13/12
to ioio-...@googlegroups.com
You need something like:

final Thread current = Thread.current();
TimerTask t = new TimerTask() {
  public void run() {
    current.interrupt();
  }
};
timer.schedule(t, 2000);
try {
  ... do work ...
  timer.cancel();
} catch (...) {
...

(sorry if that's not compiling, I was just typing that into the browser, but you get the idea...)
You can wrap this thing in a method that simply returns the pulse count after two seconds to make this more organized.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/DX3llZzNul4J.

JP

unread,
Aug 16, 2012, 5:25:48 PM8/16/12
to ioio-...@googlegroups.com
Thanks! The timeout now works as expected!

I wanted to debug my app and check so that it's robust when it comes to connecting/disconnecting/reconnecting so I tried various combinations of disconnecting by pulling the USB cable and leaving the app by going back to the home screen and then returning. Most things work but I have come across when situation where the connection is not reestablished the way I think it should (or at least the way I would like to have it).

I was able to reproduce the problem using HelloIOIO (to rule out errors just in my own code). This is what I did:

  1. Start HelloIOIO without the USB cable plugged in.
    • The HelloIOIO GUI is displayed.
  2. Plug in the USB cable, wait for a couple of seconds to allow connection,  tap the led on/off button twice.
    • The led comes on and then off.
  3. Leave HelloIOIO by pressing the "Home" button on the phone going back to the home screen.
  4. Start HelloIOIO again.
    • The HelloIOIO GUI is displayed.
  5. Tap the led on/off button.
    • The led does not come on indicating that there is not connection.

Logcat shows the following trace:

08-16 22:47:03.176: D/IOIOImpl(25125): Waiting for IOIO connection
08-16 22:47:03.176: V/IOIOImpl(25125): Waiting for underlying connection
08-16 22:47:03.176: V/SocketIOIOConnection(25125): Creating server socket
08-16 22:47:03.176: V/SocketIOIOConnection(25125): Waiting for TCP connection
08-16 22:47:07.850: V/SocketIOIOConnection(25125): TCP connected
08-16 22:47:07.860: V/IOIOImpl(25125): Waiting for handshake
08-16 22:47:07.880: V/IOIOImpl(25125): Querying for required interface ID
08-16 22:47:07.880: V/IOIOImpl(25125): Required interface ID is supported
08-16 22:47:07.880: I/IOIOImpl(25125): IOIO connection established
08-16 22:47:13.456: D/IOIOImpl(25125): Client requested disconnect.
08-16 22:47:13.466: V/SocketIOIOConnection(25125): Client initiated disconnect
08-16 22:47:13.476: D/IOIOProtocol(25125): Received soft close.
08-16 22:47:13.506: D/IOIOAndroidApplicationHelper(25125): IOIOThread is exiting
08-16 22:47:16.208: D/IOIOImpl(25125): Waiting for IOIO connection
08-16 22:47:16.208: V/IOIOImpl(25125): Waiting for underlying connection
08-16 22:47:16.208: V/SocketIOIOConnection(25125): Creating server socket
08-16 22:47:16.208: V/SocketIOIOConnection(25125): Waiting for TCP connection

It seems like the app is trying to reestablish a connection between the phone and the board but the TCP connection gets stuck somehow. Is this the way it's supposed to work? Does anyone else experience the same behavior?

I'm using the following hardware/software:

HTC Wildfire S with Android version 2.3.5)
SPRK0016
Bootloader IOIO303
Firmware IOIO324

Ytai Ben-Tsvi

unread,
Aug 19, 2012, 12:59:31 AM8/19/12
to ioio-...@googlegroups.com

This is definitely not how it should work and I've been testing all possible combinations of exit app / enter app / connect IOIO / disconnect IOIO quite aggressively on the platforms I'm using. May I suggest that you try to debug this and figure out where it gets stuck exactly?

To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/32TJk5AmJfEJ.

JP

unread,
Aug 19, 2012, 2:21:00 PM8/19/12
to ioio-...@googlegroups.com
Yes, I will try to debug this. I've read somewhere that it's possible to debug in realtime connecting the Android device to the computer while simultaneously having the IOIO board connected. My Android device doesn't have OpenAccessory. I've seen posts on the Internet about debugging over wifi and Bluetooth. Has anyone tried that in combination with IOIO? I'm using a company phone so rooting the phone is not really an option... What options do I have?

I have started to examine the different connection problems my app has experienced more closely and I think there are actually several different problem areas.

- At one time the phone seems to have lost the DNS connection (possibly all Internet connection). It's difficult to say why this happened but I think I need to make the code more robust and add some code to reset the Internet connection.

- Another time the USB connection between the phone and the board was lost. Again it's very difficult to see why this all of a sudden happened (just by looking at the logcat). But if this happens the app should just try to reconnect. The reason why this didn't work could very likely be caused by my implementation but now when I've switched to the recommended use of IOIOActivity I hope that it's more robust.

- I see some garbage collection (GC_FOR_MALLOC) traces in logcat. I'm not sure if those stem from my app or something else. I've just begun to study how memory leaks can be analyzed using MAT.

Ytai Ben-Tsvi

unread,
Aug 20, 2012, 1:12:38 AM8/20/12
to ioio-...@googlegroups.com
Re debugging, if you connect to the IOIO over Bluetooth you can leave your Android connected to your PC over USB. That's what I normally do.

To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/vfxHxJW3V6sJ.
Message has been deleted

JP

unread,
Aug 23, 2012, 1:07:48 PM8/23/12
to ioio-...@googlegroups.com
This is strange. When I tried to reproduce the problem with a Bluetooth connection and USB for debugging, the problem was gone. I then tried without Bluetooth and it worked for this setup as well. Next step was to remove the Bluetooth lib and recompile the app (going back to the inital setup) but the problem was gone. Must be some sort of temporary glitch...

JP

unread,
Sep 24, 2012, 6:40:18 AM9/24/12
to ioio-...@googlegroups.com

Hi!

 

Since many of the posts in this group naturally concerns problems of some kind, I just wanted to report back that my IOIO-based wind meter is actually working very well. Many thanks to Ytai for your support!

 

I had some trouble with sporadic IOIO disconnects and Internet connection drops but my latest changes seem to have been successful. The wind meter has now run 24/7 for some month without problems.

 

In order to handle the various problems I encountered, the following changes were made:

 

1.If the DNS connection is lost the mobile data connection is reset. This is done by accessing the hidden API IConnectivityManager.setMobileDataEnabled() using Java reflection. This solution is not future-proof since the API can be removed in future release of the Android OS but in my case it works for now and I don't plan on changing the phone I'm using.

 

2.I switched to IOIOActivity instead of my own implementation and it seems to be more robust when it comes to USB disconnection/reconnection.

 

3.The occurrence of garbage collection messages in the log is probably not a problem which was my initial thought. I used MAT to analyze the memory consumption of my app and it didn't grow over time so the GC messages are probably just a proof that the GC is working as intended.

 

4.I added some housekeeping code to log potential exceptions and pass them on to the web server so I can happily monitor the state of the app remotely.

 

Ytai Ben-Tsvi

unread,
Sep 25, 2012, 1:18:26 AM9/25/12
to ioio-...@googlegroups.com
Thanks for reporting! It is indeed fun to read about things that work rather than about things that don't :)
Let's see how long it lasts before surrendering to the weather. This is a valuable experiment.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/ZvMTPe-1x74J.

JP

unread,
Sep 25, 2012, 2:27:02 AM9/25/12
to ioio-...@googlegroups.com

 

Well, if it's not the weather it could be mother nature. The wind meter suddenly began to report zero wind speed even if it was quite windy weather. I suspected that there was some electrical problem but it turned out to be a gang of spiders that thought the anemometer cups were a good place to settle down. They secured the cups tightly with a spider web so the cups couldn't rotate :)

 

Ytai Ben-Tsvi

unread,
Sep 25, 2012, 3:41:36 AM9/25/12
to ioio-...@googlegroups.com
:D

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/xiY9SehAFqAJ.

Jeff Eberl

unread,
Sep 25, 2012, 11:03:38 AM9/25/12
to ioio-...@googlegroups.com

Good thing the ioio has enough ports to control an automated turret.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ioio-users/-/xiY9SehAFqAJ.
Reply all
Reply to author
Forward
0 new messages