View Full Version : Bluetooth again
lopez1de
09-28-2008, 01:25 PM
Hi folks,
my question is: Is it possible to directly create a bluetooth connection between two devices with ppl, or is it only possible with a PAN?
Because not all Bluetooth drivers support PAN. It would be nice to support PAN on PC from within PPL.
For PPC I have a simple WM6BTPAN.exe which bring support PAN to WM6, even if the driver isn't supporting it. Just create a pair and start WM6BTPAN.exe on pc. Now the Wm6 device is able to accept pan connections!
I'm not the author of this software (WM6BTPAN.exe). I got it from xda-developers. This is the source:
http://forum.xda-developers.com/showthread.php?p=1571776
Another way to activate PAN profile (tested on WM6 from me) is changing the registry:
http://forum.xda-developers.com/showthread.php?t=358638
Please give me some hints on how to establish a PAN with PPL (even if the PC BT driver have no PAN profile).
thanks.
Nicknack
09-28-2008, 05:44 PM
as far i know, nobody has released any code for a etablished bluetooth connection until now.
only mike has written a small program for tcp connections, but he hasn't published this in open code yet.
despite the fact i don't even know how to connect in a pan sever, i can't imagine to connect without it, because in a pan the different devices has ips and with a serial connection you have only that bluetooth address, but ppl methods need a real ip.
i also think that ppl can't activate bluetoth itself, so you have to set up the pan or the serial connection on your own, before running any code.
Mike Halliday
09-29-2008, 05:47 AM
It should be possible to connect to a) a pan server and b) direct to a device using sockets.
I will dig out my tcp socket code and post it in the forum to see if that helps you.
Connecting to Bluetooth should be easy - The only thing you need to know is the COM port on both machines where the bluetooth is connected, then open a socket to that port and send/receive data.
Check back for my source code.
Thanks
Mike.
Mike Halliday
09-29-2008, 08:24 AM
Here, as promised is the code to do the following;
PC 1 - Server
Wait for a connection from the client, then mirror the display of the client.
PC 2 - Client
Connect to the waiting server, and then send X,Y co-ords of the mouse to the server.
Pretty crude code, but it shows how to establish connections and send/receive code.
Hope this helps.
(This should be easily converted to bluetooth).
http://www.4shared.com/file/64907939/84221678/Client_Server.html
Nicknack
09-29-2008, 09:24 AM
Many thanks mike! i will try it out with bluetooth right away :)
edit:
ok one problem solved, as you can read in kornalius ppl 1.52 thread,the search function was changed actually ("- Changed Search() function to Search(expr$, string$) -> string$"). i do it now this way:
data$ = SW_Receive(cl_sock$, 7);
strtoarray(data$, ":", st$);
Mx$ = st$[0];
My$ = st$[1];
lopez1de
09-29-2008, 03:55 PM
Sounds really good.
Maybe this article is a nice documentation how to setup bluetooth winsock.
http://www.developer.com/ws/other/article.php/10949_3640576_2
First you have to enumerate the devices to get the adress. then list services and so on...
In the moment this is a bit to tricky for me. I'm a C beginner. But it would be nice if one of you will get this running. :-)
Mike Halliday
09-29-2008, 04:54 PM
That is a good link, but I am having a hard time understanding the enumeration bit on page 1.
If any of you get this converted to PPL, please submit it so we can all use bluetooth via PPL.
A tutorial would be good on how it was converted from the link supplied into PPL, then we can follow the conversion process.
Nicknack
09-30-2008, 10:05 AM
yeah that's right, it should be easy, but Mister Pushvar Error at SW_Connect is still the winner :(
the only way to get him is to connect from desktop as client to ppc over wlan, since the client works fine on desktop and the server code on ppc.
lopez1de
10-04-2008, 01:40 PM
This is another good starting source for coding BT with C++
http://msdn.microsoft.com/en-us/library/aa362932.aspx
And I have VS2008 with all the header and libs for Bluetooth installed. Maybe you want to have a look at it? Please PM me.
lopez1de
10-04-2008, 01:57 PM
And some more...
http://mobile.liveshere.net/articles/viewarticle.php?id=19
http://www.codeproject.com/KB/winsdk/BluetoothAPI__Device_Enum.aspx
lopez1de
10-04-2008, 02:05 PM
This one looks very promising. He explained why not using Bluetooth API from VS and code your own with C++
http://www.lenholgate.com/archives/000102.html
lopez1de
10-08-2008, 02:44 PM
I spend some time into bluetooth. On my way I got lost in compling/debugging this code:
#include "winsock.ppl"
proc main
local(wsd$,sa$);
struct(wsd$, WSADATA);
WSAStartup (MAKEWORD(1,0), &wsd$);
socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
struct(sa$,SOCKADDR_BTH);
memset(&sa$,0,sizeof(sa$));
sa.btAddr$ = {00178357e2b2};
end;
My pc can't parse this code.... :confused:
To run this you need a new define in winsock.ppl
#define SOCKADDR_BTH {"addressFamily", USHORT, "btAddr", BTH_ADDR, "serviceClassId", GUID, "port", ULONG}
the parsing stops at this line:
struct(sa$,SOCKADDR_BTH);
Maybe we have to define BTH_ADDR too. But I don't know how to define this in ppl:
typedef ULONGLONG BTH_ADDR, *PBTH_ADDR;
A ULONGLONG is a 64-bit unsigned integer (range: 0 through 18446744073709551615 decimal). Because a ULONGLONG is unsigned, its first bit (Most Significant Bit (MSB)) is not reserved for signing.
Another structure to define is GUID
http://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx
typedef struct _GUID {
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8];
} GUID;
please support me...:rolleyes:
this code is based on this article: http://msdn.microsoft.com/en-us/library/ms881660.aspx
lopez1de
10-09-2008, 08:52 AM
I found another way (@xda developers) to make a WM5/6 ppc accapting PAN connections.
You only have to set the following registry settings:
http://forum.xda-developers.com/showthread.php?t=358638
This is tested by me and runs well.
The only thing we have to do now is: Starting a PAN from the client side (PC). In the moment a try to wrote a simple C++ (VS) command line tool to start pan. But the BT API from MS is not well documentated. I can't find anything on how to start the PAN. Well, it works with Mouseklicks but not programatically. :(
kornalius
10-09-2008, 11:05 PM
Thank you for all the time you spend on this and all the documenting you do with it. I would love to help you, however I don't know anything about bluetooth on the internal.
lopez1de
10-10-2008, 02:11 PM
Ok, finally...It's not documented how to establish a PAN connection with BNEP on windows. Listing BT devices and services and open a socket isn't the whole deal when using PAN. :( And you have ever to deal with the diffrent BT Stacks. They are all totally different.
Found this in another forum:
PAN is very different than DUN. DUN uses RFCOMM, which CE 4.2 provides an API for, as mentioned above. PAN uses BNEP, which is Bluetooth Network Encapsulation Protocol, which, like RFCOMM, is a layer on top of the L2CAP layer. The trouble is, CE 4.2 does not provide a BNEP layer or expose any API to send or receive packets at the L2CAP layer. At least, not a documented API. I'm sure there is one in there somewhere. Assuming one can get past that, then it would still be a lot of work to implement BNEP and then PAN, but it would be doable and I'd likely take a stab at it.
I also looked at implementing the BT LAN profile, which was in version 1.0 of the spec but is deprecated as of 1.1. BT LAN is simply PPP over RFCOMM, so it is doable in CE 4.2. Still a lot of work though. It would take a PPP implementation, DHCP server, and NAT'ing. Of course there are open source versions of these things in existence but porting them to Windows CE would probably not be easy, it might be better to just reimplement the minimal required functionality from scratch. Authentication would not be required since one can assume if a device is paired, it's trusted. Of course there are hacks for that, but let's not go there.
Maybe I will invest some more time later on connecting via com ports. This is a better and much easier way to communicate with BT.
For my project I dicited to go another way. With an Autoit script it's possible to auto connect a PAN by virtually clicking all the standard forms. I know this isn't the best way. But I need a direct TCP/IP connection with BT, to make my app working with WLAN also.
:rolleyes:
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.