Page 363 - ARM Based Microcontroller Projects Using MBED
P. 363
14.4 PROJECT 2—ANDROID—NUCLEO BOARD COMMUNICATION USING THE ESP-01 349
/**********************************************************************
ESP-01 BOARD RELAY CONTROL
==========================
In this program an ESP-01 module is used to provide Wi-Fi functions
to the Nucleo-F411RE development board. Additionally, a 4-channel
relay board is connected to GPIO ports PC_0 to PC_3 of the
development board. Commands ONx activate relay x. Similarly, commands
OFFx de-activate relay x.
Author: Dogan Ibrahim
Date : September 2018
File : esp
**********************************************************************/
#include "mbed.h"
//
// Define the expansion board to development board UART connections
//
#define TX PA_9 // UART TX
#define RX PA_10 // UART RX
Serial esp(TX, RX); // UART TX,RX
//
// Configure all relays as outputs and de-activate all relays
//
DigitalOut Relay1(PC_0, 1);
DigitalOut Relay2(PC_1, 1);
DigitalOut Relay3(PC_2, 1);
DigitalOut Relay4(PC_3, 1);
//
// This function connects to the Wi-Fi
//
void ConnectToWiFi()
{
esp.printf("AT+RST\r\n");
wait(2);
esp.printf("AT+CWMODE=1\r\n");
wait(3);
esp.printf("AT+CWJAP=\"BTHomeSpot-XNH\",\"49346abaeb\"\r\n");
wait(10);
esp.printf("AT+CPIMUX=1\r\n");
wait(3);
esp.printf("AT+CIFSR\r\n");
wait(3);
esp.printf("AT+CIPSTART=\"UDP\",\"192.168.1.178\",0,5000,2\r\n");
wait(3);
}
int main()
FIG. 14.18 Program listing.
(Continued)