WiFi 智能开关是指,在之前 TCPServer 基础上,通过发送信号,控制 ESP8266 输出引脚电平高低,从而操控继电器是否连通。(继电器可以隔离控制器和设备,起到用小电信号控制大量电流和电压的作用)
采用 GPIO5 直接驱动继电器,继电器电源 VCC 连接 VIN,继电器 GND 连接到 GND。
#include "esp_common.h"
#include "gpio.h"
/******************************************************************************
* FunctionName : Relay_Control
* Description : Relay_Control
* Parameters : uint32 mask
* Returns : none
*******************************************************************************/
void Relay_Control(uint32 mask)
{
GPIO_OUTPUT(GPIO_Pin_5,mask);
}
#ifndef __RELAY_H__
#define __RELAY_H__
#ifdef __cplusplus
extern "C" {
#endif
#define RELAY_ON 1
#define RELAY_OFF 0
void Relay_Control(uint32 mask);
#ifdef __cplusplus
}
#endif
#endif
extern "C" 的作用:C++ 函数支持重载功能,导致全局变量或函数被 C++ 编译后在符号库中的名字与 C 语言的不同。在 C 和 C++ 混合编程情境下,会产生编译后符号不匹配问题,从而导致编译失败。而 extern "C" 就是告诉编译器,其所包含的部分,采用 C 语言的方式进行编译,从而解决上述问题。