I am new to the J2ME technology. And I am making an application which will transfer the text and image(downloaded through http and stored into an ImageItem of a form) from a client mobile to the server mobile using bluetooth. The connection used is SPP. I have succeded to transfer the text message. But I am unable to transfer the image.
Can anyone help me to transfer the image to the server mobile through bluetooth directly without saving it into the phone memory or memory card.,
I would be thankful to you.
javax.microedition.lcdui.Image.getRGB() is the method you are looking for.
If myImageItem is your ImageItem object, the code would look like this:
------------
Image myImage = myImageItem.getImage();
int[] myImageInts = new int[myImage.getHeight() * myImage.getWidth()];
// Beware of OutOfMemoryError here.
myImage.getRGB(myImageInts, 0, myImageInts.length, 0, 0,
myImage.getWidth(), myImage.getHeight());
------------
You can then convert each int in the array into 4 bytes
(in the correct order please)
and feed these to your Connection's OutputStream.
Alternatively, DataOutputStream.writeInt() does the conversion for you.
Well if your server mobile is using Bluetooth and also running an application written by you, then you can create your own protocol to do this.
For image transfer, it is best to send the bytes that were downloaded over HTTP (and used to create the ImageItem), then receive them at the server end and display in the same way.
What is the specific problem you're encountering while doing this?
funkybro
As funkybro suggested, you can use the bytes to transfer the image to the server mobile. For that you need to can just open the output stream of the connection that you have made to the bluetooth server mobile and then write the byte contents on to the output stream.
Related
I have a use case for connecting with a arbitrary bluetooth device (not a scanner). I have the following questions -
Is it possible to connect data wedge to a random bluetooth device to send and receive data? I was unable to find any example online in docs or elsewhere. The idea is that the bluetooth device will dump data to its outputstream, and i am hoping data wedge can pick it up and insert in my app field.
Can data wedge also send requests to the bluetooth device? ( Or can it only be a listener and receive data? ) If yes, how to we configure the request string and frequency.
In our use case the data is a long string (eg - "a,b,c,d"). My idea is to send this string to a text field and then segregate it in application itself.
Our use case is for TC 56 devices. As i understand it, the application app listens for the intent data wedge generates post scanning. Can it work seamless on laptops as well? The service in our use case is a web app.
I have an app that communicates with a bluetooth device, and I'm trying to replace that app with some code.
I tried using C# InTheHand nuget, Microsoft's Bluetooth LE Explorer, python's sockets and others to send data and see what happens.
But there's something I still don't understand - in each way using different libraries I saw in wireshark a different protocol: ATT, RFCOMM, L2CAP...
When I sniffed my bluetooth traffic from my phone using the app mentioned before, I saw mostly HCI_CMD protocol traffic.
How can I choose the protocol I want to send? Is there a simple package for that? something to read?
Do I need to build the packet myself? including headers and such?
Thank you!
Update:
Using Microsoft's Bluetooth LE Explorer I was able to send a packet that lit up my lamp, starting with 02010e10000c00040012(data)
Using bleak I was able to send a packet starting with 02010e10000c00040052(data)
the difference makes the lamp not ligh up and I'm not sure if I can change it via bleak as it's not part of the data I send
I think what you are showing is that bleak does a write without response while MS BLE Explorer does a write_with_response.
Looking at the Bleak documentation for write_gatt_char that seems to be consistent as response is False by default
write_gatt_char Parameters:
char_specifier (BleakGATTCharacteristic, int, str or UUID). The characteristic to write to, specified by either integer handle, UUID
or directly by the BleakGATTCharacteristic object representing it.
data (bytes or bytearray) – The data to send.
response (bool) – If write-with-response operation should be done. Defaults to False.
I would expect the following to have the desired effect:
await client.write_gatt_char(LIGHT_CHARACTERISTIC, b"\x55\xaa\x03\x08\x02\xff\x00\xff\xf5", True)
I want to open an image and send it and send to the sockets that are connected in my nodejs server.
The problem is when I'm trying to send some image via socket.write(myImage); because the method write() can't send it as an image object. The "solution" that i've found is to create a buffer from my image, copy in another buffer and parse it to a base64 encode and send this using socket.write(myBase64Img), receive it in my Qt client and decode that image with openCV. the problem is that this is very expensive. There is another way to send my image via TCP sockets?
PS: I can't send the URL of the image, I want to send the image.
Thanks!
You should be able to write the raw image data to the socket without base64-encoding it, just pass a Buffer containing that binary data to write(). You could also stream the data if you don't have the image completely in memory already since that would help save on memory usage.
Assuming that you're dealing with an image that is already on disk, the right way to do this is to stream the image directly from disk to the socket.
var stream = fs.createReadStream(filePath);
stream.pipe(socket);
See the docs for details:
fs.createReadStream
Stream#pipe
I have been trying to figuring out if it is possible to send files between a wp8 device and a windows rt (Surface). Some people seem to write that this is possible but they never write how to do this.
So what I want to do is 1. record a video with my app on the wp8 device and save it to the isolated storage (this is where Im at, at the moment) 2. Send the video (approx 20min recording time) to my windows rt device 3. Play the video on the rt device. Step 1 & 3 are simple but step 2 is driving me crazy. I have been thinking about using Bluetooth but as the speed is just around 700kbit/s it will take forever to transfer it. Usb is a no go as it is in the isolated storage. Skydrive needs 3g. So what I am thinking is to start internet sharing on my wp8 device and then connect my windows rt device to it and when its done use wifi to send the video from wp8 to win rt.
Is there any way this could work or is this impossible?
If your devices are in the same Wi-Fi network, you can use it to send files. Glossing over the details, this could be achieved in two steps:
Make devices discover each other in the network (they should know each other's ip addresses).
Implement file sending over a tcp socket. The simplest approach is to split the file into chunks of some arbitrary, but small size, and send those chunks one after another.
Of course, it's a high-level description, so if you need some further help in topics mentioned above, feel free to ask.
EDIT: This url says that there's a possibility to listen to incoming network connections, because related class is available for Windows Store apps and for Windows Phone 8. You can use it as a starting point.
EDIT 1: I've quickly put up an example for you, to prove it works. Just tested it on my Lumia 920.
Windows.Networking.Sockets.StreamSocketListener listener = new Windows.Networking.Sockets.StreamSocketListener();
listener.ConnectionReceived += async (_, args) =>
{
var w = new Windows.Storage.Streams.DataWriter(args.Socket.OutputStream);
w.WriteInt32(42);
await w.StoreAsync();
};
await listener.BindEndpointAsync(new Windows.Networking.HostName("127.0.0.1"), "55555");
var clientSocket = new Windows.Networking.Sockets.StreamSocket();
await clientSocket.ConnectAsync(new Windows.Networking.HostName("127.0.0.1"), "55555");
var r = new Windows.Storage.Streams.DataReader(clientSocket.InputStream);
await r.LoadAsync(4);
var res = r.ReadInt32();
clientSocket.Dispose();
System.Windows.MessageBox.Show(res.ToString(), "The Ultimate Question of Life, the Universe, and Everything", System.Windows.MessageBoxButton.OK);
Is this something you are trying to do in code?
What is your average file size - are we talking low-res 320x480 or HD-quality 720p+ video...?
What are your limitations? (Time, Connectivity, etc)
You could set up Dropbox to do the transfer. The free version is limited in space (more if you share), but if you moved the files into and out of Dropbox as necessary then you'd at least be able to set it and forget about it. This would still require a network connection, so if you need to do this on the go it may not be a good answer.
If this is something you need to do while on vacation at Disney World or camping or something like that it may not be a viable option.
I want to a Java ME application that transfers any SMS received to a PC using bluetooth. The PC can then direct the Java ME application via bluetooth to send a response SMS. Is there library available for this architecture or I have to design it myself?
Is this approach correct or a better one exists? I want to use bluetooth as then I will not have dependency on the cable.
You'll need to create this yourself, however you'll find that you can't do what you want with J2ME.
J2ME can't access any old SMS that the handset receives, only ones sent to a specific port upon which the MIDlet is listening. So to get all the other SMSes, create a bluetooth serial/dial-up connection to your handset in the way I've described in this answer.
Create a PC client which repeatedly issues AT+CGML commands (as described in the AT command set document linked to in the answer above), to see when an SMS has been received. Use AT+CGMR to read and parse the message text. Then use AT+CGMS to sent a response. This can all be done over bluetooth.
It's better to use the serial connection to send a response, because a MIDlet cannot usually be triggered to open based on incoming bluetooth data.
Hope this helps.
You may have already achieved your task, anyway for the reference I think it is much better if you try using Gammu . I'm using it for the same task (Send / receive SMS through PC ) with a simple bat file I have written, works like a charm.
Anyway you don't need any J2me program for this.
Wammu takes care of making the connection to phone and sending AT commands.