Page 354 - ARM Based Microcontroller Projects Using MBED
P. 354
340 14. ADVANCED PROJECTS
FIG. 14.9 Import the SpwfInterface library.
You should have the following folders and programs in your Program Workspace:
WiFi
NetworkSocketAPI
X_NUCLEO_IDW01M1v2
main.cpp
mbed
The program listing is shown in Fig. 14.10. At the beginning of the program header
files mbed.h, SpwfInterface.h, and TCPSocket.h are included in the program. The
UART interface between the Wi-Fi expansion board and the development board are then
defined where PA_9 is the UART TX and PA_10 is UART RX. In this project the IP address
of the mobile phone was 192.168.1.178 and this is assigned to IPAddress. The connections
between the development board and the relay board are defined and PORTC pins PC_0
to PC_3 are assigned to variables RELAY1 to RELAY4, respectively. Inside the main
program the Wi-Fi ssid name and password are assigned to variables ssid and password,
respectively. All the relays are deactivated at the beginning of the main program by
setting the relay inputs to logic 1s. The program then connects to the mobile phone over
a TCP socket with port number 5000 and waits in a loop to receive data (commands) from
the mobile phone. The following actions are taken when data is received from the mobile
phone: