Things slowly came together this past week for adding Bluetooth Low Energy (BLE) capability into the Android Boat Captain software. I used Android Studio on my wife's computer for a day to do this, but found it a bit cumbersome to drag my electronics and USB cables back and forth between my laptop and her computer. This prompted some browsing of new computers on the Internet for a couple of hours, but this exercise revealed that the computer I wanted to buy was over $1000 so plan B was to try installing Android Studio on the Mac partition of my hard drive, to see if it fared any better than it did under Windows. Lo and behold it did!!! It was pretty much as fast as it was on my wife's computer, and didn't suffer any of the same debugging problems that I had under Windows. Why it performed so poorly under Windows, I'm not sure. Maybe it was general Windows 10 slowness, or the 2000 or so things that always seem to be running in the background, I don't know.
Anyway, I was able to make some steady progress after that. The reason I wasn't receiving any BLE traffic before was that I had to wait for a notification that data had arrived in the Android code. The process for requesting and receiving BLE data is somewhat convoluted. The literature claims that the reason for this is to conserve power. That may be so, but it sort of seems more complicated than it needs to be, as there are a number of steps involved in setting up a connection, more steps involved for sending out data and verifying that the data was really sent, then steps involved for enabling notifications for the receipt of data, and then finally actually receiving the data when it does arrive. Plus, the data arrives in little chunks that are no more than 20 bytes in size, so the actual data packets have to be stitched back together afterward. The 20-byte packet size and notification-based-approach also makes data transfer a bit slow; unless I can figure out some way to reliably speed it up, it'll be like travelling back in time 30 years to the days of dial-up modems. The slow speed is fine for simple control commands that only require a few bytes, but makes things like image downloads pretty slow.
Everything communications-wise is almost all working now. The commands for controlling propeller power and direction, and requesting basic sensor data all work, but some of the more complicated commands for requesting image samples and / or bringing the boat back to the GPS location of the phone need a bit more work. After that I'll switch over to iOS and do it all over again...
No comments:
Post a Comment