51.
fo.write("}
\n")
52.
fo
.
close()
53.
54.
55.
new_input =
1
56.
try
:
57.
while
1
and
console
.
is_open
.
__bool__():
58.
# get keyboard input once
59.
if
(new_input ==
1
):
60.
# Python
2
users
61.
# input = raw_input("Enter something such
as
a Manufacturer Specific (MFS) ID
to
scan
for
and
store
in
a
file
or
just leave it blank
to
scan all: ")
62.
new_input = input("Enter something such
as
a Manufacturer Specific (MFS) ID
to
scan
fo
r
and
store
in
a
file
or
just leave it blank
to
scan all: ")
63.
time
.
sleep(
0.1
)
64.
# sends the commands
to
the dongle. Important
to
send the \r
as
that
is
the return-
key.
65.
console
.
write
(str
.
encode("AT+CENTRAL"))
66.
console
.
write
(
'\r'
.encode())
67.
time
.
sleep(
0.1
)
68.
console
.
write
(str
.
encode("AT+FINDSCANDATA="))
69.
console
.
write
(new_input
.
encode())
70.
console
.
write
(
'\r'
.encode())
71.
out =
''
72.
# Let
's wait one second before reading output (let'
s give device time
to
answer)
73.
time
.
sleep(
1
)
74.
print("\nCollecting data...\nPress Ctrl-C
to
stop.")
75.
while
console
.
inWaiting() >
0
:
76.
out += console
.
read(console
.
inWaiting()).decode()
77.
else
:
78.
if
not
out
.
isspace():
79.
# We make sure it doesn't print the same message over
and
over again by setting [o
ut]
to
blankspace
80.
#
and
check
for
blankspace
and
that [out] isn't anything
else
before writing
to
fi
le
81.
if
not
out
.
__contains__("AT+")
and
not
len(out) <=
106
:
82.
write_data_to_file(out)
83.
out = " "
84.
except
KeyboardInterrupt:
85.
exit()
Open up the command prompt in the directory where the script is located. Start the script by
typing
1.
python scan_and_store_example
.
py
and press Enter.
You should now be prompted to enter what you want to scan for. For example a Manufacturer
Specific ID (if you want to scan for Smart Sensor Devices products for example you enter the
Flag for MFS Data
FF
and then our MFS ID:
5B07
).