This project is made for the ESP8266 NodeMCU to control GPIO pins over HTTP, it works as an API endpoint.
- Clone this project.
- Enter the main folder and create a file named wifi_credentials.h, enter your WiFi SSID and password as such:
#define SSID "your ssid" #define PASSWORD "your password"
- Open the main.ino with Arduino IDE, upload the sketch to your ESP, and it is ready to use.
- To find the local IP of your ESP, check your router's DHCP clients list or reserve an address for your ESP's MAC address.
- You can now send POST requests to the IP address of your ESP8266 and it will reply. Check out the blink.py Python script for an example.
- In responses from ESP, a non-zero status value represents an error with parsing JSON.
- For analogRead of A0, specify pin as 0.
- Value 0 means INPUT
- Value 1 means OUTPUT
- Value 2 means INPUT_PULLUP
POST
{
"cmd": "pinMode",
"pin": 2,
"value": 1
}
Reply
{
"status": 0
}
POST
{
"cmd": "digitalRead",
"pin": 2
}
Reply
{
"status": 0,
"value": 1
}
POST
{
"cmd": "analogRead",
"pin": 0
}
Reply
{
"status": 0
"value": 768
}
- Value 0 means LOW
- Value 1 means HIGH
POST
{
"cmd": "digitalWrite",
"pin": 2,
"value": 1
}
Reply
{
"status": 0
}
POST
{
"cmd": "analogWrite",
"pin": 4,
"value": 137
}
Reply
{
"status": 0
}