Is it possible to access an android accessory through WebUSB? - android

I have a custom hardware, that works as an android accessory connected to a phone through USB. I managed to communicate with it through a native android app. I'd like to know if it's possible to communicate with it through the WebUSB API.
So far I just tried listing the available devices with requestDevice() using an empty filter but my device doesn't show up in the list. The site is served through https so that's not the issue and other devices that work with otg show up.
I haven't managed to found anything in docs regarding support for android accessories.

WebUSB is a wrapper around the Android USB Host API, which supports communicating with peripherals connected in client mode. The Android USB Accessory API requires the peripheral instead to be in host mode (with the Android device being the client) and provides a very different interface for reading and writing data.
This interface looks more like what is provided by the Serial API so it may make sense to expose accessories through that API instead. This is an area to research further. I have filed issue 987271 in the Chromium repository to track this exploration.

Related

Is it possible to use OTG Host Negotiation Protocol to change modes while connecting two devices?

I have two android phones connected with an OTG cable. Obviously, the cable forces once phone into host mode and the other becomes the peripheral. I would like to be able to dynamically alternate the host/peripheral status of the devices without switching the cable around and the OTG HNP spec seems to indicate that is possible. I found some further information on it here but I'm not sure where to go with it - https://android.googlesource.com/kernel/msm/+/android-msm-bullhead-3.10-marshmallow-dr/Documentation/usb/msm_otg.txt
Yes, it is possible. Good find on the very technical documentation. However the Developer.android.com site and the USB.org has more information regarding implementation:
USB accessory and host modes are directly supported in Android 3.1 (API level 12) or newer platforms. USB accessory mode is also backported to Android 2.3.4 (API level 10) as an add-on library to support a broader range of devices. Device manufacturers can choose whether or not to include the add-on library on the device's system image.
Link
As far as I can tell Host negotiation always favors traditional Host controllers like computers. Android devices have traditionally been USB accessories. However a very complicated situation arises when you have a hub with a host (like a PC) and another accessory plugged in. It seems like there is no way to settle the dispute about which device should be a host the Android or the PC. For instance I plugged in a host PC to a Android device with a HUB attached and a gigabit ethernet dongle. I could never establish a connection with the dongle. In fact the HNP never seemed to take place.
Finally, the documentation seems to suggest that the Host is responsible for operating the USB Stream. What seems most promising is the documentation Here which establishes the direction of a USBEndpoint.

CAN (Controller Area Network) on Android

I am trying to connect control multiple device on the network centrally via a tablet/android device and have some issues trying to find the right protocol for secure communication.
Is there a api available for coding/utilizing CAN network on android over Ethernet/Bluetooth/Wifi ? Or is there another protocol that is more suitable for my application?
Thank you.
What you are able to use will be determined by what protocol your devices support.
However, the use of a CAN bus is meant primarily to reduce wiring between the components, so implementing it over a wireless protocol is pretty much nonsense.
Considering you have the alternatives you mentioned (Ethernet/Bluetooth/Wifi), assuming some kind of TCP/IP network between your devices HTTPS would be a reasonable protocol to use.
Another way is to use a CAN bus to Android dongle specifically designed for this application. It uses Google's USB open accessory to communicate through USB.
If you have a PC with CAN adapter, you can use https://github.com/dschanoeh/socketcand daemon and an app (you'll have to write it yourself using available Java classes from https://github.com/dschanoeh/Kayak) on your tablet to directly communicate with CAN nodes.
Another way is to use some Ethernet/Wifi gateway like NetCAN Plus 110 Mini or NetCAN Plus 120 WLAN. You'll need to write an Android app opening a TCP channel and talking ASCII protocol to these gateways.
For Bluetooth http://www.rmcan.com/index.php?id=1067

controlling Embedded system from MOBILE. ANDROID or iOS? suggestions and explanations please

As a part of feasibly study. I need to choose between Android or iOS for integrating it with an embedded system.
Basically, that embedded system will have an AVR or a PIC Microcontroller. I want to establish a communication between a mobile and that particular system.
Need some wireless technology for communication (bluetooth,wifi,internet etc..)
Micro Controllers have communication ports like UART, USART etc..
It really depends on the kind of communication you need.
I particular, if you have a normal WIFI connection and your controller can work with receiving & sending your data via wifi, you may go iOS or Android.
If however you need some kind of free format serial communication, you need to go Android, serial cable via USB.
recarding other factors, I guess it really is just a personal taste issue.
Could you give more info on how & what needs to be communicated and what kind of communication device you have between your phone and the device itself.
Not sure if this is similar to what you have in minde, but you might look at this: http://www.arduino.cc/ being probably the best known example in this context.
Using some serial to bluetooth module would be the most easier to implement.
I would go with Android unless your target audience are photographers. Seriously. Also, with iOS you need to be careful. For instance you want to use BlueTooth, but not all iOS devices will connect to, say, the Bluetooth protocol for a keyboard. (Ah! You didn't know there were more then one Bluetooth protocol did you?) And I don't think any iOS device will let you connect using the Bluetooth serial port protocol.
With Android you can jump in and start flying immediately by using the (or a copy of) the PIC 24F based IOIO board. And if you are an Android / Eclipse developer (I think) you can down load and use the IOIO JAVA / Android libraries. I have been told this makes programming the IOIO board just about as easy as programming an Arduino. Especially if you are well versed in JAVA, Android and the Eclipse editor. Add to this the IOIO board can be a host to the Android (i.e. connected by wired USB) or host to some Bluetooth modules (i.e. connect to the Andoid's bluetooth radio).
If you don't want to go it along you can buy the Microchip Android Development Kit (ADK) board which is also a PIC 24F based "USB wired" using AOA protocol to connect to an Android. I say "not going it alone" as I would expect you can then get limited support from Microchip w.r.t. their hardware (the ADK board), software (Android) and firmware (PIC ADk board). This solution, however, does not have built in Bluetooth support. I am guessing you can add it, it's just not part of the ADK software/firmware that Microchip put together.

Gameboy-like keys and D-Pad for Android

I wanted to make an RPG for Android 2.3 Mobile Phone and thought that the good old Gameboy had the perfect format for such games. So I want to build a "Case" with a D-Pad and a few keys and connect them with the Android Device over USB. I don't want Bluetooth, because it needs to much energy. I thought about giving the Case its own Battery Cell and maybe loading the Android Device with it. So my Question is:
How can I access the Keys of this Case from the Android Device?
You might consider the Android Open Accessory Development Kit.
Even if you don't want to buy the ADK, the above link has information that will be useful to you in developing an interface to your accessory. In particular, the section on implementing the accessory protocol and the following section on how the ADK implements the protocol should prove informative. In addition, you'll probably want to look at the USB Accessory link which contains a section concerning communication with an accessory.
You can use USB on devices that have a host USB port unfortunately, not many devices have this. Your other options are bluetooth or wifi both can be accomplished in a multitude of ways. If you Google Arduino + Android I believe you will find examples of people connecting hardware to Android devices via Arduino. This is not the only way to do it, just an example of one way you could do it.
Android USB documentation
http://developer.android.com/guide/topics/usb/index.html
EDIT
You, could I suppose, use Arduino as the USB host also and use accessory mode on the Android end. In any case this none of these options are incredibly straightforward and you will need to do a lot of research to accomplish what you are envisioning.

Android USB host-to-serial connection?

Apparently with Android 2.3.4 and 3.1 one can now access USB accessories.
I have a Ardupilot Mega (based on Arduino) board with a USB cable connected to my laptop, and I can connect to it using a simple serial communications program over COM7 and 115,200 baud. This allows me into the command-line interface, and I can issue commands and get logs.
Is it possible to write an Android app that will communicate over USB to my Ardupilot Mega board?
I've seen many similar threads, but most of them were pre-USB host.
usb-serial-for-android is my open source library written for exactly this need. It supports FTDI and CDC-ACM usb serial devices using Android's USB host support; no root or ADK necessary. It can talk most Arduinos.
The project is still in its early days, but the basic support has worked well enough for several projects. There is also a discussion list where you can get help.
Unfortunately the library from mik3y's answer (see here: mik3y/usb-serial-for-android) seems to be long dead. It has many problems and waiting pull requests. Also the LGPL licence prevents anybody to fork it and maintain it.
But don't lose your hope, there's a working replacement and it's under the MIT licence. felHR85/UsbSerial.
EDIT: I found a maintained fork of mik3y's library. But the licence or readme is not updated, so I suppose the owner doesn't have a connection to mik3y and simply took it and improved it. I hope he won't get into any trouble because of the licence, because we need this library. See kai-morich/usb-serial-for-android
EDIT2: It seems that all of these libraries are maintained again, mik3y joined forces with kai-morich and they're working together now.
EDIT3: mik3y/usb-serial-for-android is under MIT license now. And still maintained in 2022.
Maybe. Check out the Android Open Accessories announcement on the Android Developers Blog. The Arduino Mega ADK is compatible. Not sure about the Ardupilot Mega.
From their page:
The Android 3.1 platform (also backported to Android 2.3.4) introduces
Android Open Accessory support, which allows external USB hardware (an
Android USB accessory) to interact with an Android-powered device in a
special "accessory" mode. When an Android-powered powered device is in
accessory mode, the connected accessory acts as the USB host (powers
the bus and enumerates devices) and the Android-powered device acts as
the USB device. Android USB accessories are specifically designed to
attach to Android-powered devices and adhere to a simple protocol
(Android accessory protocol) that allows them to detect
Android-powered devices that support accessory mode. Accessories must
also provide 500mA at 5V for charging power. Many previously released
Android-powered devices are only capable of acting as a USB device and
cannot initiate connections with external USB devices. Android Open
Accessory support overcomes this limitation and allows you to build
accessories that can interact with an assortment of Android-powered
devices by allowing the accessory to initiate the connection.
Note: Accessory mode is ultimately dependent on the device's hardware
and not all devices will support accessory mode. Devices that support
accessory mode can be filtered using a "uses-feature" element in your
corresponding application's Android manifest. For more information,
see the USB Accessory Developer Guide.
The following list of distributers are currently producing Android
Open Accessory compatible development boards:
The Arduino Store provides the Arduino Mega ADK (in EU nations or
non-EU nations) that is based on the ATmega2560 and supports the ADK
firmware. DIY Drones provides an Arduino-compatible board geared
towards RC (radio controlled) and UAV (unmanned aerial vehicle)
enthusiasts. Microchip provides a PIC based USB microcontroller board.
Modern Device provides an Arduino-compatible board that supports the
ADK firmware. RT Corp provides an Arduino-compatible board based on
the Android ADK board design. Seeed Studio provides an
Arduino-compatible board that supports the ADK firmware. SparkFun's
IOIO board now has beta support for the ADK firmware.
You can check out the library described in Slick USB 2 Serial Library.
It enables common USB-to-serial adapters to work with Android devices that have USB host mode without needing to root.
http://slickdevlabs.com/
I am currently using the library in my own app, however I think you can get away with just the app that slick has on the market. There are two free apps and one is the "pro" version of one of the free ones; search slick usb in Google Play.
It does use HOST mode and you can change the baud rate to whatever you need.

Categories

Resources