ESP8266 - ElectroDragon
ESP8266
> >Contents |
Specification
- Module power 3.3V, regular current consumption at 70ma, peak current at 240mA (300mA must be able to provided)
- +20Dbm power, 100M max transmitting distance on ideal circumstance.
- It is common and correct to see some random error data when module is power up, and end up with "ready" (Turn baud rate to 115200 can see this actual debug data, this is used for firmware updating)
IC Features
- 802.11 b / g / n
- WIFI @ 2.4 GHz, supports WPA / WPA2 security mode
- Ultra-small size module 11.5mm * 11.5mm
- Built-in 10 bit precision ADC
- Built-in TCP / IP protocol stack
- Built-in TR switch, balun, LNA, power amplifier and matching network
- Built-in PLL, voltage regulator and power management components
- 802.11b mode + 19.5dBm output power
- Supports antenna diversity
- Off leakage current is less than 10uA
- Built-in low-power 32-bit CPU: can double as an application processor
- SDIO 2.0, SPI, UART
- STBC, 1x1 MIMO, 2x1 MIMO
- The guard interval A-MPDU, the polymerization of the A-MSDU and 0.4 s of
- Within 2ms of the wake, connect and transfer data packets
- Standby power consumption is less than 1.0mW (DTIM3)
- Operating temperature range -40 ~ 125 ℃
AT Commands
- AT Command Instruction set, based on AT version 020
- AT command examples, based on AT version 020
- Becareful there are must be no any spaces between the " and IP address or port
- More extra At commands available based on custom AT firmware here: ESP8266 Custom AT Firmware
Pin Wiring (V090)
- Use FT232RL can supply enough power, must be genius IC of course
- Swap the uart pins if no data show up on the monitor
- There are two leds on the board, one is power led (RED), another one is status LED(BLUE), when power up, pwr led keeps on and status led will blink once.
- baud rate may work at 9600 (seems the latest correct one), 115200 or 57600
Module Pin Description
- Normal mode: Normal boot from flash, normal working mode
- Flash mode: Firmware flash mode
Pin | High Status | Low Status |
---|---|---|
VCC, GND* | ||
TXD, RXD** | ||
RST (maybe GPIO16) | N/C | restart |
CH_PD | normal mode and flash mode | - |
GPIO0 | - | flash mode |
GPIO 15*** | - | normal mode and flash mode |
GPIO 2 | should be high on when booting**** |
- * Better use standard alone power source, with large capacitor (CPOL-107), common GND
- ** The serial port, swap these two pins if no data come up. this is very easily go wrong. (TX to RX, and RX to TX, not TX to TX and RX to RX)
- *** N/A for PTH version WI07-01, available on SMD version
- **** Normally already set to high on default, just don't pull it low on booting
Setup Verification
- check two LEDS status when boot up, if this is not working, double check your wiring first then continue, don't forget CHPD to VCC
- check if your devices (phone) can find a wifi spot named like "ESP_98529F" or similar, the later number part is the mac ID, if you can see this wifi spot, it means your module boot up sucessfully
- swap RX and TX pins if you can not get AT commands response
- Tick "new line" option on SSCOM32 serial port monitor tool
- Try baudrate 9600 or 115200 normally should be these two, old version is 115200
- Don't forget to connect GPIO15 to GND if you are using the SMD model
First time use guide
Using arduino as serial port montior
- Connect VCC and GND of module to 3v3 and GND of arduino, RXD to TXD of arduino, and TXD to RXD of arduino (should add resistors or logic level shifter for logic level and protect IOs)
- Simply upload blink sketch to arduino, to ensure MCU won't use serial port
- User any other serial port monitor like SSCOM32 we used here, available here UART
- In the serial port, you should see "ready" in the end of the random data after powered up.
- Send AT (commands, with "newline option")will receive OK in return.
Steps and note
- AT+RST restart the module, received some strange data, and "ready"
- AT+CWMODe=3 change the working mode to 3, AP+STA, only use the most versatile mode 3 (AT+RST may be necessary when this is done.)
Join Router
- AT+CWLAP search available wifi spot
- AT+CWJAP=“you ssid”, “password” join my mercury router spot (ops, the wifi password is here :) )
- AT+CWJAP=? check if connected successfully, or use AT+CWJAP?
TCP Client
- AT+CIPMUX=1 turn on multiple connection
- AT+CIPSTART=4,"TCP","192,168.1.104",9999 connect to remote TCP server 192.168.1.104 (the PC)
- AT+CIPMODE=1 optionally enter into data transmission mode
- AT+CIPSEND=4,5 send data via channel 4, 5 bytes length (see socket test result below, only "elect" received), link will be "unlink" when no data go through
TCP Server
- AT+CIPSERVER=1,9999 setup TCP server, on port 9999, 1 means enable
- AT+CIFSR check module IP address
- PC as a TCP client connect to module using socket test, send data
Socket test running result
- In the sockettest, do not tick the "secure" in TCP client, it causes unstable
Other Arduino Demo Code
- In this case, the wifi module still connect to hardware serial (software serial port can not higher than 19200 baud rate), and another software serial port should be created on arduino and print out via another serial port
- So the connection should be
Wifi's uart to arduino hardware uart; arduino's sotware UART to another serial port device, for example like FTDI basic, CP2102 breakout, etc, and this serial port device can connect to PC to read data
- change the SSID and password in code for your wifi router
#include <SoftwareSerial.h> #define SSID "xxxxxxxx" #define PASS "xxxxxxxx" #define DST_IP "220.181.111.85" //baidu.com SoftwareSerial dbgSerial(10, 11); // RX, TX void setup() { // Open serial communications and wait for port to open: Serial.begin(57600); Serial.setTimeout(5000); dbgSerial.begin(9600); //can't be faster than 19200 for softserial dbgSerial.println("ESP8266 Demo"); //test if the module is ready Serial.println("AT+RST"); delay(1000); if (Serial.find("ready")) { dbgSerial.println("Module is ready"); } else { dbgSerial.println("Module have no response."); while (1); } delay(1000); //connect to the wifi boolean connected = false; for (int i = 0; i < 5; i++) { if (connectWiFi()) { connected = true; break; } } if (!connected) { while (1); } delay(5000); //print the ip addr /*Serial.println("AT+CIFSR"); dbgSerial.println("ip address:"); while (Serial.available()) dbgSerial.write(Serial.read());*/ //set the single connection mode Serial.println("AT+CIPMUX=0"); } void loop() { String cmd = "AT+CIPSTART=\"TCP\",\""; cmd += DST_IP; cmd += "\",80"; Serial.println(cmd); dbgSerial.println(cmd); if (Serial.find("Error")) return; cmd = "GET / HTTP/1.0\r\n\r\n"; Serial.print("AT+CIPSEND="); Serial.println(cmd.length()); if (Serial.find(">")) { dbgSerial.print(">"); } else { Serial.println("AT+CIPCLOSE"); dbgSerial.println("connect timeout"); delay(1000); return; } Serial.print(cmd); delay(2000); //Serial.find("+IPD"); while (Serial.available()) { char c = Serial.read(); dbgSerial.write(c); if (c == '\r') dbgSerial.print('\n'); } dbgSerial.println("===="); delay(1000); } boolean connectWiFi() { Serial.println("AT+CWMODE=1"); String cmd = "AT+CWJAP=\""; cmd += SSID; cmd += "\",\""; cmd += PASS; cmd += "\""; dbgSerial.println(cmd); Serial.println(cmd); delay(2000); if (Serial.find("OK")) { dbgSerial.println("OK, Connected to WiFi."); return true; } else { dbgSerial.println("Can not connect to the WiFi."); return false; } }
Debug and Note
- Better use standalone power source, not using power from USB-TTL module, it may not able to provide sufficient current.
- Module will disconnect "unlink" TCP/UDP when no data go through
- Wait AT commands feedback and continue, otherwise will return "busy"
- Potential cause for "error" : password length must be more than 8 bytes, use multiple connection and mode three, try disconnect current connection before try "AT+CWLAP" (module will reconnect after restart), re-flash firmware.
- mac address please check in your router page or use arp to check.
- (1st Oct.) change CR to CR/LF (\r\n in coding), which means "carriage return and line feed" for new firmware version 0.92
Firmware
Latest firmware
- Espressif firmware source updated at http://bbs.espressif.com
- Complied AT firmware (custom version 0.95 based on espressif SDK 0.93), see log update on this page ESP8266 Custom AT Firmware
Tools and how to update firmware
You can find all the tools on our documents link at the end of this page. two types of firmware examples available: AT (Commands, normally only UART pins used) and IO (Control, full IOs version)
How to use for XTCOM
- Download the bin file
- Set the module to update mode, connect the module : choose "tools" - "configure device"
- Upload bin file: API Test - Flash image download
- upload the bin file eagle.app.v6.flash.bin at 0x00000 (app)
- upload the second bin file eagle.app.v6.irom0text at 0x40000 (this one is optionally, libraries)
Firmware Details
Boot Process
- Reset vector is 0x40000080.
- Boots into Espressif code in IROM0.
- Loads SPI ROM data.
- Starts executing ESP SDK-code shadowed SPI ROM (unconfirmed).
SPI Flash ROM Layout
Address | Size | Name | Description |
---|---|---|---|
00000h | 248k | app.v6.flash.bin | User application |
3E000h | 8k | master_device_key.bin | OTA device key |
40000h | 240K | app.v6.irom0text.bin | SDK libraries |
7C000h | 8k | esp_init_data_default.bin | Default configuration |
7E000h | 8k | blank.bin | Filled with FFh. May be WiFi configuration. |
SDK
- GCC Linux toolchain nurdspace First setup guide - GCC https://nurdspace.nl/ESP8266/First_setup, not yet tested to work with 0.92 firmware, work with 0.91 (seems different settings, need update)
- SDK source code and more tools please find on the drive for now, examples folder includes AT (default UART commands flashed in the module) and IoT demo (simple webserver, socket, light control, etc)
IC Pin Defintion
Pin | Name | Type | GPIO | Function | UART, IIC, 3Bits SDIO, LED | Plug/PWM light/Sensor | Boot |
---|---|---|---|---|---|---|---|
1 | VDDA | P | Analog Power 3.0 ~3.6V | ||||
2 | LNA | IO | RF Antenna Interface,Chip Output Impedance=50 Ω Recommend that the π- type matching network is retained. | ||||
3 | VDD3P3 | P | Amplifier Power 3.0~3.6V | ||||
4 | VDD3P3 | P | Amplifier Power 3.0~3.6V | ||||
5 | VDD_RTC | P | NC(1.1V) | ||||
6 | TOUT | I | ADC Pin | ||||
7 | CHIP_EN | I | Chip Enable. High: On, chip works properly; Low: off power supply, minimum current | High for booting | |||
8 | XPD_DCDC | IO | GPIO16 | Deep-Sleep Wakeup, external RST, low to reset, high for working mode | |||
9 | MTMS | IO | GPIO14 | HSPICLK | I2C SCL | IR recv | |
10 | MTDI | IO | GPIO12 | HSPIQ | Communication status LED | (Light)PWM red LED control | |
11 | VDDPST | P | Digital/IO Power Supply (1.8V~3.3V) | ||||
12 | MTCK | IO | GPIO13 | HSPID | RST Key | (Light)PWM blue LED control; (plug) RST Key | |
13 | MTDO | IO | GPIO15 | HSPICS | 3bits SDIO | (Light)PWM green LED control; (Plug) relay control, H/L TTL | Low for booting |
14 | GPIO2 | IO | GPIO2 | UART Tx during flash progamming (?); must be high when booting, already set to high on default | 3bits SDIO; UART1 system info print (TX); I2C SDA | ||
15 | GPIO0 | IO | GPIO0 | SPICS2 | 3bits SDIO; Status LED | (plug) wifi status LED | Low for flashing mode |
16 | GPIO4 | IO | GPIO4 | ||||
17 | VDDPST | P | Digital/IO Power Supply (1.8V~3.3V) | ||||
18 | SDIO_DATA_2 | IO | Connect to SD_D2 (Series R 200Ω);SPIHD; HSPIHD | ||||
19 | SDIO_DATA_3 | IO | Connect to SD_D3 (Series R 200Ω); SPIWP; HSPIWP | ||||
20 | SDIO_CMD | IO | Connect to SD_CMD(Series R 200Ω); SPICS0 | ||||
21 | SDIO_CLK | IO | Connect to SD_CLK (Series R 200Ω); SPICLK | ||||
22 | SDIO_DATA_0 | IO | Connect to SD_D0 (Series R 200Ω); SPIQ | ||||
23 | SDIO_DATA_1 | IO | Connect to SD_D1 (Series R 200Ω); SPID | ||||
24 | GPIO5 | P | GPIO5 | ||||
25 | U0RXD | IO | GPIO3 | UART Rx during flash progamming (?) | UART0 for user | ||
26 | U0TXD | IO | GPIO1 | GPIO1; SPICS1 (?) | UART0 for user, do not allow low when booting | ||
27 | XTAL_OUT | IO | Connect to crystal output, can be used to provide BT clock input | ||||
28 | XTAL_IN | IO | Connect to crystal input | ||||
29 | VDDD | P | Analog Power 3.0~3.6V | ||||
30 | VDDA | P | Analog Power 3.0~3.6V | ||||
31 | RES12K | I | Connect to series R 12kΩ to ground | ||||
32 | EXT_RSTB | I | External reset signal (Low: Active) |
Documents
Links
- Our documents link here, will keep updating from time to time.
- ESP8266 wiki page, very helpful
- ESP8266 IoT Standard example (in Progress)
The new AT ESP8266 V0.9.5 firmware release, more stable, support intelligent connection technology and OTA upgrades!
AT firmware release new, more stable, support intelligent connection technology!
Download: <ignore_js_op style="outline: none;"> Shun v0.9.5.2AT firmware can support SmartLink.rar
Welcome to the Q group AC: 222 651 602 / 146 137 081
in transparent mode, even power down automatically after power recovery still transparent mode , even in large amounts of data is not a crash restart.
This is a transparent mode in the true sense!
Due to changes in the AT command is very large, and the past is not compatible with AT firmware, please consult the attached manual, support for more instructions!
Currently supported: Support OTA upgrade (using the module to connect Internet routing, then AT + CIUPDATE, can be upgraded)
Shun be intelligent connection technology AI-LINK
Yue Xin intelligent connection technology ESP-TOUCH
micro-channel intelligent connection technology AIR-KISS
Smart LINK APP: without direct connection module can be configured modules.
<ignore_js_op style="outline: none; color: rgb(68, 68, 68); font-family: 'Microsoft yahei', 微软雅黑, Arial, Helvetica, sans-serif, 宋体; font-size: 14px; line-height: 16.7999992370605px;">
Features Introduction and Usage instructions:
. ai-link.app to install a mobile phone (ai-link.APK to install Cell Phone.)
b v0.9.5.1 AT firmware to burn. 0x00000 address ( Burn v0.9.5.1 . AT Firmware to 0x00000)
. c using AT commands via serial debugging tools (enjoy AT command).
Before using AT commands, please read the PDF document (Before using AT command, please read documents).
Frequently Asked Questions (FAQ):
How to Use ai-thinker of smart link technology? (? How to use ai-thinker's smart link technology)
to perform AT + CWSMARTSTART = 0 (EXECUTE: AT + CWSMARTSTART = 0)
to install and use smart link APP fill SSID and PASSWORD perform module configuration (And use smart link software push on the phone SSID and password over the ai-link technology.)
How to control GPIO and ADC? (Read How to Control GPIO and ADC?)
AT + CIPAP? AT Returns the IP address of the module current AP mode + CIPAP = "192.168.4.2" Setting the IP address of the AP mode
AT + CIPSTA? View IP address AT STA mode + CIPSTA = fixed IP "192.168.1.2" STA mode setting above operations are Effective Immediately without restarting
AT + CIPAPMAC Query the current MAC address of the AP mode Settings for the current MAC address of the AP mode AT + CIPAPMAC =? "1a : fe: 34: 9E: 34: a9 "
AT + CIPSTAMAC exercise STA MAC address mode AT + CIPSTAMAC =? "18: fe: 34: 9E: 34: a9" AP mode Settings for the current MAC address
reads command AT + CIOADC Note the ADC value: ADC input Voltage range is 0V to 1V BETWEEN 0 to 1024,10 bit Precision!
AT + CIOREAD command reads the GPIO AT + CIOREAD = 0 reads GPIO0 High Level Assumptions GPIO0 is, Will it return 1: HIGH, otherwise it Returns 0: LOW range of Digital GPIO, GPIO0, GPIO16 CAN
AT + CIOWRITE command to set the GPIO AT + CIOWRITE = 0,0 GPIO0 Level setting is low AT + CIOWRITE = 16, 1 set of High Level GPIO16
Baud rate Support WIDER , 110,300,600,1200,2400,4800,9600,19200,38400,57600,74880,115200,230400,256000,460800,921600 AT + CIOBAUD = 115200,8,1,0,3 ORAT + CIOBAUD = 115200 CAN baudrate set you want
ESP8266 Quick Start
http://benlo.com/esp8266/esp8266QuickStart.html
ESP8266 Quick Start
This page is meant to be a quick introduction to the ESP8266 for those who are confused by all of the information available on the various blogs and forums who just want to try out this exciting board in the shortest possible time. This guide is for Windows users who want to use the NodeMCU environment.
Not counting waiting for hardware to ship to you (1-10 days), you should be able to use your ESP8266 for something useful in less than an hour. Ready?
What do I need to buy?
You will need an ESP8266 development board. There are several ESP8266 boards available, usually numbered ESP-01 through ESP-12. Check the pins of the actual board you order with the information from your source as the rapid development of these products has led to confusion and duplication of board identification numbers.
The prices vary from around $2 for a simple ESP-01 to $15 for a complete board with USB to serial and 3.3 volt regulator. The ESP-01 is a simple board to start with. The ESP-12 is popular because of its size and the number of pins brought to the side of the board. Recently, more development boards have become available with additional sensors, relays, LEDs and voltage regulators on the board.
A 3 volt power supply. The ESP8266 runs on anything from 1.8 to 3.5 volts, so a couple of AA batteries will work. Most of us use a 3.3 volt regulated power source. Maximum current draw is 300 mA, so use a supply that can supply 500 mA to be safe. More is better. A weak supply will cause the board to reset unexpectedly and make debugging difficult. The NodeMCU Development Board has a USB power supply on the board.
A USB to serial adapter. This should be a 3.3 volt compatible model. It is possible to level convert if you already have a 5 volt adapter. The NodeMCU Development Board has the USB to serial interface on the board. When you receive your adapter, verify that the actual voltage output is 3.3 volts as some cheap adapters have been found to be mislabelled. Any of the following should work: FTDi,CH340, FT232RL.
What do I need to download?
The ESP8266 board you bought may have one of many different firmware versions on it. Many come with AT firmware for serial communications. Some come with no user firmware at all. I recommend the NodeMCU Lua firmware as a starting point because it gives you an interactive programming language which allows you to experiment and build simple working programs without a lot of effort. If you are not familiar with Lua, you will find that it is not hard to learn, at least for the simple tasks needed to get started.
The tool you will use to flash the NodeMCU firmware on your ESP8266 board is thenodemcu-flasher. It is open source on github. Go to the nodemcu-flasher page and choose Win32 or Win64 depending on your computer system. Click on ESP8266Flasher.exe and then right click on View Raw and Save Link As... to download the application to your PC. Or use the direct links below:
ESP8266Flasher.exe for Win32
ESP8266Flasher.exe for Win64
What do I have to connect?
The actual connections will depend on the board you have and the USB to serial adapter you are using.
- Power.
- +3.3 volts to Vcc
- ground
- Communications.
- TxD on the board to RxD on the adapter
- RxD on the board to TxD on the adapter
- Ground
- Jumpers.
- Connect Vcc to CH_PD to enable the chip
- Connect GPI0 to GND to enable flash reprogramming
How do I install NodeMCU on my ESP8266?
Plug the USB to serial adapter into your PC. Most adapters are automatically recognized by Windows 7 and 8. Users of XP or older versions of Windows may need a driver which should be supplied by the manufacturer of the USB adapter. The adapter will appear as a new COM port on your system. Check the Device Manager if necessary.
Run ESP8266Flasher.exe
If you only have one COM device, the port will appear automatically. If you have more than one, select the correct one from the drop down menu.
The program comes with default NodeMCU firmware in memory. This is unlikely to be the latest version, but to get started, just use the default internal image. Later, you can download the latest firmware version, then select the [Config] tab to choose the .bin file to flash to the chip.
Click on Flash(E) to start the programming process. If the MAC addresses don't appear within a few seconds, disconnect the power to the board and reconnect it. If it still doesn't work, check your connections. Make sure that the jumper between GND and GPIO0 is there so that the board is in reflash mode.
Reflashing the chip will take a couple of minutes. When the job is done, disconnect power from the board and remove the jumper from GND to GPIO0 to leave reflash mode.
You are now ready to program the ESP8266 for your own application.
How do I communicate with the ESP8266?
The NodeMCU Lua firmware you have just installed communicates with the PC over the serial link. You can use PuTTY, SimpleTerm, or any other terminal program that you like to write Lua programs or enter direct commands to the board. The default speed is 9600 baud, but that can be changed to any other baud rate once you have established communications.
LuaLoader
LuaLoader is a Windows program for uploading files to the ESP8266 and working with the Lua serial interface. As well as being a simple terminal program, it has built in Lua command buttons that make it easy to interact and experiment with the ESP8266 board.
Download: LuaLoader.zip
LuaLoader.exe is a simple Windows application that requires no special installation.
From the Settings menu, select COM Port Settings and choose the appropriate COM port for your USB to serial adapter. Don't change any other setting.
Clicking buttons on LuaLoader sends commands to the board. Power your board and watch for the initial message. After displaying some funny characters (these are firmware reset parameters sent at 74880 baud), you should see the version information of the NodeMCU build:
NodeMCU 0.9.5 build 20150107 powered by Lua 5.1.4
LuaLoader will warn you if a later firmware build is available.
After booting, NodeMCU will attempt to run a file called init.lua in flash memory. Since you haven't put it there, it will report an error and show the > prompt. You are now ready to interact with Lua on the ESP8266.
Click the Heap button to display the amount of RAM available. LuaLoader will type the command = node.heap()and the ESP8266 will respond with 23016 or some other value, followed by the > prompt again.
How do I connect to an Access Point?
Enter the SSID and password of your closest access point in the appropriate text box on LuaLoader. Click Set AP. LuaLoader will type the commands to set the WiFi mode and connect. This information is saved in flash memory and will be remembered until changed, even if the board is powered down.
Click the WiFi button to check the connection status.
Click Get IP to confirm that the ESP8266 is connected to your access point.
Click the Survey button to list the available access points visible to the ESP8266. The SSID, authentication mode, signal strength, MAC address and channel are shown.
All of the commands typed by LuaLoader can be entered manually, or saved in a file to be run automatically.
How do I read a GPIO input?
The Lua function gpio.read(pin) reads the value of the input specified by pin if the GPIO has been set up as an input.
LuaLoader makes this easy to test. Select pin 3 GPIO0 from the GPIO dropdown menu, select input and floating from the mode dropdown menus. Click Set. Then, click Read. The current pin value will be 0 or 1. In this case, 1 as that pin is held high normally.
Note that if GPIO0 is low on reset, the chip will enter reflashing mode, so you must ensure that any use of that GPIO0 for user input is high when the device is powered on or reset.
To read the value of the input pin repeatedly, in LuaLoader, click on the clock beside the Read button. Note, that if you are using the NodeMCU development board, the button marked FLASH will change the value from 1 to 0 when the button is pressed as it is connected to GPIO0 and ground. The read rate can be changed in the Settings menu.
How do I send data to a server?
The demo script httpget.lua connects to this webserver and sends the time it took to connect (in microseconds) and the amount of heap (RAM) available at that time.
Download the script to your computer, then upload it to your ESP8266 using theUpload File button.
-- tested on NodeMCU 0.9.5 build 20141222...20150108 -- sends connection time and heap size to http://benlo.com/esp8266/test.php print('httpget.lua started') Tstart = tmr.now() conn = nil conn = net.createConnection(net.TCP, 0) -- show the retrieved web page conn:on("receive", function(conn, payload) success = true print(payload) end) -- once connected, request page (send parameters to a php script) conn:on("connection", function(conn, payload) print('\nConnected') conn:send("GET /esp8266/test.php?" .."T="..(tmr.now()-Tstart) .."&heap="..node.heap() .." HTTP/1.1\r\n" .."Host: benlo.com\r\n" .."Connection: close\r\n" .."Accept: */*\r\n" .."User-Agent: Mozilla/4.0 " .."(compatible; esp8266 Lua; " .."Windows NT 5.1)\r\n" .."\r\n") end) -- when disconnected, let it be known conn:on("disconnection", function(conn, payload) print('\nDisconnected') end) conn:connect(80,'benlo.com')
Connect to your access point first using the Set AP button. This is not normally necessary if you have set the correct AP since the last time you flashed new firmware.
Use the dofile button to run the file you have just uploaded.
The contents of the retrieved page should be displayed.
Feel free to use my server for a few tests, but please change to your own webserver or sign up for one of the public internet of things servers, such as thingspeak.com. Claudiuchiru has posted an example of sending temperature (using an inexpensiveBS18B20 I2C sensor) to thingspeak.com.
This simple script is all it takes to make useful gadgets from the simplest ESP-01 board. The board can be connected so that it receives power when a device is on, a button is pressed, motion is detected, a magnet trips a reed switch, etc. etc.
The php script will receive the signal and can be programmed to send an email, send an sms, push a notification to your phone, or simply log events for future reference.
Our well pump is now monitored by an ESP-01 running a simple script once every 30 seconds when the power is on. As well as logging the activity and sending a daily email report, the script sends out emergency notifications if the pump runs for more than 2 hours, or hasn't run for more than 36 hours.
A motion detector with a relay turns on another ESP-01 which runs the same program but calls a different php script to alert me when there is motion in front of the house. My phone receives the alert before the doorbell is pressed.
How do I make the program run automatically?
When the ESP8266 starts, it runs the init.lua file. Simply create a file called init.luawhich runs the file with your program instructions. It is also a good place to initialize any variables you are using, such as the SSID of the access point. While debugging, it is a good idea to use a timer to call your file after a few seconds. If you make a mistake, causing a crash, you will have a few seconds to stop the timer with thetmr.stop button before the program starts to run again. For the example above, one line will do:
tmr.alarm(0,10000,0,function() dofile('httpget.lua') end)
Arm timer number 0 to execute the function dofile('httpget.lua') in 10 seconds.
How can I learn more?
The Help menu of LuaLoader has a large number of links to ESP8266 and Lua resources for convenient access while programming. There is also a menu item linking files on your computer you may have downloaded for reference.
- NodeMCU Lua API Reference
- The esp8266 community forum. Lots of sample scripts.
- Technical Overview of the ESP8266 by Nurdspace
- Lua.org, home of the Lua language.
- NodeMCU github Lua source and latest binaries
- Espressif Systems, manufacturer of the ESP8266
Buy me a beer. Donations to support this web site are gratefully accepted. You can use PayPal, credit card, or bitcoin. No amount is too small.