AIRi connecting as master to Android device

47 views
Skip to first unread message

Piotr Tomczyk

unread,
Aug 17, 2012, 8:22:32 AM8/17/12
to airc...@googlegroups.com
Hello,
I have some problem with connecting to Android. I used to connect my phone to AIRi like in Native-Android-AIRi and it was working fine. But now I want AIRi to connect to my phone. I modified code from tutorials, and from debugging I know that master function is executed with MAC address of my phone, but my Android bluetooth server is not getting any connections. On my server side I wrote code similar to this in Native-Android_AIRi (with reflection I'm using function listenUsingInsecureRfcommOn).
Camera and phone are paired and I can connect to camera with BASIC: A = slave ..., but camera cannot connect phone A = master $1 ($1 is my phones MAC).
Can you suggest me some server-side solution?

Juergen Kienhoefer

unread,
Aug 17, 2012, 12:57:55 PM8/17/12
to airc...@googlegroups.com
here is a nice master code you can use:
the comments should help you to adapt the code for your use.


@ERASE

0 REM this is a service master code. It will find a device that
0 REM matches a name and a MAC address filter.

0 REM Line $1 discovered device buffer
1 0

0 REM Line $2 stores the name filter
2 AIRmini

0 REM Line $3 stores the address filter
0 REM only connect to AIRcable devices
3 0025BF

0 REM pin code
4 1234

0 REM CABLE MODE slave address
8 0

@INIT 50
0 REM debug
49 Z = 1

0 REM PIN code
50 $4 = "1234"

0 REM blue LED output and off
51 A = pioclr 20
0 REM RS232 POWER ON out and on, PIO12 (5X: PIO2)
52 A = pioout 3
53 REM A = pioclr 3
54 A = pioset 3
0 REM RS232 POWER OFF out and on, PIO11 (5X: PIO10)
55 A = pioout 11
56 A = pioset 11
0 REM RS232 DTR pin out and on, PIO13 (5X: PIO4)
57 A = pioset 5
58 A = pioout 5

0 REM Sleep mode PIO10 (low no deep sleep) and Handshake PIO15 (high enabled)
59 REM A = pioout 11
60 REM A = pioclr 11
61 REM A = pioout 16
62 REM A = pioset 16

0 REM empty discovered device buffer
63 $1 = "0"

65 A = baud 96
0 REM E will be used for state
0 REM E = 0 disconnected
0 REM E = 1 connected
66 E = 0

67 A = zerocnt
68 G = 1
69 $0="AIRservice "
70 A = getuniq $10
71 PRINTV $10
72 A = name $0

0 REM button state variable
73 W = 0
0 REM check for button, virtual PIO17
0 REM PIO17 goes high when pressed no need to change PIO
74 REM A=pioirq"P00000000000000001"
75 RETURN



0 REM slave call idle, called only exactly once
0 REM call ALARM to get started
@IDLE 90
0 REM set DTR to -5V
90 A = pioset 5;
0 REM LED off
91 A = pioclr 20;
92 ALARM 1
93 RETURN



0 REM change for INDUSTRIAL or other with no button otherwise keep at ALARM 100
@ALARM 120
0 REM check for button pressed
100 A = pioget 17;
101 IF A = 0 THEN 120;

0 REM long press power down
102 ALARM 0;
0 REM wait until button release
103 A = pioset 20
104 A = pioclr 20;
105 A = pioget 17;
106 IF A = 1 THEN 103;
107 W = 3;
108 A = reboot;
109 FOR E = 0 TO 10
110 WAIT 1
111 NEXT E
112 RETURN



0 REM check if we need to start an inquiry (E=1 master connect was successful)
0 REM blink leds
120 IF E = 1 THEN 140
121 A = pioset 20
122 A = delayms 100
123 A = pioclr 20
124 ALARM 5
125 A = strlen $1
126 IF A > 11 THEN 140

0 REM check CABLE MASTER MODE
130 A = strlen $8
131 IF A < 11 THEN 135
0 REM do a master connect, no inquiries
132 GOTO 250

0 REM inquiry stopped because of master match, start again
135 A = inquiry 9
136 RETURN

0 REM check FTP service and disable
140 IF G = 0 THEN 150
141 A = readcnt
142 IF A < 60 THEN 150
143 WAIT 3
144 A = disable 3
145 G = 0
146 GOTO 150

0 REM we are connected, lets check we are still connected
150 A = status
151 IF A = 0 THEN 155
152 ALARM 5
153 RETURN

0 REM we were disconnected
155 $1 = "0"
156 A = pioclr 20
0 REM set DTR to -5V
157 A = pioset 5
0 REM red LED back to charger control
158 A = pioclr 19
159 A = pioin 19

160 ALARM 1
0 REM status disconnected
161 E = 0
162 A = unlink 2
163 RETURN




@INQUIRY 198
198 A = pioclr 19
0 REM when this interrupt gets called we have on $0 an string like this:
0 REM 00112233445566 NAME where the number is the bt address.
0 REM we need to check first if the addess is on our block of address
0 REM then if the name matches the filter
199 $6 = $0[13];
200 REM PRINTU $6
201 $5 = $0;


202 $0 = $6;
203 A = strcmp $2;
204 IF A <> 0 THEN 217;

0 REM check address match
205 REM A = strcmp $3
206 REM IF A <> 0 THEN 217

207 $1 = $5
0 REM found a match, do connect and kill other inq, show on red light
208 A = pioout 19;
209 A = pioset 19;

210 A = inquiry 0;
212 A = master $1;

0 REM save address to try
214 $9 = $1;
0 REM indicate that we have tried the master, reset variable
215 $1 = "0";

0 REM call for ALARM to check connection
0 REM we don't get an IDLE call when master failed
216 ALARM 20;
217 RETURN



0 REM CABLE mode connect
250 A = master $8
251 $9 = $8
253 $1 = "0"
0 REM found a match, do connect and kill other inq, show on red light
254 A = pioout 19
255 A = pioset 19
256 ALARM 20
257 RETURN




@MASTER 300
0 REM connected
300 E = 1
0 REM blue on
301 A = pioset 20

0 REM give back red LED and clear
302 A = pioclr 19
303 A = pioin 19

0 REM set DTR to +5V
304 B = pioclr 5
0 REM RS232_on high
305 B = pioset 3
0 REM save the address that was successful, ENABLE FOR CABLE MODE
306 $8 = $9
0 REM connect RS232 to master
307 C = link 2
308 RETURN



0 REM button press interrupt
0 REM work with ALARM for long press
@PIO_IRQ 400
400 IF $0[17]=49 THEN 410;
0 REM ignore button release on long presses for reboot
401 IF W = 3 THEN 403;
0 REM was it a release, handle it
402 IF W <> 0 THEN 420;
403 RETURN

0 REM button press, save state, start ALARM
411 W = 1;
412 ALARM 3
413 RETURN

0 REM short button release disconnects master
420 A = disconnect 1
421 A = pioclr 20
422 RETURN



@PIN_CODE 500
0 REM fixed PIN code
500 $0=$4;
501 RETURN

512 END
> --
> You received this message because you are subscribed to the Google Groups
> "AIRcable(tm)" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/aircable/-/5NdcKqflRWgJ.
> To post to this group, send email to airc...@googlegroups.com.
> To unsubscribe from this group, send email to
> aircable+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/aircable?hl=en.

Piotr Tomczyk

unread,
Aug 20, 2012, 9:22:03 AM8/20/12
to airc...@googlegroups.com
Thanks for your response. Is it possible to connect to Android device (which should be slave)? I don't get any incoming connections on my smartphone. To listen I'm using function listenUsingInsecureRfcommOn on channel 1. Is there any other way?

Juergen Kienhoefer

unread,
Aug 20, 2012, 11:35:37 AM8/20/12
to airc...@googlegroups.com
Sure you need a standard serial SPP service running on the Android.
There are many example codes that provide that.

Check that channel number again. It is not certain that it's always number 1
and that port is free. It could be that the DUN service is running there since
it was started before.

Hope that helps
Juergen
Wireless Cables Inc.
> https://groups.google.com/d/msg/aircable/-/x6l6vS9B9VcJ.

Piotr Tomczyk

unread,
Aug 22, 2012, 6:04:16 AM8/22/12
to airc...@googlegroups.com
Thank you for your support, now it's working as I wanted to. It was my fault, i had to create listening socket using listenUsingRfcommWithServiceRecord("SPP", UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));

Juergen Kienhoefer

unread,
Aug 22, 2012, 12:08:21 PM8/22/12
to airc...@googlegroups.com
Hi Piotr,
Would you be able to share your code with the community?
I think you did a very nice implementation that could get others going quickly
and you could benefit from the many more enhancements that others would
put in your code.
Thank you
Juergen
> https://groups.google.com/d/msg/aircable/-/StEycUvw4AwJ.

Piotr Tomczyk

unread,
Aug 23, 2012, 3:39:30 AM8/23/12
to airc...@googlegroups.com
Do you mean BASIC or java code?

Juergen Kienhoefer

unread,
Aug 23, 2012, 12:17:46 PM8/23/12
to airc...@googlegroups.com
whatever you can share

think about this, if you keep code for yourself you own it and you are
responsible
for any updates and maintenance.

If you open source your code, others can pick it up and make it better or
tell you about problems to improve it. Some may even enhance functionality.
If you want, I could publish your work (or link to it) on the AIRi
Support pages.

We try to make as much code available as possible.

Regards
Juergen
Wireless Cables Inc.
> https://groups.google.com/d/msg/aircable/-/TvLvc95akB0J.
Reply all
Reply to author
Forward
0 new messages