wifi button pusher by esp8266

23584565_1988669997816480_568971519_nBlock diagram

Home automation

 

step 1: settup webserver on raspberry

  • install apache, php, ssh, blabla….

Step2: then this is the tutorial for control LED via web UI.

these tutorial is about turn on and off LED but we can change the PHP to run the any other system commands

the batden.php

<?php

echo “pusher off”;

exec(‘mosquitto_pub -d -u pusher -P 1 -t test -m “push off”‘);

?>

the control.php

 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

<title>Apache2 Ubuntu Default Page: It works</title>

http://code.jquery.com/jquery-1.11.0.min.js

$(document).ready(function(){ $(‘#on’).click(function(){

var a = new XMLHttpRequest();

a.open(“GET”, “batden.php”);

a.onreadystatechange=function(){

if(a.readyState==4){

if(a.status == 200){     }

else  alert(“Error”)         } }

a.send(); });

$(‘#off’).click(function(){

var a = new XMLHttpRequest();

a.open(“GET”, “tatden.php”);

a.onreadystatechange=function(){

if(a.readyState==4){      if(a.status == 200){      }      else{      alert(“Error”)      }         }     }        a.send();

});

});
</head><body>

<button type=”button” id=”on”>Bật Đèn</button><br>

<button type=”button” id=”off”>Tắt Đèn</button><br>  </body>
</html>

 

NOTE: chmod 777 for all file to make in access everywhere

Step 3: install MQTT to communicate between Raspberry and ESP8266

this instructables show what is MQTT

  • http://www.instructables.com/id/How-to-Use-MQTT-With-the-Raspberry-Pi-and-ESP8266/
  • after install the MQTT broker on raspberry, we can test the publish and subscribe system
  • mosquitto_pub -d -u username -P password -t test -m “Hello, World!”
  • this is also the system command we will put to the php file so that when user press a button on website, php run to publish command to topic and ESP8266 will listen to that command and turn on servo motor to push any button.

step 4: the below tutorial show how to make the ESP8266 subscribe to some topic on broker Raspberry

step 5: study php and ajax or html to create complex web ui so that we can set the

  1. timmer (to turn on/off device or turn on/off servo motors)
  2. update clock timer
  3. set the position for servo motor

step 6: put button to turn on musics, slider to adjust volume

 

 

the mechanical from servo 

check out this video for the most simple pusher mechanical

 

other references:

  1. http://www.roboremo.com/esp8266-servo.html
  2. http://nodemcu.com/index_en.html (the esp8266 module)

note:

1.upload code on esp8266 nodemcu faster with uart speed 115200, it may need to load the lastest firmware on nodemcu web

2. the esp8266 and mqtt broker need to be on the same network or same prefix of ip address. Ex: broker 192.168.x.x then esp should be the same 192.168.x.x In my own case, sometimes esp receive 10.0.x.x and some other times were 192.168.x.x Press reset button on the esp to force it to joint the same network

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s