The connection call pulses are controlled by the iOS and during debugging the connections are slow but usually, with the devices alone, connect quickly.
There were a couple of typos as mentioned although no big deal. The only time I got EXC_BAD_ACCESS is when trying to send data when not connected or something like that.
Although now it works fine and here is a non-tested GLB code sample of what I have so far:
TYPE _data
connected
connected_last
data_recv$
data_send$
session_id$
peer_id$
self_id$
master
toggle
time
ENDTYPE
GLOBAL tooth AS _data
bluetooth_main()
FUNCTION bluetooth_main:
LOCAL time$
tooth.session_id$ = "01"
GLB_iBT_Init()
GLB_iBT_Start(tooth.session_id$)
tooth.connected = GLB_iBT_Connected()
WHILE NOT tooth.connected
PRINT "Connecting", 1, 1
SHOWSCREEN
tooth.connected = GLB_iBT_Connected()
WEND
tooth.peer_id$ = GLB_iBT_PeerID()
tooth.data_send$ = "PEERID:" + tooth.peer_id$
GLB_iBT_Send(tooth.data_send$)
time$ = MID$(PLATFORMINFO$("TIME"),11,8)
WHILE tooth.connected
tooth.data_recv$ = GLB_iBT_Recv()
tooth.data_send$ = "TIME:" + time$
GLB_iBT_Send(tooth.data_send$)
recv_data()
PRINT "LOCAL TIME:" + time$, 1, 1
PRINT "REMOTE TIME:" + tooth.time$, 1, 20
SHOWSCREEN
WEND
GLB_iBT_Close()
ENDFUNCTION
FUNCTION recv_data:
LOCAL match$
tooth.connected = GLB_iBT_Connected()
IF tooth.connected
tooth.data_recv$ = GLB_iBT_Recv()
IF tooth.data_recv$ <> "NO_DATA"
match$ = left_match$(tooth.data_recv$, "PEERID:")
IF match$ <> ""
tooth.self_id$ = match$
IF tooth.self_id$ < tooth.peer_id$
tooth.master = MASTER_LOCAL
ELSE
tooth.master = MASTER_REMOTE
ENDIF
ENDIF
match$ = left_match$(tooth.data_recv$, "TIME:")
IF match$ <> ""
tooth.time$ = time$
ENDIF
ENDIF
tooth.data_recv$ = "NO_DATA"
ENDIF
ENDFUNCTION
FUNCTION left_match$: word_data$, match$
LOCAL length1 = LEN(word_data$)
LOCAL length2 = LEN(match$)
LOCAL result$
IF LEFT$(word_data$, length2) = match$
result$ = RIGHT$(word_data$, length1 - length2)
ELSE
result$ = ""
ENDIF
RETURN result$
ENDFUNCTION