I am trying to emulate this app - Wifi Direct sensors (https://play.google.com/store/apps/details?id=esnetlab.apps.android.wifidirectsensors)
I have gone through the demo of wifi-direct from android samples.
I am able to get sensors data on a individual device, but i need to get them from the peers in a wifi-direct group.
So I wanted to know if someone could suggest on how to go about the design/process of getting the sensors data from 'remote sensors' on one device (as shown in the screenshot of that app).
There are basically three components you are going to need...
If you're going to want to plot the results, need a plotting library like Androidplot.
You're going to need to establish a Wi-Fi direct connection between the devices. There is sample code for this in the android SDK, but it isn't in the newest SDKs, I think it's in levels 14 to 18, or something like that. In the samples, they show you how to open a socket connection and send a file. You just need to leave the socket connections open.
The sensor event class is not serializable, and I think its constructor is either protected or private. This makes it difficult to send over a socket since it is difficult to reconstruct the sensor event on the peer. A library like Gson might help with this, but an easier way would be to pick a subclass of information that is important to you and to just send that info.
What you want to do will be a lot of work.
Related
For mobile development i woud like to move something on the screen on a mobile device and on another mobile device you see the same object moving.
What would be my best option to use to exchange this data? I thought about firebase but the problem is you move the image alot of times so you easily get to the 50000 limit within an hour. also the fact that saving an position is abit odd to do in a database.
My second option would be using netty framework. I thought about using their socketstream option. My question about this is, my school stresses the use of an api between data exchange but is that also possible here? or is that more for webdevelopment?
In summery, What would be the best option to use for data exchange if you need to send alot of small request. If you sockets/nio framework is it normal to put an api between the client and server?
I thought about firebase but the problem is...
You don’t need a database because you don’t want to save the object’s position. This data is not valuable to you (right?).
You need to pass data from one device to the other to see the object moving. This can be done by establishing a network between these two devices. This can be done using sockets.
If you sockets/nio framework is it normal to put an api between the
client and server?
If this API use sockets under the hood to simplify a client/server implementation for example then it’s not a good idea to use sockets. They’ve already being used by the API.
On the other hand if the API does need socket implementation from your part to be used correctly, like the android Bluetooth API, then yes it’s normal.
Your use case
You can do this by connecting the two devices on the same network and transmit freely any data you like.
If this network doesn’t need to be the Internet then you may want to transmit data over
Bluetooth
WiFi p2p
or your local WiFi using NSD
For these and more see Android Connectivity.
I am creating a multiplayer android game as a part of my coursework. This is my first game. I intended to allow users to connect to the game over a simple network. I don't want to use internet at all hence I wont be using the android game services. How do I go about this. I have no clue at all. I have tried various tutorials but all of them are using a central game server. I just want to create a simple Client - Server network. One user will host a game and others will join.
it's my first time answering a question here. I usually just read here in stackoverflow. I'm also currently working on my first game. It connects devices using wifi peer-to-peer or WifiDirect (without a wifi hotspot). It requires high version of android OS (4.0 or 4.1?) but I believe you can also try the other way on which the devices needs to connect in the same wifi hotspot for lower OS version requirements. The latter, I haven't tried yet.
After I connect the devices on the same network (peer-to-peer), I use sockets to exchange data between them. I use serializable objects for sending data. I don't know if it's the best way but it works for me.
My game can connect more than two players in wifi peer-to-peer. One device acts as the network owner (and also the game server).
See android's tutorial/documentation for WifiDirect connection :
http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html
Be sure to read also the adjacent lessons.
Also, Sockets must be used with Threads so you also need to read about it if haven't.
Hope I helped ^^
I finally got the solution and made the Android application. Simply used java socket programming. It works on Hotspot. This works on client - server framework.
Please find the code here and contact me if you require any assistance.
https://github.com/rohitramkumar308/GameOfCards
and this is the link to the app
https://play.google.com/store/apps/details?id=srk.syracuse.gameofcards
Hope this helps you.
I have a project idea which is suggested by my lecturer to create an ad-hoc mobile network using WiFi-direct available in android mobile phones. the purpose of this network is to send data over a long distance from one android device to another using several other android devices as intermediate nodes and also to use a MANET routing protocol for path selection when there's more than one path available to reach the destination.
I have looked into some of the questions related to this where some have asked how to implement a similar type of network but most of those answers were pretty old at which time WiFi-direct was not available widely, as I assume.
I'm pretty much new to android and I'm learning it now for this purpose. so I would like to know weather this can be done using an android app, some guidelines to start if possible and any sample codes i can refer to get this done.
Thank you in advance.
Well you could use socket server and socket client technology to share data between devices in the same network which is definitely not a long distance thing. For long distance, you have to use internet to send and receive data because socket servers/clients cant connect devices in other networks. I am not sure how its gonna work but Good luck!
I am student and currently working on a project for my university. I am trying to write an app which is capable of reading date by using the TUSB3410(http://www.ti.com/product/tusb3410) and its USB to connect it with the C2500(http://www.ti.com/product/cc2500) connected via UART. Something like USB to serial.
I can get information off the TUSB3140 like its vendor id or its endpoint so I can use the normal USB API. But it is rather tricky to receive the information of the cc2500. I don't know which methods I should use or which parameter are correct. So maybe you have an idea how the methods like controlTransfer() etc. should look like.
I hope you can help me with this problem!
I'm afraid the answer isn't quite as simple as all that.
According to the linked datasheet and associated documentation, the TUSB3410 is not a fixed function device. It's basically a USB device on one side, a UART on the other side, and an MCU applications processor in the middle. In order for that chip to do anything useful, it has to have a firmware application loaded into it to govern how the data moves from one side to the other. So you get to define in the firmware how the data moves through the USB (interrupt transfers, bulk transfers, etc.) and that will govern how an Android application interacts with it.
Also, the chip does not seem to support having its firmware burned in, it always loads the firmware externally from I2C EEPROM or from the USB Host. If your device setup does not already have the EEPROM on it, you will likely have a difficult time because the Android USB APIs don't really give your application access to the device during the enumeration process, which is when the firmware would need to be sent if downloaded from the Host. It also would require you to detect your device twice (once with the standard bootcode VID/PID, and once again after the firmware file takes over and the device reconnects to the bus).
If you are just looking for a simple embedded implementation to get UART, SPI, etc. data into an Android application, you are probably better off with something like the FTDI FT311, which implements the Open Accessory protocol and comes with library code to get you started on both sides of the equation: http://www.ftdichip.com/Products/ICs/FT311D.html
EDIT: From your comment
So if your device conforms to the CDC USB Device Class, then there are basically three points of interest:
Every device has an "endpoint 0" for configuration, and this is accessed in the Android APIs using the controlTransfer() method. CDC devices use this endpoint for changing items like baud rate, stop bits, etc.
CDC Devices like a VCP have two interfaces, one for communications and one for data. The data interface (usually enumerated second) has two bulk endpoints (one in and one out) where the serial data is usually transferred. You can transfer the data back and forth on those endpoints with the bulkTransfer() method, or using an asynchronous UsbRequest.
As a starting point, perhaps take a look at the source of this open source project, which implements CDC basics using the host APIs. You should be able to get a good idea of how to roll your own driver from there (specifically the CdcAcmSerialDriver):
http://code.google.com/p/usb-serial-for-android/
I think apart from the FT311D which is using the AOA protocol, you may also consider to use FT231X, via FT231X, you can use the APK of android hyperterminal which you can easily find in google search/ google play. This is using by OTG method. You may also have a look.
Here's the scenario:
I need to write an application for Android to create a RFCOMM socket to a PC with a Bluetooth dongle (I'm going to write the server too).
My requirement is that the user doesn't have to pair device manually.
Actually, with a big hack, I'm using the createInsecureRfcommSocket.
A little scenario: I've an Android application which exchanges information with a Linux box with a RFCOMM socket opened. I can manually set the PIN on the devices (hard coding it IS an option)
I'm looking for different roads:
Write a JNI wrapper
As has been done here by Max Kellermann, I can write a JNI layer to make all the pairing phase. This should be a good option, but there's a problem:
The NDK 4b does not provide libbluetooth libraries, so -lbluetooth fails, as well as the NDK v.3.
Options:
Find the NDK 1.5 (which includes lib bluetooth). After days of web search I've been not able to find out. Anyone has or knows where I can find it?
Compile libbluetooth for Android by myself and use them for -lbluetooth. No lucky there, I'm not able to build them. Any hint?
Use something exposed by the APIs
Any one know how can I use createRfcommSocketToServiceRecord and have the user not to manually pair the device? Is it possible? How should I write the server?
Something I do not know
Maybe (sure!) there is something I do not know. Maybe I can use something else? Not RFCOMM? SDP?
Maybe I can manually pair with the Android API?
I hope to have been clear enough, if not just ask. And again, as it's not the first time, I'm in your hands :)
Thanks for all the support guys!
At the end, I can say that you can't.
Even if you find a way, using wrappers, writing C modules and so on, android evolution will probably change the thing you're using.
And so, there's no option. Sadly.
Let's see how Android Bluetooth API will change in the future.
Yes we can create it Rfcomsocket and listen the socket without user concerns and also without pairing devices.
https://code.tutsplus.com/tutorials/create-a-bluetooth-scanner-with-androids-bluetooth-api--cms-24084
Follow this !!
The Android Bluetooth API is not finalized, and will change. Use at your own risk. This class implements an API to the Bluetooth RFCOMM layer. An RFCOMM socket is similar to a normal socket in that it takes an address and a port number. The difference is of course that the address is a Bluetooth-device address, and the port number is an RFCOMM channel. The API allows for the establishment of listening sockets via methods bind, listen, and accept, as well as for the making of outgoing connections with connect, connectAsync, and waitForAsyncConnect. After constructing a socket, you need to create it and then destroy it when you are done using it. Both create and accept return a FileDescriptor for the actual data. Alternatively, you may call getInputStream and getOutputStream to retrieve the respective streams without going through the FileDescriptor.