Arduino WIFI透传模块控制LED 四博智联DT-6_TTL-WiFi 透传模块

Arduino WIFI透传模块控制LED 四博智联DT-6_TTL-WiFi 透传模块

本产品内置 HTTP Server,可以通过 PC 机或者手机等其他智能终端的浏览器进行配置,无需其他配置工具或者 APP。在出厂设置中,固件默认工作在 AP 模式,WiFi 模块主动发出来的热点名称为:“Doit_WiFi_xxxxxx”,其中“xxxxxx”是该模块的 MAC 地址后六位。可以使用带无线网卡的 PC 机或者智能手机/平板(支持 Android 和 IOS、Windows Phone 等)连接该热点。热点无密码。

连接成功,使用浏览器访问默认IP地址“192.168.4.1”。

STATUS、MODULE(完成WiFi配置)、MORE(Restart重启)三个界面。

 

//此处为了兼容其他的多串口Arduino板子
#define WIFISerial Serial3
#define DEBUGSerial Serial
#define LED_R 2
#define LED_G 3
#define LED_B 4
#define LED_ON LOW
#define LED_OFF HIGH
const unsigned int WIFIRxBufferLength = 100;
char WIFIRxBuffer[WIFIRxBufferLength];
unsigned int WIFIBufferCount = 0;
void setup() //初始化内容
{
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
digitalWrite(LED_R, LED_OFF);
digitalWrite(LED_G, LED_OFF);
digitalWrite(LED_B, LED_OFF);
WIFISerial.begin(9600); // 定义波特率9600
DEBUGSerial.begin(9600);
DEBUGSerial.println("Wating...");
}
void loop() //主循环
{
while (WIFISerial.available()) {
char buffer = WIFISerial.read();
WIFIRxBuffer[WIFIBufferCount++] = buffer;
if (WIFIBufferCount == WIFIRxBufferLength)clrRxBuffer();
DEBUGSerial.write(buffer); // 收到数据则通过Serial输出
}
if (strstr(WIFIRxBuffer, "RON") != NULL)
{
digitalWrite(LED_R, LED_ON);
clrRxBuffer();
}
else if (strstr(WIFIRxBuffer, "ROFF") != NULL)
{
digitalWrite(LED_R, LED_OFF);
clrRxBuffer();
}
if (strstr(WIFIRxBuffer, "GON") != NULL)
{
digitalWrite(LED_G, LED_ON);
clrRxBuffer();
}
else if (strstr(WIFIRxBuffer, "GOFF") != NULL)
{
digitalWrite(LED_G, LED_OFF);
clrRxBuffer();
}
if (strstr(WIFIRxBuffer, "BON") != NULL)
{
digitalWrite(LED_B, LED_ON);
clrRxBuffer();
}
else if (strstr(WIFIRxBuffer, "BOFF") != NULL)
{
digitalWrite(LED_B, LED_OFF);
clrRxBuffer();
}
}
void clrRxBuffer(void)
{
memset(WIFIRxBuffer, 0, WIFIRxBufferLength); // 清空
WIFIBufferCount = 0;
}
//此处为了兼容其他的多串口Arduino板子 #define WIFISerial Serial3 #define DEBUGSerial Serial #define LED_R 2 #define LED_G 3 #define LED_B 4 #define LED_ON LOW #define LED_OFF HIGH const unsigned int WIFIRxBufferLength = 100; char WIFIRxBuffer[WIFIRxBufferLength]; unsigned int WIFIBufferCount = 0; void setup() //初始化内容 { pinMode(LED_R, OUTPUT); pinMode(LED_G, OUTPUT); pinMode(LED_B, OUTPUT); digitalWrite(LED_R, LED_OFF); digitalWrite(LED_G, LED_OFF); digitalWrite(LED_B, LED_OFF); WIFISerial.begin(9600); // 定义波特率9600 DEBUGSerial.begin(9600); DEBUGSerial.println("Wating..."); } void loop() //主循环 { while (WIFISerial.available()) { char buffer = WIFISerial.read(); WIFIRxBuffer[WIFIBufferCount++] = buffer; if (WIFIBufferCount == WIFIRxBufferLength)clrRxBuffer(); DEBUGSerial.write(buffer); // 收到数据则通过Serial输出 } if (strstr(WIFIRxBuffer, "RON") != NULL) { digitalWrite(LED_R, LED_ON); clrRxBuffer(); } else if (strstr(WIFIRxBuffer, "ROFF") != NULL) { digitalWrite(LED_R, LED_OFF); clrRxBuffer(); } if (strstr(WIFIRxBuffer, "GON") != NULL) { digitalWrite(LED_G, LED_ON); clrRxBuffer(); } else if (strstr(WIFIRxBuffer, "GOFF") != NULL) { digitalWrite(LED_G, LED_OFF); clrRxBuffer(); } if (strstr(WIFIRxBuffer, "BON") != NULL) { digitalWrite(LED_B, LED_ON); clrRxBuffer(); } else if (strstr(WIFIRxBuffer, "BOFF") != NULL) { digitalWrite(LED_B, LED_OFF); clrRxBuffer(); } } void clrRxBuffer(void) { memset(WIFIRxBuffer, 0, WIFIRxBufferLength); // 清空 WIFIBufferCount = 0; }
//此处为了兼容其他的多串口Arduino板子
#define WIFISerial  Serial3
#define DEBUGSerial Serial

#define LED_R 2
#define LED_G 3
#define LED_B 4

#define LED_ON 	LOW
#define LED_OFF HIGH

const unsigned int WIFIRxBufferLength = 100;
char WIFIRxBuffer[WIFIRxBufferLength];
unsigned int WIFIBufferCount = 0;

void setup()	//初始化内容
{
  pinMode(LED_R, OUTPUT);
  pinMode(LED_G, OUTPUT);
  pinMode(LED_B, OUTPUT);

  digitalWrite(LED_R, LED_OFF);
  digitalWrite(LED_G, LED_OFF);
  digitalWrite(LED_B, LED_OFF);

  WIFISerial.begin(9600);	// 定义波特率9600
  DEBUGSerial.begin(9600);

  DEBUGSerial.println("Wating...");
}

void loop()		//主循环
{
  while (WIFISerial.available()) {
    char buffer =  WIFISerial.read();

    WIFIRxBuffer[WIFIBufferCount++] = buffer;
    if (WIFIBufferCount == WIFIRxBufferLength)clrRxBuffer();

    DEBUGSerial.write(buffer); // 收到数据则通过Serial输出
  }

  if (strstr(WIFIRxBuffer, "RON") != NULL)
  {
    digitalWrite(LED_R, LED_ON);
    clrRxBuffer();
  }
  else if (strstr(WIFIRxBuffer, "ROFF") != NULL)
  {
    digitalWrite(LED_R, LED_OFF);
    clrRxBuffer();
  }

  if (strstr(WIFIRxBuffer, "GON") != NULL)
  {
    digitalWrite(LED_G, LED_ON);
    clrRxBuffer();
  }
  else if (strstr(WIFIRxBuffer, "GOFF") != NULL)
  {
    digitalWrite(LED_G, LED_OFF);
    clrRxBuffer();
  }

  if (strstr(WIFIRxBuffer, "BON") != NULL)
  {
    digitalWrite(LED_B, LED_ON);
    clrRxBuffer();
  }
  else if (strstr(WIFIRxBuffer, "BOFF") != NULL)
  {
    digitalWrite(LED_B, LED_OFF);
    clrRxBuffer();
  }

}

void clrRxBuffer(void)
{
  memset(WIFIRxBuffer, 0, WIFIRxBufferLength); // 清空
  WIFIBufferCount = 0;
}

通过网络助手模拟发送数据包控制小灯。

发表回复

您的电子邮箱地址不会被公开。