Page 355 - ARM Based Microcontroller Projects Using MBED
P. 355

14.3 PROJECT 1—ANDROID—NUCLEO BOARD COMMUNICATION USING THE WI-FI EXPANSION BOARD  341
                  /**********************************************************************
                              Wi-Fi EXPANDION BOARD RELAY CONTROL
                              ===================================

                  In this program the Nucleo Wi-Fi expansion board is plugged on top
                  of the Nucleo0F411RE development board. PC_0 to PC_3 pins of the
                  development board are connected to a 4-channel relay board. The
                  relay contacts are controlled by sending commands from a mobile
                  phone (or a PC) over teh Wi-Fi link using the TCP protocol. Commands
                  ONx activates relay x. Similarly, command OFFx de-ctivates relay x.
                  Author: Dogan Ibrahim
                  Date  : September 2018
                  File  : WiFi
                  **********************************************************************/
                  #include "mbed.h"
                  #include "SpwfInterface.h"
                  #include "TCPSocket.h"
                  //
                  // Define the expansion board to development board UART connections
                  //
                  #define TX PA_9
                  #define RX PA_10
                  #define IPAddress "192.168.1.178"           // Mobile phone IP address
                  SpwfSAInterface wifi(TX, RX, false);

                  //
                  // Configure all relays as outputs
                  //
                  DigitalOut Relay1(PC_0);
                  DigitalOut Relay2(PC_1);
                  DigitalOut Relay3(PC_2);
                  DigitalOut Relay4(PC_3);

                  int main()
                  {
                      int count;
                      TCPSocket socket(&wifi);                // Create a TCP socket
                      char Buffer[80];                        // Buffer to store data
                      char *ssid = "BTHomeSpot-XNH";          // Wi-FI SSD name
                      char *password = "49346abaeb";          // Wi-FI password

                      Relay1 = 1;                             // De-activate Relay 1
                      Relay2 = 1;                             // De-activate Relay 2
                      Relay3 = 1;                             // De-activate Relay 3
                      Relay4 = 1;                             // De-activate Relay 4
                  //
                  // Connect to the Wi-Fi
                  //
            FIG. 14.10  Program listing.
                                                                                     (Continued)
   350   351   352   353   354   355   356   357   358   359   360