This project is now deprecated, as I am focusing all my efforts on the Arduino-compatible ESP8266 library. You can find the Arduino-compatible version of the library at https://github.com/marcoschwartz/aREST
aREST API for the ESP8266 WiFi chip using the NodeMCU firmware
A simple module that implements a REST API for the ESP8266 chip.
If you want to know more about aREST, go over to http://arest.io/.
- aREST.lua: the library file.
- examples: several examples using the aREST module
The library is in theory working with all the modules based on the ESP8266 chip. It was tested with the ElectroDragon ESP8266 module & the Olimex ESP8266 development board.
Using this library requires an ESP8266 board with the NodeMCU firmware running on it, and connected to your local WiFi network. You can learn more about the NodeMCU firmware on the NodeMCU GitHub repository (https://github.com/nodemcu/nodemcu-firmware).
You can also find a complete guide on how to setup an ESP8266 board with the NodeMCU firmware on:
To install the module, simply place the aREST.lua file at the root of your ESP8266 board. To do so you can use tools like ESPlorer (https://github.com/4refr0nt/ESPlorer) or LuaTool (https://github.com/4refr0nt/luatool).
This module follows the GPIO pins mapping as defined in the official NodeMCU firmware documentation.
- Connect a LED & resistor to pin number 1 of your ESP8266 board
- Start your ESP8266 module and get the IP address of the module. Let's assume here it is 192.168.1.103
- Put the basic.lua example at the root of your ESP8266 chip
- Execute the file via the dofile("basic.lua") command
- Go to a web browser and type
192.168.1.103/mode/1/oto set the pin as an output
- Now type
192.168.1.103/digital/1/1and the LED should turn on
The API currently supports five type of commands: digital, analog, and mode.
Digital is to write or read on digital pins of the ESP8266. For example:
/digital/1/0sets pin number 1 to a low state
/digital/1/1sets pin number 1 to a high state
/digital/1reads value from pin number 1 in JSON format (note that for compatibility reasons,
/digital/1/rproduces the same result)
Analog is to write or read analog values on the ESP8266. Note that you can only read analog values from analog pin 0. For example:
/analog/1/123sets pin number 1 to 123 using PWM
/analog/0returns analog value from pin number 0 in JSON format (note that for compatibility reasons,
/analog/0/rproduces the same result)
Mode is to change the mode on a pin. For example:
/mode/1/osets pin number 1 as a digital output
/mode/1/isets pin number 1 as a digital input
/mode/1/psets pin number 1 as a PWM output
Get data about the board
You can also access a description of all the variables that were declared on the board with a single command. This is useful to automatically build graphical interfaces based on the variables exposed to the API. This can be done via the following calls:
- The names & types of the variables will then be stored in the variables field of the returned JSON object