mirror of https://github.com/IoTcat/wIoT.git
parent
88c5d3a713
commit
f7aef86444
11 changed files with 485 additions and 0 deletions
@ -0,0 +1,137 @@ |
||||
/* *****************************************************************
|
||||
* this is the code for control unit in hallway |
||||
*
|
||||
* *****************************************************************/ |
||||
|
||||
//declear the moudle is WIFI
|
||||
#define BLINKER_PRINT Serial |
||||
#define BLINKER_WIFI |
||||
|
||||
//include function set
|
||||
#include <Blinker.h> |
||||
|
||||
//define overal var
|
||||
char ssid[] = "yimian-iot"; |
||||
char pswd[] = "1234567890."; |
||||
|
||||
//announce keyname
|
||||
BlinkerButton Button1("btn-abc"); |
||||
BlinkerButton Button2("btn-on"); |
||||
BlinkerButton Button3("btn-off"); |
||||
|
||||
//declear var
|
||||
int swi,swi1 ,i,a,timer,timer1,b,c= 0; |
||||
|
||||
|
||||
|
||||
|
||||
//button1-function
|
||||
void button1_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button state: ", state); |
||||
if(digitalRead(D5)){ Button1.print("灯正亮!");}else{ Button1.print("灯未亮!");} |
||||
digitalWrite(D5,LOW); |
||||
Button1.print("正在重置!"); |
||||
for(i=10;i>0;i--) |
||||
{ |
||||
Blinker.print(i); |
||||
digitalWrite(D6,LOW);digitalWrite(D13,LOW); |
||||
digitalRead(D6);digitalRead(D13); |
||||
delay(1000); |
||||
} |
||||
a=0; |
||||
Button1.print("重置完成!"); |
||||
timer1=Blinker.time()-249; |
||||
if(digitalRead(D5)){ Button1.print("灯已打开!");}else{ Button1.print("灯已关闭!");} |
||||
} |
||||
|
||||
|
||||
//button2-function
|
||||
void button2_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button state: ", state); |
||||
a=1; |
||||
digitalWrite(D5,HIGH); |
||||
if(digitalRead(D5)){ Button1.print("灯已打开!");}else{ Button1.print("灯已关闭!");} |
||||
timer=Blinker.time(); |
||||
}
|
||||
|
||||
|
||||
//button3-function
|
||||
void button3_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button state: ", state); |
||||
a=1; |
||||
digitalWrite(D5,LOW); |
||||
if(digitalRead(D5)){ Button1.print("灯已打开!");}else{ Button1.print("灯已关闭!");} |
||||
timer=Blinker.time(); |
||||
}
|
||||
|
||||
|
||||
|
||||
//main setup function
|
||||
void setup()
|
||||
{ |
||||
Serial.begin(115200); |
||||
|
||||
pinMode(D5, OUTPUT); //control the light
|
||||
pinMode(D6, INPUT); //sensor1
|
||||
pinMode(D13, INPUT); //sensor2
|
||||
//D4&D8 are used for checking the switch state
|
||||
pinMode(D4, INPUT); |
||||
pinMode(D8, OUTPUT); |
||||
|
||||
//set the light paraperation
|
||||
digitalWrite(D5, HIGH); |
||||
|
||||
//connect to WIFI
|
||||
Blinker.begin(ssid, pswd); |
||||
|
||||
//set interrupt
|
||||
Button1.attach(button1_callback); |
||||
Button2.attach(button2_callback); |
||||
Button3.attach(button3_callback); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
//main loop function
|
||||
void loop() { |
||||
Blinker.run(); |
||||
|
||||
//get time info
|
||||
|
||||
|
||||
//judge the switch state
|
||||
swi1=swi; |
||||
swi=0; |
||||
for(i=0;i<2;i++) |
||||
{ |
||||
//change D8 state
|
||||
digitalWrite(D8,!digitalRead(D8)); |
||||
if(digitalRead(D4)!=digitalRead(D8)){ swi++;} |
||||
} |
||||
|
||||
BLINKER_LOG2("get slider value: ", swi); |
||||
if(swi!=swi1){digitalWrite(D5,!digitalRead(D5));a=1;timer=Blinker.time();Blinker.print("已切换至手动控制!");} |
||||
if(timer==(Blinker.time()-300)){a=0;Blinker.print("手动控制结束!");} |
||||
BLINKER_LOG2("get slhgggggggggggider value: ",digitalRead(D5) ); |
||||
//get sensor info
|
||||
BLINKER_LOG2("get sensor1: ", digitalRead(D13)); |
||||
BLINKER_LOG2("get sensor2: ", digitalRead(D6)); |
||||
BLINKER_LOG2("a= ", a); |
||||
|
||||
//if people light on
|
||||
if(digitalRead(D6)==1&&digitalRead(D13)==1&&a!=1){ Blinker.print("探测到人"); if(Blinker.hour()<=7||Blinker.hour()>=17){ digitalWrite(D5,HIGH);Blinker.print("灯已打开!");timer1=Blinker.time();}}else{if(a!=1&&timer1==(Blinker.time()-250)){digitalWrite(D5,LOW);Blinker.print("未探测到人,灯已关闭!"); Button1.print("正在重置!"); |
||||
for(i=10;i>0;i--) |
||||
{ |
||||
Blinker.print(i); |
||||
|
||||
digitalRead(D6);digitalRead(D13); |
||||
delay(1000); |
||||
} |
||||
Button1.print("重置完成!");}} |
||||
|
||||
} |
||||
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,78 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="zh-CN"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<title>ESP8266</title> |
||||
<link href="css/bootstrap.min.css" rel="stylesheet"> |
||||
<style type="text/css"> |
||||
button { |
||||
width: 150px; |
||||
padding:8px; |
||||
background-color: #428bca; |
||||
border-color: #357ebd; |
||||
color: #fff; |
||||
-moz-border-radius: 5px; |
||||
-webkit-border-radius: 5px; |
||||
border-radius: 10px; /* future proofing */ |
||||
-khtml-border-radius: 5px; /* for old Konqueror browsers */ |
||||
text-align: center; |
||||
vertical-align: middle; |
||||
border: 1px solid transparent; |
||||
font-weight: 900; |
||||
font-size:100% |
||||
} |
||||
</style> |
||||
</head> |
||||
<body> |
||||
<nav class="navbar navbar-inverse"> |
||||
<div class="container"> |
||||
<div class="navbar-header"> |
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> |
||||
<span class="sr-only">Toggle navigation</span> |
||||
<span class="icon-bar"></span> |
||||
<span class="icon-bar"></span> |
||||
<span class="icon-bar"></span> |
||||
</button> |
||||
<a class="navbar-brand" href="#">ESP8266</a> |
||||
</div> |
||||
</div> |
||||
</nav> |
||||
|
||||
<div class="container"> |
||||
|
||||
<div class="starter-template"> |
||||
<h1>欢迎使用WiFiduino</h1> |
||||
<br> |
||||
<p>点击下面按钮</p> |
||||
<P>可控制蓝色LED灯</P> |
||||
<br> |
||||
<button onclick='setPinValue("on")' >点亮板载LED</button> |
||||
<br> |
||||
<br> |
||||
<button onclick='setPinValue("off")' >熄灭板载LED</button> |
||||
</div> |
||||
</div> |
||||
<script src="js/jquery.min.js"></script> |
||||
<script src="js/bootstrap.min.js"></script> |
||||
|
||||
|
||||
<script type="text/javascript"> |
||||
function setPinValue(value) { |
||||
var xh = new XMLHttpRequest(); |
||||
xh.onreadystatechange = function() { |
||||
if (xh.readyState == 4){ |
||||
if(xh.status == 200) { |
||||
//alert(xh.responseText); |
||||
alert("操作成功"); |
||||
} |
||||
} |
||||
} |
||||
var requestString = "/pin?a=" + value + "&pin=2"; |
||||
xh.open("GET", requestString, true); |
||||
xh.send(null); |
||||
} |
||||
</script> |
||||
</body> |
||||
</html> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@ |
||||
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
|
||||
require('../../js/transition.js') |
||||
require('../../js/alert.js') |
||||
require('../../js/button.js') |
||||
require('../../js/carousel.js') |
||||
require('../../js/collapse.js') |
||||
require('../../js/dropdown.js') |
||||
require('../../js/modal.js') |
||||
require('../../js/tooltip.js') |
||||
require('../../js/popover.js') |
||||
require('../../js/scrollspy.js') |
||||
require('../../js/tab.js') |
||||
require('../../js/affix.js') |
@ -0,0 +1,110 @@ |
||||
#include <ESP8266WiFi.h> |
||||
#include <ESP8266WebServer.h> |
||||
#include <FS.h> |
||||
|
||||
ESP8266WebServer server ( 80 ); |
||||
String ssid = "TOTOLINK_3be124"; //你的wifi热点名称
|
||||
String password = "13371035727"; //你的wifi热点密码
|
||||
|
||||
//String ssid = "236-iot"; //你的wifi热点名称
|
||||
//String password = "236236236"; //你的wifi热点密码
|
||||
|
||||
String getContentType(String filename){ |
||||
if(server.hasArg("download")) return "application/octet-stream"; |
||||
else if(filename.endsWith(".htm")) return "text/html"; |
||||
else if(filename.endsWith(".html")) return "text/html"; |
||||
else if(filename.endsWith(".css")) return "text/css"; |
||||
else if(filename.endsWith(".js")) return "application/javascript"; |
||||
else if(filename.endsWith(".png")) return "image/png"; |
||||
else if(filename.endsWith(".gif")) return "image/gif"; |
||||
else if(filename.endsWith(".jpg")) return "image/jpeg"; |
||||
else if(filename.endsWith(".ico")) return "image/x-icon"; |
||||
else if(filename.endsWith(".xml")) return "text/xml"; |
||||
else if(filename.endsWith(".pdf")) return "application/x-pdf"; |
||||
else if(filename.endsWith(".zip")) return "application/x-zip"; |
||||
else if(filename.endsWith(".gz")) return "application/x-gzip"; |
||||
return "text/plain"; |
||||
} |
||||
/* NotFound处理
|
||||
*/ |
||||
void handleNotFound() { |
||||
String path = server.uri(); |
||||
Serial.print("load url:"); |
||||
Serial.println(path); |
||||
String contentType = getContentType(path); |
||||
String pathWithGz = path + ".gz"; |
||||
if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){ |
||||
if(SPIFFS.exists(pathWithGz)) |
||||
path += ".gz"; |
||||
File file = SPIFFS.open(path, "r"); |
||||
size_t sent = server.streamFile(file, contentType); |
||||
file.close(); |
||||
return; |
||||
} |
||||
String message = "File Not Found\n\n"; |
||||
message += "URI: "; |
||||
message += server.uri(); |
||||
message += "\nMethod: "; |
||||
message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; |
||||
message += "\nArguments: "; |
||||
message += server.args(); |
||||
message += "\n"; |
||||
for ( uint8_t i = 0; i < server.args(); i++ ) { |
||||
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; |
||||
} |
||||
server.send ( 404, "text/plain", message ); |
||||
} |
||||
void handleMain() { |
||||
Serial.print("handleMain"); |
||||
File file = SPIFFS.open("/index.html", "r"); |
||||
size_t sent = server.streamFile(file, "text/html"); |
||||
file.close(); |
||||
return; |
||||
} |
||||
void handlePin() { |
||||
if(server.hasArg("a")) { |
||||
String action = server.arg("a"); |
||||
if(action == "on") { //a=on
|
||||
digitalWrite(2, LOW); //点亮8266上的蓝色led
|
||||
server.send ( 200, "text/html", "Pin 2 has turn on"); return; //返回数据
|
||||
} else if(action == "off") { // a=off
|
||||
digitalWrite(2, HIGH); //熄灭板载led
|
||||
server.send ( 200, "text/html", "Pin 2 has turn off"); return; |
||||
} |
||||
server.send ( 200, "text/html", "unknown action"); return; |
||||
} |
||||
server.send ( 200, "text/html", "action no found"); |
||||
} |
||||
void setup() {
|
||||
pinMode(2, OUTPUT); |
||||
Serial.begin ( 115200 ); |
||||
SPIFFS.begin(); |
||||
int connectCount = 0; |
||||
WiFi.begin ( ssid.c_str(), password.c_str() ); |
||||
while ( WiFi.status() != WL_CONNECTED ) { |
||||
delay ( 1000 ); |
||||
Serial.print ( "." ); |
||||
if(connectCount > 30) { |
||||
Serial.println( "Connect fail!" ); |
||||
break; |
||||
} |
||||
connectCount += 1; |
||||
} |
||||
if(WiFi.status() == WL_CONNECTED) { |
||||
Serial.println ( "" ); |
||||
Serial.print ( "Connected to " ); |
||||
Serial.println ( ssid ); |
||||
Serial.print ( "IP address: " ); |
||||
Serial.println ( WiFi.localIP() ); |
||||
connectCount = 0; |
||||
} |
||||
server.on ("/", handleMain); |
||||
server.on ("/pin", HTTP_GET, handlePin); |
||||
server.onNotFound ( handleNotFound ); |
||||
server.begin(); |
||||
Serial.println ( "HTTP server started" ); |
||||
} |
||||
|
||||
void loop() { |
||||
server.handleClient(); |
||||
} |
@ -0,0 +1,17 @@ |
||||
volatile double waterFlow; |
||||
void setup() { |
||||
Serial.begin(9600); //baudrate
|
||||
waterFlow = 0; |
||||
attachInterrupt(0, pulse, RISING); //DIGITAL Pin 2: Interrupt 0
|
||||
} |
||||
void loop() { |
||||
Serial.print("waterFlow:"); |
||||
Serial.print(waterFlow); |
||||
Serial.println(" L"); |
||||
delay(500); |
||||
} |
||||
|
||||
void pulse() //measure the quantity of square wave
|
||||
{ |
||||
waterFlow += 1.0 / 450.0; |
||||
} |
@ -0,0 +1,130 @@ |
||||
/* *****************************************************************
|
||||
* |
||||
this is the code for the control part of automatic home solar-powered water heated system. |
||||
*
|
||||
* *****************************************************************/ |
||||
|
||||
//announce connection moudle
|
||||
#define BLINKER_PRINT Serial |
||||
#define BLINKER_WIFI |
||||
|
||||
//declear the slider on phone
|
||||
#define Slider_1 "slider" |
||||
|
||||
//include function set
|
||||
#include <Blinker.h> |
||||
|
||||
//declear overall variable::user, password, identify key
|
||||
char auth[] = "c625b08a9549"; |
||||
char ssid[] = "yimian-iot"; |
||||
char pswd[] = "1234567890."; |
||||
|
||||
//declear Button with certain keyname
|
||||
BlinkerButton Button1("btn-abc"); |
||||
BlinkerButton Button2("btn-on"); |
||||
BlinkerButton Button3("btn-off"); |
||||
BlinkerButton Button4("btn-start"); |
||||
//declaer Slider with certain keyname
|
||||
BlinkerSlider Slider1(Slider_1); |
||||
|
||||
//define vairable
|
||||
int counter,timer,time1,time2,a,b = 0; |
||||
float i=0; |
||||
|
||||
//Button1 function::state check
|
||||
void button1_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button1 state: ", state); |
||||
if(digitalRead(D5)){ Button1.print("未加水");}else{ Button1.print("正在加水..");}
|
||||
if(a==1){ Blinker.print("剩余分钟:"); |
||||
Blinker.print((time2-Blinker.time())/60);} |
||||
} |
||||
|
||||
//Button2 function::on
|
||||
void button2_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button2 state: ", state);
|
||||
digitalWrite(D5, LOW); |
||||
if(digitalRead(D5)){ Button2.print("停止加水");}else{ Button2.print("开始加水..");} |
||||
} |
||||
|
||||
//Button3 function::off
|
||||
void button3_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button3 state: ", state); |
||||
|
||||
digitalWrite(D5, HIGH); |
||||
|
||||
if(digitalRead(D5)){ Button3.print("加水已停止.");}else{ Button3.print("正在加水..");} |
||||
if(a==1){delay(500);Button3.print("加水已终止!");} |
||||
|
||||
a=0; //reset key var a
|
||||
} |
||||
|
||||
//Button4 function::start on
|
||||
void button4_callback(const String & state)
|
||||
{ |
||||
BLINKER_LOG2("get button4 state: ", state); |
||||
|
||||
a=1; |
||||
digitalWrite(D5, LOW); |
||||
|
||||
time1=Blinker.time(); |
||||
time2=time1+timer*60; |
||||
BLINKER_LOG2("get slider value: ", time2-Blinker.time()); |
||||
Button4.print("开始计时加水!"); |
||||
} |
||||
|
||||
//skider function
|
||||
void slider1_callback(int32_t value) |
||||
{ |
||||
timer=value; |
||||
} |
||||
|
||||
//setup function
|
||||
void setup()
|
||||
{ |
||||
Serial.begin(115200); |
||||
|
||||
pinMode(D5, OUTPUT); |
||||
pinMode(D7, INPUT); |
||||
digitalWrite(D5, HIGH); |
||||
|
||||
Blinker.begin(/*auth,*/ ssid, pswd); |
||||
Button1.attach(button1_callback); |
||||
Button2.attach(button2_callback); |
||||
Button3.attach(button3_callback); |
||||
Button4.attach(button4_callback); |
||||
Slider1.attach(slider1_callback); |
||||
} |
||||
|
||||
//main loop function
|
||||
void loop()
|
||||
{ |
||||
Blinker.run(); |
||||
|
||||
if(a==1&&time2>=Blinker.time()) |
||||
{ |
||||
if((time2-Blinker.time())/60==0&&b<=(millis()-1000)){ Blinker.print("剩余秒数:");Blinker.print(time2-Blinker.time());b=millis();} |
||||
|
||||
if((time2-Blinker.time())>60&&b<=(millis()-15000)) |
||||
{ |
||||
Blinker.print("剩余分钟:"); |
||||
Blinker.print((time2-Blinker.time())/60); |
||||
b=millis(); |
||||
} |
||||
|
||||
} |
||||
|
||||
if(a==1&&time2<=Blinker.time()) |
||||
{ |
||||
delay(500); |
||||
Button4.print("加水结束!!"); |
||||
Blinker.notify("计时加水已结束!"); |
||||
|
||||
digitalWrite(D5, HIGH); |
||||
a=0; |
||||
} |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue