
36.
print("\nWelcome
to
the Serial Port Service (SPS) example!\n\n")
37.
print("\nRemember
to
setup the Peripheral dongle first so Central has something
to
connect
to
.\n\n
")
38.
39.
# Python
2
users
40.
# input = raw_input("Choose \n1)
for
Peripheral...
41.
role_input = input("Choose: \n1)
for
Peripheral Role\n2)
for
Central role\n>> ")
42.
while
not
(role_input == "
1
"
or
role_input == "
2
"):
43.
role_input = input("Please choose
1
or
2
.\nChoose: \n1)
for
Peripheral Role \n2)
for
Central r
ole\n>> ")
44.
45.
connected = "
0
"
46.
while
1
and
console
.
is_open
.
__bool__():
47.
if
role_input == "
1
":
48.
print("Starting advertising.")
49.
time
.
sleep(
0.1
)
50.
# Sends the commands
to
the dongle. Important
to
send the \r
as
that
is
the return-key.
51.
console
.
write
(str
.
encode("AT+ADVSTART"))
52.
console
.
write
(
'\r'
.encode())
53.
while
connected == "
0
":
54.
dongle_output = console
.
read(console
.
in_waiting)
55.
time
.
sleep(
2
)
56.
print("Awaiting connection
to
Central...")
57.
if
not
dongle_output
.
isspace():
58.
# We make sure it doesn't print the same message over
and
over again by resetting
[out]
to
blankspace
59.
# after printing once
and
check
for
blankspace before print again
60.
print(dongle_output
.
decode())
61.
if
dongle_output
.
__contains__(str
.
encode("\r\nCONNECTED.\r\n")):
62.
# Opens Serial Stream
63.
console
.
write
(str
.
encode("AT+SPSSEND"))
64.
console
.
write
(
'\r'
.encode())
65.
connected = "
1
"
66.
print("Connected!")
67.
dongle_output = " "
68.
elif role_input == "
2
":
69.
# This
is
what will be sent back
and
forth between the dongles.
70.
# You can change this message
to
whatever you like.
71.
msg = "Echo"
72.
# Sends the commands
to
the dongle. Important
to
send the \r
as
that
is
the return-key.
73.
console
.
write
(str
.
encode("AT+CENTRAL"))
74.
console
.
write
(
'\r'
.encode())
75.
time
.
sleep(
0.1
)
76.
print("Putting dongle
in
Central role
and
trying
to
connect
to
other dongle.")
77.
while
connected == "
0
":
78.
# Sends the commands
to
the dongle. Important
to
send the \r
as
that
is
the return-
key.
79.
time
.
sleep(
0.5
)
80.
console
.
write
(str
.
encode("AT+GAPCONNECT="))
81.
console
.
write
(str
.
encode(target_dongle_mac_address))
82.
console
.
write
(
'\r'
.encode())
83.
dongle_output2 = console
.
read(console
.
in_waiting)
84.
time
.
sleep(
2
)
85.
print("Trying
to
connect
to
Peripheral...")
86.
if
not
dongle_output2
.
isspace():
87.
# We make sure it doesn't print the same message over
and
over again by resetting
[out]
to
blankspace
88.
# after printing once
and
check
for
blankspace before print again
89.
print(dongle_output2
.
decode())
90.
if
dongle_output2
.
decode().__contains__("CONNECTED."):
91.
# Opens Serial Stream
92.
console
.
write
(str
.
encode("AT+SPSSEND"))
93.
console
.
write
(
'\r'
.encode())
94.
connected = "
1
"
95.
print("Connected!")
96.
time
.
sleep(
2
)
97.
# We wait a bit
then
sends the starting msg
to
the other dongle.
98.
console
.
write
(str
.
encode(msg))
Содержание BleuIO
Страница 1: ......
Страница 4: ...How to use Windows Step 1 Figure 1 Connect the dongle to your computer ...
Страница 7: ...Linux Raspberry Pi Step 1 Figure 1 Connect the dongle to your Linux RaspberryPi ...
Страница 14: ...Issues Showing advertising and or response data either when setting or querying has been temporarily disabled ...
Страница 32: ...Youtube Tutorial Follow the Youtube tutorial https www youtube com watch v CixqMR3leGs ...