8/13/2019 Bluetooth Writeup
1/25
Web Home Automation through Bluetooth
Overview
This project aims to allow the home owner to get information about home temperatures and control lighting
entirely through a web-based interface. On one end a home !" is set to run an A#!.$%T web server that sends
commands to the &'() microcontroller via a Bluetooth #erial !ort !rofile *#!!+. On the other end the
microcontroller interfaces with a !hilips B,B' Bluetooth module using /A0T. The microcontroller calculates
room temperature through the built-in )-bit A1" using a thermistor and also controls the status of various
household lights. "ommands from the !" can tell the microcontroller to turn on or off lights and report the state of
any light or the room temperature.
%2uipment
*)+ #ilicon 3abs "&'()4''(#15 %valuation Board with /#B 1ebug Adapter
*)+ #par64un W03-'&787 Bluetooth #91 9odule based on !hilips B,B'
*)+ #par64un W03-'')(' Bluetooth /#B 9odule
*)+ B(8&:)9')(;''' 3eaded $T" thermistor
*+ 7.86Ohm resistors
#chematic
8/13/2019 Bluetooth Writeup
2/25
8/13/2019 Bluetooth Writeup
3/25
Building the "ircuit
There are a couple of different Bluetooth modules available for purchase. The W03-'&787 used here is a
surface mount device so you will need a brea6out board or some other way to connect the module to your
microcontroller.
8/13/2019 Bluetooth Writeup
4/25
). "onnect pin T< on the module to 0< on the microcontroller and 0< to TO bloc6.
7. #et jumpers on the ;? connecter such that A=O'-) is connected to the microcontroller A=$'-).
#oftware
This device re2uires use of the microcontroller@s /A0T and A1" subsystems. The software needs to
initialie these systems and also setup the Bluetooth module through the /A0T interface using the B,B'@s AT
command set.
4irst we will ta6e a loo6 at the A1" initialiation. #et the B=A#% bit to enable the A1". The "&'()4''(
already contains an internal ). voltage reference which we can use by setting the 0%4B% bit. The internal
reference goes through a gain buffer amplifier for an input range from -.7 to .7. #et A1" conversion to
start upon write of ) to the A1B/#C bit in the A1"'"$ control register. 0emember to enable the A1" end-of-
conversion interrupt bit ) on the %=% register.
!eriodic readings of the thermistor are triggered by Timer interrupt which sets A1B/#C. We initialie
the reload value such that an interrupt is triggered approDimately every second. The Timer =#0 simply clears the
interrupt flag and sets A1B/#C.
To enable the /A0T the "rossBar needs to be configured so that T< and 0< are assigned to port =>O pins.
The eDact pins depend on what other functionality is enabled but in this setup T< is assigned to !'.' and 0< to
!'.). This is done by setting the /A0T%$ bit in the +G*cloc6 speed+G*)>*)?-reload value++
=n order to ensure successful communication try to stay within I error in baud rate. Table J gives a list of
usable baud rates and reload values for the internal oscillator versus that for an )).'(:9H eDternal oscillator.
#tandard 0ate )?9H reload )?9H error )).'(:9H
reload
)).'(:9H error
))('' 'D444" &.()I 'D4441 'I
(8?'' 'D4448 -.((I 'D444A 'I
&7'' 'D444 '.)?I 'D4448 'I
8/13/2019 Bluetooth Writeup
5/25
):'' 'D44%? '.)?I 'D44%% 'I
:?'' 'D44"" '.)?I 'D441" 'I
As you can see the )).'(:9H cloc6 allows for faster /A0T communication even though it is slower
than the internal oscillator. Also the internal oscillator does not run at eDactly )?9H so you may need to try a
couple of reload values before hitting on one that wor6s for your microcontroller.
3astly we need to implement the /A0T =#0 called when either 0= or T= flags are set. The 0= is the receive
interrupt set when the microcontroller has finished receiving a byte of data in the #B/4 register. The T= is the
transmit interrupt which is set when a byte of data has finished transmitting. #ince 0= and T= both trigger the same
interrupt the =#0 must handle both cases.
On a receive interrupt the software clears the 0= flag and attempts to place the received byte into a buffer
array. =f the buffer is full the data is simply lost.
=n case of a transmit interrupt the software clears the T= flag and chec6s is there is more data in the
transmit buffer. =f it is empty the software clears T
8/13/2019 Bluetooth Writeup
6/25
ATBT/0TF:?'' & ' ) '
#ets /A0T baud rate to :?''
ATBT#%"F'
1isable security mode such that pairing is unnecessary
ATBT43#
#tores current configuration into 4lash
ATBT#0F
#tarts the Bluetooth #!! server
At this point you are ready to communicate with the !" from the microcontroller. Once the !" establishes
an #!! connection any data sent from the &'() will show up on a virtual serial port on the !" and vice versa.
9easuring Ambient 0oom Temperature
The B(8&:)9')(;''' thermistor is a negative temperature coefficient device meaning its resistance gets
smaller as the temperature increases. Thermistors are accurate and stable over time but they are highly nonlinear.
=nstead of mathematically calculating the temperature the software will use an &-point loo6up table based off the
thermistor datasheet and estimate intermediate values using linear interpolation.
The thermistor is placed in a Wheatstone bridge with three 7.86Ohm resistors. By measuring the voltage
difference between both arms we can accurately determine small changes in the thermistor@s resistance. Another
advantage of the Wheatstone bridge is that the voltage difference is a relative measurement meaning fluctuations in
supply voltage will not affect the voltage measurement as much.
The )-bit A1" in the "&'()4''( converts the potential A=$' Q A=$) into a digital value based off the
internal .7 voltage reference. Thus in the differential input mode the range of the A1" is from -.7 to .7.
We can use 5irchoff@s circuit laws to determine the resistance of the thermistor.
Fcc> -ccG0>*7.860+ -cc>FccG0>*7.860+ *-cc>+G7.86*-cc>+G0FccG0
-cc>+G7.86F0*Gcc>-+
0F7.86G*-cc>+>*ccG>-+
By using the above e2uation we can build a loo6up table from the data sheet to relate voltage to
temperature.
Temperature 0esistance oltage'.' 7'' '.'(?:
(.' 7? '.7'
)'.' 8?? '.7))
)(.' & '.(?:
'.' )& '.8))
(.' )('' '.&?
'.' )7( '.:77
(.' )'' ).'7
8/13/2019 Bluetooth Writeup
7/25
7'.' &(?.( ).)
The A1" samples an un6nown input by using a small capacitor. =t continuously trac6s the voltage level of
the input. When it is ready to perform a conversion the A1" cuts off connection to the input and holds the charge
that represents the analog level. This is commonly referred to as a sample and hold circuit.
The A1" uses a techni2ue called successive approDimation. =t utilies a )-bit 1A" and a comparator. The
A1" gets cloc6ed ) times by the system cloc6. %ach cycle determines the value of one bit starting with the most
significant. 4or eDample on the first cloc6 cycle the most significant bit of the 1A" is set and its voltage compared
to the input. =f the voltage of the input is higher than the 1A" output then we 6now the most significant bit should
be one. Otherwise that bit should be '.
An A1" interrupt is triggered at the end of each conversion. The =#0 ta6es the new reading and adds it to
an accumulator variable. %very & readings the accumulator is averaged and the averaged value stored in the global
variable Rresult@. #uch an averaging filter helps reduce the effect of noise and produce a more stable temperature
reading.
"onnecting to the !"
=nstall the Blue#oleil software that comes with the Bluetooth /#B module. !lug in the Bluetooth module
and open the Blue#oleil main window by double clic6ing on the tray icon.
$eDt clic6 on the orange orb to search for Bluetooth devices. 1on@t forget to have your microcontroller
Bluetooth module powered on at this pointS $ote that the #par64un module might show up as only a device address
at first. Wait until the Blue#oleil program finishes its search and right clic6 on the module then select 0efresh
#ervices. After that right clic6 again and select "onnect-NBluetooth #erial !ort #ervice.
8/13/2019 Bluetooth Writeup
8/25
The first time you connect to the #!! service a uic6 "onnect dialogue will appear. Write down or
remember which "O9 port it is connected to. =f at any time you forget you can find out which port the device is
assigned by going to Tools-N"onfiguration-Nuic6 "onnectU
$ow you can open up any terminal program and send data to the microcontroller by connecting to that
"O9 port with the same baud rate and data settings as the Bluetooth module on the device.
Web =nterface using A#!.$%T
The final step is to build a web interface to allow remote control by the home owner from anywhere in the
world. This is done using A#!.$%T to build a dynamic web page that can interact with the virtual serial port on the
web server.
8/13/2019 Bluetooth Writeup
9/25
The website organies and shows the user the status of every component connected to the microcontroller.
The two update buttons update the status variables by 2uerying the &'() over the Bluetooth. The microcontroller
processes 2uery strings and returns the relevant data.
#imilarly the website uses a form interface to allow the user to send command strings over Bluetooth
which the microcontroller processes and effects any necessary changes.
"ode
main.c:
#include #include #include "uart_fifo.h"
sbit LED = P1!
$D%0 definitions#define &$'LE()*E 8#define )+&DE% 8
unsi,ned char a-,'uffer8/
unsi,ned short a-,&eeratureunsi,ned char a-,2olta,eunsi,ned short su2olta,eunsi,ned short accuulatorunsi,ned short result
char -olta,e&able&$'LE()*E/ = 3!4 60 6! 84 88 74 78 104unsi,ned short teerature&able&$'LE()*E/ = 3165 900 995 950 965 400 495 450
8/13/2019 Bluetooth Writeup
10/25
union stran,e3
unsi,ned short buf1!char buf89/
adc'uffer
ain definitions#define '$:D;$&E 115900
-oid ((%L_)nit-oid?-oid P@;&_)nit-oid?-oid &)AE;4_)nit-oid?-oid $D%0_)nit-oid?
-oid &)AE;1_)(;-oid?-oid &)AE;4_)(;-oid?-oid $D%0_)(;-oid?
-oid reort&eerature?
char adcratechar bufferint i B
-oid ain -oid?3
CD&%+ = 0DE disable atchdo, tier CD&%+ = 0$D
((%L_)nit? initialiFe oscillator P@;&_)nit? initialiFe crossbar and GP)@&)AE;4_)nit? initialiFe heartbeat interrut
$D%0_)nit? initialiFe $D%0
:$;&_)nit7!00? initialiFe :$;&
)E H= 080 ,lobal interrut enable
;I'uf)nit?&I'uf)nit?
:$;&_@ut(trin,"JJJ$&J'&$:&=1Kr"?:$;&_@ut(trin,"$&J'&(;2=9Kr"?
hile1?3
if:$;&_)n%harbuffer??
3 ifbuffer == MNM?3
hileO:$;&_)n%harbuffer?? 3 ifbuffer == M&M?3
reort&eerature?else ifbuffer == MLM?3
8/13/2019 Bluetooth Writeup
11/25
hileO:$;&_)n%harbuffer?? 3 sitchbuffer?3
case M1M hileO:$;&_)n%harbuffer?? 3 ifLED?
3 :$;&_@ut(trin,"L1@nKrKn"? else 3 :$;&_@ut(trin,"L1@ffKrKn"? breaQ
default breaQ
else ifbuffer == M%M?3
hileO:$;&_)n%harbuffer?? 3
ifbuffer == MLM?3
hileO:$;&_)n%harbuffer?? 3 sitchbuffer?3
case M1M hileO:$;&_)n%harbuffer?? 3 ifbuffer == M1M? 3 LED = 1 else ifbuffer == M0M? 3 LED = 0
breaQ
default breaQ
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR )nitialiFation (ubroutines
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR ((%L_)nitRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR &his routine initialiFes the sSste clocQ to use internal 1!ATF crSstal-oid ((%L_)nit-oid?3
8/13/2019 Bluetooth Writeup
12/25
@(%I%+ = 000 eternal oscillator off@(%)%+ = 006 internal oscillator set to 1!ATF
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR P@;&_)nitRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR %onfi,ure the %rossbar and GP)@ orts-oid P@;&_)nit-oid?3
I';0 Port )@ %rossbar ;e,ister 0 bit 6 %P0E+ = 0 bit ! E%)E = 0 bit 5R4 P%$0AE = 000 bit 9 :$;&E+ = 1 bit 1 (P)0@E+ = 0 bit 0 (A'0@E+ = 0I';0 = 00U
I';1 = 000 I';9 = 0U0 Enable crossbar and eaQ ullRus
P;&0%V H= 004 set &I in as ushRullP;&1%V H= 0U0 set heartbeat led as ushRull
P;&0%V = 0VDP;&1%V = 0VVP;&9%V = 0VVP;&4%V = 0VV
P1 = 000
&ier 4 controls $D%0 con-ersion interrut-oid &)AE;4_)nit-oid?3
&A;4%+ &ier 4 %ontrol ;e,ister bit 6 &V4 bit !R4 unused bit 9 &;4 = 0 disable tier 4 bit 1 &4A = 0 use sSste clocQ19 bit 0 unused&A;4%+ = 000
&A;4;LT = RU1!!6? >> 8? 0VV?&A;4;LL = RU1!!6? 0VV?&A;4T = &A;4;LT&A;4L = &A;4;LL
E)E9 = 001&A;4%+ = 00U
8/13/2019 Bluetooth Writeup
13/25
-oid $D%0_)nit-oid?3
select $)+0R1 differential inut$AI0%V = 001$AI0(L = 000
select $)+0 sin,le ended inut$AI0%V = 000$AI0(L = 000
$D%0%V $D% %onfi,uration ;e,ister bit 6 $D%(%9 = 0 bit ! $D%(%1 = 1 bit 5 $D%(%0 = 1 bit UR4 unused bit 9 $APG+9 = 0 bit 1 $APG+1 = 0 bit 0 $APG+0 = 0
$D%0%V = 0!0
$D%0%+ $D% %ontrol ;e,ister bit 6 $D%E+ = 1 enable $D%0 bit ! $D%&A = 1 bit 5 $D%)+& = 0 bit U $D':( = 0 bit 4 $D(&A1 = 0 con-ersion on rite to $D':( bit 9 $D(&A0 = 0 bit 1 $DC)+& = 0 bit 0 $DLW(& = 0 ri,htRBustified
$D%0%+ = 0%0
$D%0T6U/ = 000b data in $D%0T40/R$D%0L60/
;EV0%+ ;eference %ontrol ;e,ister bit 6R4 unused bit 9 &EAPE = 0 internal teerature sensor off bit 1 ')$(E = 1 internal bias on bit 0 ;EV'E = 1 use internal -olta,e reference;EV0%+ = 004
E)E9 H= 009 enable $D%0 endRofRcon-ersion interrut
-oid $D%0_)(;-oid? interrut 153
$D%)+& = 0 clear interrut fla,
adc'uffer.buf80/ = $D%0Tadc'uffer.buf81/ = $D%0L
accuulator J= adc'uffer.buf1! add ne -alue to accuulator
ifOB?3
result = accuulator)+&DE% deciate and store
8/13/2019 Bluetooth Writeup
14/25
B = )+&DE% reset accuulatoraccuulator = 0
BRR
-oid &)AE;4_)(;-oid? interrut 1U3
&A;4%+ = X080?
aroiatelS 1 con-ersionsecondifadcrateJJ? == 010?3
$D':( = 1adcrate = 0
-oid reort&eerature?3
con-erts ra $D% -alue to -olta,e in units 0.12a-,2olta,e = result >> 9?Y!1?198? 0VV?
i = 0hilei < &$'LE()*E a-,2olta,e > -olta,e&ablei/?3
iJJ
ifi == 0?3
-alue is belo iniu on looQu tablea-,&eerature = teerature&ablei/
else ifi == &$'LE()*E?3
-alue is abo-e aiu on looQu tablea-,&eerature = teerature&able&$'LE()*ER1/
else3
linear aroiation for an inRbeteen -aluea-,&eerature = teerature&ablei/ R -olta,e&ablei/ R a-,2olta,e? Y
teerature&ablei/ R teerature&ableiR1/? -olta,e&ablei/ R -olta,e&ableiR1/??
reorts teerature in M&.KrKnM forat:$;&_@ut(trin,"&"?:$;&_@ut:Deca-,&eerature?:$;&_@ut(trin,"KrKn"?
uart_fifo.h:
8/13/2019 Bluetooth Writeup
15/25
V)V@ Definitions-oid ;I'uf)nit-oid?int ;I'ufPushchar nedata?int ;I'ufPochar YdataPt?int ;I'ufVull-oid?int ;I'ufEtS-oid?
-oid &I'uf)nit-oid?int &I'ufPushchar nedata?int &I'ufPochar YdataPt?int &I'ufVull-oid?int &I'ufEtS-oid?
:$;& Definitions-oid :$;&_)nitint baudrate?-oid :$;&_)(;-oid?
-oid :$;&_@ut%harchar outdata?-oid :$;&_@ut(trin,char Youtdata?
-oid :$;&_@ut:Decunsi,ned short nuber?int :$;&_)n%harchar Yindata?
uart_fifo.c:
#include #include "uart_fifo.h"
V)V@ Definitions#define ;I':V()*E 90#define &I':V()*E 90
V)V@ 2ariableschar ;I'uf;I':V()*E/char Y;IGetPtchar Y;IPutPtchar &I'uf&I':V()*E/char Y&IGetPtchar Y&IPutPt
:$;& Definitions#define ((%L 17900000#define ((%L 18000000
char &I'usS
-oid ;I'uf)nit-oid?3
;IPutPt = ;I'uf0/;IGetPt = ;I'uf0/
int ;I'ufPushchar nedata?3
char YtPt = ;IPutPt
8/13/2019 Bluetooth Writeup
16/25
YtPt? = nedata trS to ush data onto buffer tPtJJ
iftPt == ;I'uf;I':V()*E/?3
tPt = ;I'uf0/ ,o to front of buffer
iftPt == ;IGetPt?3
return 0 buffer is full ush failedelse3
;IPutPt = tPt set PutPt ush successfulreturn 1
int ;I'ufPochar YdataPt?
3if;IGetPt == ;IPutPt?3
return 0 buffer etS nothin, to oelse3
YdataPt? = Y;IGetPt?;IGetPtJJif;IGetPt == ;I'uf;I':V()*E/?3
;IGetPt = ;I'uf0/ ,o to front of buffer
return 1
int ;I'ufVull-oid?3
char YtPt = ;IPutPttPtJJiftPt == ;I'uf;I':V()*E/?3
tPt = ;I'uf0/ ,o to front of bufferiftPt == ;IGetPt?
3 return 1else3
return 0
int ;I'ufEtS-oid?
8/13/2019 Bluetooth Writeup
17/25
3return ;IGetPt == ;IPutPt?
-oid &I'uf)nit-oid?3
&IPutPt = &I'uf0/&IGetPt = &I'uf0/
int &I'ufPushchar nedata?3
char YtPt = &IPutPtYtPt? = nedata trS to ush data onto buffer tPtJJ
iftPt == &I'uf&I':V()*E/?3
tPt = &I'uf0/ ,o to front of buffer
iftPt == &IGetPt?3
return 0 buffer is full ush failedelse3
&IPutPt = tPt set PutPt ush successfulreturn 1
int &I'ufPochar YdataPt?
3if&IGetPt == &IPutPt?3
return 0 buffer etS nothin, to oelse3
YdataPt? = Y&IGetPt?&IGetPtJJif&IGetPt == &I'uf&I':V()*E/?3
&IGetPt = &I'uf0/ ,o to front of buffer
return 1
int &I'ufVull-oid?3
char YtPt = &IPutPttPtJJiftPt == &I'uf&I':V()*E/?3
8/13/2019 Bluetooth Writeup
18/25
tPt = &I'uf0/ ,o to front of bufferiftPt == &IGetPt?3
return 1else3
return 0
int &I'ufEtS-oid?3
return &IGetPt == &IPutPt?
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR :$;&_)nitRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
%onfi,ure the :$;&-oid :$;&_)nitint baudrate?3
(%@+ (erial Port %ontrol ;e,ister bit 6 (A0 = 0 Aode 1 8Rbit -ariable baud rate bit ! (A1 = 1 bit 5 (A9 = 0 bit U ;E+ = 1 :$;& recetion enabled bit 4 &'8 = I bit 9 ;'8 = I bit 1 &) transit interrut
bit 0 ;) recei-e interrut(%@+ = 050
&) = 1
E( = 1 enable :$;& interruts
&ier 9 setu as baud rate clocQ Chen in baud rate ,enerator ode &ier 9 clocQ source is fied at ((%L9
&;9 = 0 disable &ier 9
&9%@+ &ier 9 %ontrol ;e,ister bit 6 &V9 bit ! EIV9 bit 5 ;%L = 1 use tier 9 for :$;& recei-e bit U &%L = 1 use tier 9 for :$;& transit bit 4 EIE+9 = 0 disable eternal interrut bit 9 &;9 = 0 disable tier 9 bit 1 %&9 = 0 use internal clocQ bit 0 %P;L9 = 0 set autoRreload ode;%L = 1
8/13/2019 Bluetooth Writeup
19/25
&%L = 1EIE+9 = 0%&9 = 0%P;L9 = 0
((%L = 17900000 'aud rate = 7!00;%$P9T = R((%L49baudrate??JU? >> 8? 0VV;%$P9L = R((%L49baudrate??JU? 0VV ((%L = 18000000 'aud rate = 7!00;%$P9T = R((%L49baudrate??? >> 8? 0VV;%$P9L = R((%L49baudrate??? 0VV&L9 = ;%$P9L&T9 = ;%$P9T
&;9 = 1
-oid :$;&_)(;-oid? interrut U3
if;)?
3;) = 0 clear interrut fla,
ifO;I'ufVull??3
;I'ufPush(':V?
else if&)?3
&) = 0 clear interrut fla,
ifO&I'ufEtS??
3char &Idata&I'ufPo&Idata?(':V = &Idata&I'usS = 1 still transittin,
else3
&I'usS = 0 all transit finished
-oid :$;&_@ut%harchar outdata?3hile&I'ufPushoutdata? == 0? 3 hile&I'usS == 1? 3 &) = 1
-oid :$;&_@ut(trin,char Youtdata?3
hileYoutdata?
8/13/2019 Bluetooth Writeup
20/25
3:$;&_@ut%harYoutdata?outdataJJ
:$;&_@ut)nte,er con-erts an inte,er -alue into its $(%)) character-oid :$;&_@ut)nte,erunsi,ned char inte,er?3
sitchinte,er?3
case 0 :$;&_@ut%harM0M? breaQcase 1 :$;&_@ut%harM1M? breaQcase 9 :$;&_@ut%harM9M? breaQcase 4 :$;&_@ut%harM4M? breaQ
case U :$;&_@ut%harMUM? breaQcase 5 :$;&_@ut%harM5M? breaQcase ! :$;&_@ut%harM!M? breaQcase 6 :$;&_@ut%harM6M? breaQcase 8 :$;&_@ut%harM8M? breaQcase 7 :$;&_@ut%harM7M? breaQdefault breaQ
:$;&_@ut:Dec oututs an unsi,ned decial in . forat-oid :$;&_@ut:Decunsi,ned short nuber?3
ifnuber > 100?3
:$;&_@ut)nte,ernuber100?nuber = nuber R nuber100?Y100
ifnuber > 10?
3 :$;&_@ut)nte,ernuber10?nuber = nuber R nuber10?Y10
else3
:$;&_@ut%harM0M?:$;&_@ut%harM.M?:$;&_@ut)nte,ernuber?
8/13/2019 Bluetooth Writeup
21/25
int :$;&_)n%harchar Yindata?3
if;I'ufEtS??3
return 0else3
;I'ufPoindata?return 1
Cebsite
Default.aspx:
8/13/2019 Bluetooth Writeup
22/25
8/13/2019 Bluetooth Writeup
23/25
Error3g.+e!t = "" J J
protetedvoid-pdate+e$peratureo';etenderG EventArgeF tr: tringr!tring 'oolo$plete = fale
if)pCo$$.*penF pCo$$.*penF J &hile)o$pleteF pCo$$.Write"K+rn"F r!tring = pCo$$.8eadLineF ifr!tring.tartWith"+7"FF
o$plete = true +e$perature.+e!t = r!tring.u'tringF J J Error3g.+e!t = "" J ath+i$eoutE!eptionF Error3g.+e!t = "Co$$uniation ti$ed out" +e$perature.+e!t = "6/A" J ath-nauthoriMedAeE!eptionuaeF Error3g.+e!t = "Cannot open onnetion to Bluetooth devie" +e$perature.+e!t = "6/A" thro&uae J ath:te$.*.*E!eptioniieF Error3g.+e!t = "Error o$$uniating &ith Bluetooth devie" +e$perature.+e!t = "6/A" thro&iie J finall: pCo$$.CloeF
J J
protetedvoid-pdateLight4o';etenderG EventArgeF tr: tringr!tring 'oolo$plete = fale
8/13/2019 Bluetooth Writeup
24/25
if)pCo$$.*penF pCo$$.*penF J &hile)o$pleteF pCo$$.Write"KL4rn"F r!tring = pCo$$.8eadLineF ifr!tring.tartWith"L47"FF o$plete = true Living8oo$.+e!t = r!tring.u'tring0F J J Error3g.+e!t = "" J ath+i$eoutE!eptionF Error3g.+e!t = "Co$$uniation ti$ed out" Living8oo$.+e!t = "6/A"
J ath-nauthoriMedAeE!eptionuaeF Error3g.+e!t = "Cannot open onnetion to Bluetooth devie" Living8oo$.+e!t = "6/A" thro&uae J ath:te$.*.*E!eptioniieF Error3g.+e!t = "Error o$$uniating &ith Bluetooth devie" Living8oo$.+e!t = "6/A" thro&iie J finall: pCo$$.CloeF J J
protetedvoidChangetatuo';etenderG EventArgeF tr: if)pCo$$.*penF pCo$$.*penF J
ifLight4.Che?edF pCo$$.WriteLine"CL44rn"F J eleifLight.Che?edF pCo$$.WriteLine"CL45rn"F J Error3g.+e!t = "" J
8/13/2019 Bluetooth Writeup
25/25
ath-nauthoriMedAeE!eptionuaeF Error3g.+e!t = "Cannot open onnetion to Bluetooth devie" thro&uae J ath:te$.*.*E!eptioniieF Error3g.+e!t = "Error o$$uniating &ith Bluetooth devie" thro&iie J finall: pCo$$.CloeF J J JJ