找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2718|回复: 0
打印 上一主题 下一主题
收起左侧

ESP8266 WIFI模块和mini Rboard实现手机wifi控制

[复制链接]
跳转到指定楼层
楼主
ID:215072 发表于 2017-6-27 11:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
步骤:
1. 下载库文件:


烧写程序之前,我们需要用到ESP8266库,下载地址为:


https://github.com/itead/ITEADLIB-ESP8266


温馨提示:ESP8266 wifi库文件是基于arduino IDE 1.0.5版本编译的,如遇编译不过,请尝试其他版本。


打开库中的uartWIFI.h文件,因为我们的mini RBoard使用的是跟UNO一样的芯片,所以要在H文件里去掉定义UNO的注释,注释掉MEGA。


#define UNO
//#define MEGA


然后把_DBG_RXPIN_和_DBG_TXPIN_引脚定义改为D9和D10.


#define _DBG_RXPIN_ 9 //A0
#define _DBG_TXPIN_ 10 //A1


然后保存uartWIFI.h文件。


烧写代码:



插上FOCA,板子的类型选择“Arduino UNO”,点击烧写程序。
代码如下:

#define SSID "Itead_1(Public)"//type your own SSID name
#define PASSWORD "27955416"0//type your own WIFI passwor

#include "uartWIFI.h"
#include "SoftwareSerial.h"
WIFI wifi

extern int chlID;//client id(0-4)

void setup()
{
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
wifi.begin();
bool b = wifi.Initialize(STA, SSID, PASSWORD);
if(!b)
{
DebugSerial.println("Init error");
}
delay(8000); //make sure the module can have enough time to get an IP address
String ipstring = wifi.showIP();
DebugSerial.println(ipstring);//show the ip address of module

delay(2000);
wifi.confMux(1);
delay(100);
if(wifi.confServer(1,8080))
DebugSerial.println("Server is set up");


}
void loop()
{

char buf[100];
int iLen = wifi.ReceiveMessage(buf);
if(iLen > 0)
{
//mini Rboard的继电器控制脚是D4


if (strcmp(buf, "CH0ON") == 0)
{
digitalWrite(4,HIGH);
DebugSerial.println("CH0ON");
}
if (strcmp(buf, "CH0OFF") == 0)
{
digitalWrite(4,LOW);
DebugSerial.println("CH0OFF");
}
/* 以下多余的3个通道是4通道RBoard的继电器引脚

if (strcmp(buf, "CH1ON") == 0)
{
digitalWrite(5,HIGH);
DebugSerial.println("CH1ON");
}
if (strcmp(buf, "CH1OFF") == 0)
{
digitalWrite(5,LOW);
DebugSerial.println("CH1OFF");
}
if (strcmp(buf, "CH2ON") == 0)
{
digitalWrite(6,HIGH);
DebugSerial.println("CH2ON");
}
if (strcmp(buf, "CH2OFF") == 0)
{
digitalWrite(6,LOW);
DebugSerial.println("CH2OFF");
}
if (strcmp(buf, "CH3ON") == 0)
{
digitalWrite(7,HIGH);
DebugSerial.println("CH3ON");
}
if (strcmp(buf, "CH3OFF") == 0)
{
digitalWrite(7,LOW);
DebugSerial.println("CH3OFF");
}
*/


}
}


黏贴代码到arduino IDE中,在SSID和PASSWORD宏定义中修改成自己的路由器WIFI名称和密码。

#define SSID "Itead_1(Public)" //type your own SSID name
#define PASSWORD "27955416" //type your own WIFI password


编译,烧写,OK!


接下来我们还需要用到foca来读取串口信息,查看wifi状态。


按照以下连接方式连接FOCA和ESP8266到mini Rboard上。

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表