通信接口

利用ESP8266搭建你的Web服务器+安卓app客户端

字号+ 作者:duino123.com 来源:未知 2016-04-28 10:08 我要评论( )

本项目利用一块ESP8266搭建一个独立的web服务器,可以用来开关2个LED灯。当然,这仅仅是抛砖引玉,你可以扩展出更多的应用。

PLCLIVE.COM注:
本项目利用一块ESP8266搭建一个独立的web服务器,可以用来开关2个LED灯。当然,这仅仅是抛砖引玉,你可以扩展出更多的应用。

ESP-web-server_bb

1. 将NodeMCU烧录进你的ESP8266模块

NodeMCU is a firmware that allows you to program the ESP8266 modules with LUA script. And you’ll find it very similar to the way you program your Arduino. With just a few lines of code you can establish a WiFi connection, control the ESP8266 GPIOs, turning your ESP8266 into a web server and a lot more.

Click the image above, to see on ebay.

2. 原理图 (3.3V FTDI编程器)

esp8266_pinout_h-569x236接线:

  • RX -> TX
  • TX -> RX
  • CH_PD -> 3.3V
  • GPIO 0 -> GND
  • VCC -> 3.3V
  • GND -> GND

ESP8266 Flasher

3. 下载NodeMCU Flasher软件

After wiring your circuit, you have to download the NodeMCU flasher. It's a .exe file that you can download using one of the following links:

You can click here to find all the information about NodeMCU flasher.

4. 烧录ESP8266

Open the flasher that you just downloaded and a window should appear (as shown in the following figure).

nodemcu_flaser

Press the button “Flash” and it should start the flashing process immediately (You might have to change some of the settings  on the Advanced tab). After finishing this process, it should appear a green circle with a check icon.

5. 原理图

Now follow the schematics bellow to create your web server to control two LEDs.

ESP-web-server_bb

6. 修改和上传代码

I recommend using the ESPlorer program created by 4refr0nt to create and save LUA files into your ESP8266. Follow these instructions to download and install ESPlorer:

  1. Click here to download ESPlorer下载ESPlorer软件
  2. Unzip that folder
  3. Go to the dist folder (here's the path: ESPlorer-master\ESPlorer\dist)
  4. Run ESPlorer.jar. It's a JAVA program, so you need JAVA installed on your computer.
  5. Open the ESPlorer

esplorer start

You should see a window similar to the preceding Figure, follow these instructions to upload a LUA file:

  1. Connect your FTDI programmer to your computer
  2. Select your FTDI programmer port
  3. Press Open/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Create a new file called init.lua
  6. Press Save to ESP

Everything that you need to worry about or change is highlighted in red box.

esplorer_tab

7.代码

Upload the following code into your ESP8266 using the preceding software. Your file should be named “init.lua". 点击下载文件

Don't forget to replace your WiFi Station details in that code above (Network Name and Password).

8. 访问你搭建的服务器

When your ESP8266 restarts it prints in your serial monitor the IP address of your ESP8266. If you type your ESP8266 IP address in your web browser, you can access your web server. In my case it's http://192.168.1.95.

web server esp8266

9. 延伸  编写安卓APP访问8266服务器

在App Inventor中创建安卓APP(国内直接访问:http://app.gzjkw.net有不明白的就加qq群交流吧 214461008

MIT App Inventor is a drag-and-drop software that allows you to create a basic, but fully functional Android app within an hour or less.

Here’s how to edit the ESP8266 Controller app:

  1. Click here to download .zip folder that contains .aia file
  2. Unzip the folder
  3. Go to MIT App Inventor
  4. Click the “Create Apps” button on the top right corner
  5. Go to the “Projects” tab and select “Import project (.aia)”


After importing the .aia file, you'll be able to edit the app and see how the app was built.

界面设计

The designer tab is where you can edit how the app looks. Feel free to change the text, change the colors, add buttons or add more features.

 

程序块

The blocks section is where you can add what each button does and add logic to your app.

After finishing editing the app you can click the “Build” app tab and install the .apk file in your Android.  I personally recommend that you first upload the app provided below to ensure that everything works as expected (later you can edit the app).

安装APP

Follow these instructions to install the default app that I've created:

  1. Click here to download .zip folder that contains the .apk file 由于国内网络的限制,访问谷歌需要特殊方式,你懂的
  2. Unzip the folder
  3. Move the .apk file to your Android phone
  4. Run the .apk file to install the app

Here’s how the ESP8266 Controller app looks when you to open it.

 

It's very easy to configure. Click the button“Set IP Address” on the bottom of the screen and type your IP address (in my case 192.168.1.95).

收工!

Now you can turn the GPIOs high and low with your smartphone. 

继续延伸....

This is a basic example that shows you how easy it is to integrate an Android app with the ESP8266. You can take this example and modify it.

 

You could add multiple screens to the app, so you can other ESPs or add buttons to control more GPIOs.

如需更详细资料,如有好资源分享,请加入QQ交流群:214461008

欢迎阅读,欢迎转载,不用注明出处!本站只提供入门和进阶资料,做您学习的小伙伴!

请加群:214461008

相关文章
  • ESP8266使用指南(基于AT指令 NodeMCU 固件ESP-12E)

    ESP8266使用指南(基于AT指令 NodeMCU 固件ESP-12E)

    2016-04-28 17:50

  • 如何在Arduino平台上利用MFRC522 RFID实现安全访问

    如何在Arduino平台上利用MFRC522 RFID实现安全访问

    2016-04-28 10:54

  • ESP8266 ESP-12新手指南

    ESP8266 ESP-12新手指南

    2016-04-27 23:23

  • [转]Arduino ESP8266调试笔记

    [转]Arduino ESP8266调试笔记

    2016-04-22 23:57

网友点评
Arduino
热门教程
关注我们
自动化世界