Wemos D1 打造最简单的手机远程控制浇水系统

      WemosD1是与Arduino兼容的ESP-8266 WiFi模块为基础的开发板,通过Arduino IDE编程实现功能。本项目主要用到了库ESP8266WebServer.h,wemosD1作为web服务器,把html的代码嵌入到wemos板子中,无需额外的web服务器便能在浏览器中访问控制页面从而实现远程控制。

一 所需硬件

1.WEMOS D1  淘宝链接

2. rs232转ttl模块 淘宝链接

3.1路串口继电器 淘宝链接

4.塑料常闭式电磁阀 淘宝链接

5.DC24V电源 淘宝链接

二 硬件接线

 

三 软件代码

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <Ticker.h>
#include <WiFiUdp.h>
#include <TimeLib.h> 
#include <String.h>
Ticker tickerflash;

IPAddress timeServer(120, 25, 115, 20); // time-a.timefreq.bldrdoc.gov
const int timeZone = 8;
WiFiUDP Udp;
unsigned int localPort = 8888;


//#define EEPROM_write(address, p)(int i = 0; byte *pp = (byte*)&(p);for(;i < sizeof(p); i++) EEPROM.write(address + i, pp );)
//#define EEPROM_read(address, p) {int i = 0; byte *pp =(byte*)&(p); for (; i < sizeof(p); i++) pp = EEPROM.read(address + i);}

static char Apid[] = "*****";//根据你的路由器设置
static char softAPID[] = "*****";//路由名字
static char ApPass[13] = "*****";//路由密码

byte APip[] = { 192, 168, 1, 200 };//0106000000FFC98A
byte APGateWay[] = { 192, 168, 1, 1 };//01060000000089CA
byte APSubNet[] = { 255, 255, 255, 0 };
byte dns[] = {192,168,0,1};
byte dns1[] = {114,114,114,114};
int autoflag = 0;
int autoopenflag = 0;
byte state1;
uint8_t SetHour;
uint8_t SetMinute;
uint8_t timelong;
String SetHourc;
String SetMinc;
String timec;
unsigned char openc[1][8] = {
  { 0x01, 0x06, 0x00, 0x00, 0x00, 0xff, 0xc9, 0x8a},//1 号继电器开启
  //{ 0x01, 0x06, 0x00, 0x01, 0x02, 0x01, 0x18, 0xaa},//2 号继电器开启
  //{ 0x01, 0x06, 0x00, 0x01, 0x03, 0x01, 0x19, 0x3a},//3 号继电器开启
  //{ 0x01, 0x06, 0x00, 0x01, 0x04, 0x01, 0x1b, 0x0a},//4 号继电器开启
  //{ 0x01, 0x06, 0x00, 0x01, 0xff, 0xff, 0xd9, 0xba}//全亮
};
unsigned char closec[1][8] = {
  { 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0xca},//1 号继电器关闭
  //{ 0x01, 0x06, 0x00, 0x01, 0x02, 0x00, 0xd9, 0x6a},//2 号继电器关闭
  //{ 0x01, 0x06, 0x00, 0x01, 0x03, 0x00, 0xd8, 0xfa},//3 号继电器关闭
  //{ 0x01, 0x06, 0x00, 0x01, 0x04, 0x00, 0xda, 0xca},//4 号继电器关闭
  //{ 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0xd8, 0x0a}//全灭
};
byte TSwitch[] = {
  0, 0, 0, 0
};
byte StatSave[] = {
  0xff, 0xff, 0xff, 0xff
};//掉电保护
byte Switchnum = 10
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值