UART peripherals on Android Things for Raspberry Pi 3 - android

How do I use UART peripherals on Android Things for Raspberry Pi 3?
It seems that by default it is assigned the linux console.

By default the UART port is mapped to the linux console, in order to prevent the kernel message from messing around with your peripheral.
You can disable the console by mounting the boot partition from the sdcard on your host computer using:
mount /dev/sdX1 /mnt/disk
where sdX is replaced with your sdcard reader device name (running dmesg after inserting your sdcard into your reader should help you figure out the device name).
Then edit /mnt/disk/cmdline.txt to replace the following kernel boot argument:
console=serial0,115200
with:
console=tty0
If you need to re-enable the console later for debugging purpose, just add the same argument back.
See the developer docs for more info on disabling the console.

Beginning with Developer Preview 3, in which USB-Serial devices support added, external USB-UART dongles like this can be used instead of built-in UART of Raspberry Pi 3.

Related

Use libCEC + USB dongle in Android app

My goal is to send HDMI CEC commands from a standard (i.e non-system) app running on an Android box equipped with Pulse-Eight's USB dongle.
Following these instructions I successfully managed to compile libcec for Android and execute it as root on the box, with this command:
echo <my-cec-command> | cec-client -s /dev/ttyACM0
where /dev/ttyACM0 is the device file created by the system when plugging the dongle.
However the permissions of this file prevent the command to be executed by a non-root user (therefore it cannot be executed from my Android app).
On the other hand the app can actually access the USB dongle via the USB Host API of the Android SDK (provided the user grants the permission) and can even be wrapped into a USB serial controller with UsbSerial library.
But I don't see any way to make the bridge between the connection provided by Android's USB Host API and libcec/cec-client. Do you have any idea or suggestion?
The best solution that I have found so far is to use USB Host API + UsbSerial library to read/write CEC packets on the adapter's serial port with pure Java code (no embedded libCEC).
I did some retro-engineering on libCEC to find out the appropriate commands for basic operations like switching TV on & off and setting active source.
And I finally came up with the following UsbCecConnection java class: https://gist.github.com/sdabet/ac4d7711d1a529806cb7b695530b1fac

Sniffing/logging your own Android Bluetooth traffic

I recently bought chinesse device that connects via bluetooth with android phone / tablet. Since there is no application availible for windows / linux I want to create one for personal usage.
Usually phone connects to the device and exchanges some data. I connected PC to the device and looked into serial debugger and menaged to discover the protocol (one way only). Phone sends only one command to the device. But this time I'm not able to find out what it containts.
Is there any software that will allow me to look into data sent via bluetooth? I tried decompiling the app, but it looks really unfriendly.
Thanks.
Android 4.4 (Kit Kat) does have a new sniffing capability for Bluetooth. You should give it a try.
If you don’t own a sniffing device however, you aren’t necessarily out
of luck. In many cases we can obtain positive results with a new
feature introduced in Android 4.4: the ability to capture all
Bluetooth HCI packets and save them to a file.
When the Analyst has finished populating the capture file by running
the application being tested, he can pull the file generated by
Android into the external storage of the device and analyze it (with
Wireshark, for example).
Once this setting is activated, Android will save the packet capture
to /sdcard/btsnoop_hci.log to be pulled by the analyst and inspected.
Type the following in case /sdcard/ is not the right path on your particular device:
adb shell echo \$EXTERNAL_STORAGE
We can then open a shell and pull the file: $adb pull
/sdcard/btsnoop_hci.log and inspect it with Wireshark, just like a PCAP
collected by sniffing WiFi traffic for example, so it is very simple
and well supported:
[source]
You can enable this by going to Settings->Developer Options, then checking the box next to "Bluetooth HCI Snoop Log."
Also, this might help finding the actual location the btsnoop_hci.log is being saved:
adb shell "cat /etc/bluetooth/bt_stack.conf | grep FileName"
On a Xiaomi phone with Android 11, after enabling "Bluetooth HCI Snoop log" in developer settings the file seems to be written to
/data/misc/bluetooth/logs/btsnoop_hci.log (only accessible with root)
/sdcard/MIUI/debug_log/common/com.android.bluetooth/btsnoop_hci.log
In addition, it's possible to get the log by running adb bugreport zipname from the computer, as written here.
Note that the logging only turned on after a reboot for me.
On Xiaomi Redmi Note 9s
This configuration file can also be found /storage/emulated/0/MIUI/debug_log/common
named as hci_snoop20210210214303.cfa hci_snoop20210211095126.cfa
With enabled 'Settings->Developer Options, then checking the box next to "Bluetooth HCI Snoop Log." '
I was used Total Commander for taking file from Internal storage

Send file to computer system using USB

I have such requirement in which i have to transfer file on computer system, lets consider windows PC.
What i want to do is i have one screen with specific details,i am writing that values in one text file, now if user clicks on button then that file must be copied to computer at specific location using USB.
I have tried to search about this but didn't get anything useful.I've also refer below link
http://developer.android.com/guide/topics/connectivity/usb/host.html
Is it possible in Android, how do i communicate with windows system ?
Regards
UPDATE :
I am able sopy files to Computer using adb
./adb -s emulator-5554 pull /sdcard/juned.jpg /root/juned/android_usb/
but can i do same thing from android application ?
I think your question is not very specific to be answered. But to explain a bit consider the following:
you have to turn your android device in USB host mode so that it enumerates connected USB devices
establish a connection to your receiving device. Probably this is going to be a storage or drive with a known configuration of endpoints
when established, use a function like bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length, int timeout), which is documented as well in the link you provided. Keep in mind to choose the correct endpoint (direction TO your storage / drive)
This is just a sketch to get you started. It's clear that there is a lot more to do..
USB is probably not very suitable for what you want to do.
USB is asymmetrical, that is, a USB connection has a host at one end and a peripheral device at the other end. (For example, when you plug a USB stick into a PC, the PC is the host and the stick is the peripheral.) The host initiates and controls data transfers.
An Android phone generally acts as a peripheral device. As of Android 3.1, the phone can also act as a USB host, though not all phones support this.
In order to accomplish what you have in mind, the PC would need to run a piece of software that changes it from host mode to peripheral mode, and exposes some kind of storage that the Android device could then write to.
Maybe Bluetooth is a better option for you. You could just initiate a file transfer over Bluetooth as soon as the file changes. Inexpensive USB Bluetooth dongles are available for PCs without Bluetooth support. You might still need some software on your PC if you want to automatically accept the file transfer request on the PC.

Trouble connecting Android app to OS X through bluetooth Serial Port Profile

I'm attempting to connect to a Bluetooth port on my MacBook Pro (OS X v10.8 "Mountain Lion") from an android app (Device Version 2.2 "Froyo").
Starting with the BluetoothChat example, I removed the server-side code (only need client), and updated for API Level 8 compatibility. I can pair fine, but then I receive an IOException: Connection Refused error on bluetoothSocket.connect().
I am using the standard Serial Port Profile UUID 00001101-0000-1000-8000-00805f9b34fb, and I verified that it was supported using reflection, as show in
The Missing Manual: Android Bluetooth RFCOMM
After doing some research here on Stack Overflow and on the Google Code Forums
I tried using reflection to get a socket, which gives me the same result.
I've tried playing around with the Bluetooth port settings in OS X, but I can't find any documentation on them, and I have no idea what options I should set.
I have checked "Discoverable" in the main preferences panel:
I found the Serial Ports Menu, which is hidden by default. First you have to click options->Show More Info. Then Click options again, and you should see "Edit Serial Port...". I have no idea what to set here:
There are more serial port settings in the Advanced pane:
Anyone have any experience with this, or know what these options mean?
Edit
I'm running Serial Communication in OSX Terminal on all ports returned by ls /dev/tty.*. As shown in the link, I basically use screen /dev/tty.<port name> <datarate>
I've been using 9600 for the datarate, although I don't know if it matters.

Android 2.2. How to set up serial port(com,rfcomm) port?

I a trying to connect my Nexus One with Android version 2.2.1 with my pc and use a terminal program such as windows terminal or hyper terminal to communicate. To do this I believe I need to set up an outgoing serial com port. I have paired the devices. When I go on my PC to Bluetooth -> settings -> "add com port" the android device does not display.
What am I missing?
Does android 2.2.1 support spp? The documentation says it does.
Do I need to root the android to add spp?
Has anyone succeeded in this?
My final goal is to write an android app that communicates with an old school bluetooth device that requires com ports? Getting the android to communicate with the pc is an interim step.
I have tried everything I can think of in my android app to connect to my pc and android device but have not been successful. My android app is essentially the same as Serial over Bluetooth submitted by xCaffeniated but with fewer comments. Any suggestions?
Try beginning with the BluetoothChat sample application. You will then have to alter the UUID used to the generic SPP UUID,
00001101-0000-1000-8000-00805F9B34FB
From this point you pretty much have everything you need.
I have had issues pairing in the BluetoothChat program. So I was required to pair to my computer using the settings menu and then entering the BluetoothChat Program. In BTChat go to the menu and hit connect to a device, choose your computer. I can only speak for windows XP SP3 which is what I'm using. At this point on my machine I receive a task bar pop up asking me if I would like to allow my device to connect as a serial port. I allow it to. Now your phone is associated as the serial port profile on the computer, which you can associate with a specific com port.
Based on bluetooth spec,
http://www.bluetooth.com/SiteCollectionDocuments/SPP_SPEC_V12.pdf,
2.3 User Requirement, "... Any legacy application may be run on either device, using the virtual serial port as if there were a real serial cable connecting the two devices (with RS232 control signalling)." In 4.3 Remote Port Negotiation, "...There is a requirement to do so if the API to the RFCOMM adaptation layer exposes to those settings (e.g. baud rate, parity)... RFCOMM as such will not artificially limit the throughput based on baud rate settings,..."
In my opinion, since Android (2.2) offers no APIs to set up and open a serial port, they may not be necessary as long as you can discover the remote BT device and make a connection to it. I have tried it and it seems working with:
...
sock = device.createRfcommSocketToServiceRecord(myUUID);
sock.connect();
...
where final UUID myUUID= UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); You may need to take care of Bluetooth Permission and Setup in your application as described in
http://developer.android.com/guide/topics/wireless/bluetooth.html
There might be some issues with the connect() call, i.e. Service is not available or connect is refused, which could be resolved by making sure:
The remote BT device be discovered, and
It must be set to use PIN code (for instance 0000), and
It must be paired successfully with your Android device
These steps must be completed prior to running your application (which has connect call).
Hope this help.
George
There is definitely some funny business regarding how the AT set is implemented on the AOS. The problem is that it is hard to know if you're actually talking directly to Modem or through several abstraction layers (more likely). For a best up-to-date review of the AT Commands available on the AOS platform, plus HW, please see the post:
"How to talk to the Modem with AT commands"
http://forum.xda-developers.com/showthread.php?t=1471241

Categories

Resources