Skip to content

edvinsmineikis/ESP8266-GPIO-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This project is made for the ESP8266 NodeMCU to control GPIO pins over HTTP, it works as an API endpoint.

How to start?

  1. Clone this project.
  2. 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"
    
  3. Open the main.ino with Arduino IDE, upload the sketch to your ESP, and it is ready to use.
  4. 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.
  5. 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.

Commands list

  • In responses from ESP, a non-zero status value represents an error with parsing JSON.
  • For analogRead of A0, specify pin as 0.

pinMode

  • Value 0 means INPUT
  • Value 1 means OUTPUT
  • Value 2 means INPUT_PULLUP

POST

{
    "cmd": "pinMode",
    "pin": 2,
    "value": 1
}

Reply

{
    "status": 0
}

digitalRead

POST

{
    "cmd": "digitalRead",
    "pin": 2
}

Reply

{
    "status": 0,
    "value": 1
}

analogRead

POST

{
    "cmd": "analogRead",
    "pin": 0
}

Reply

{
    "status": 0
    "value": 768
}

digitalWrite

  • Value 0 means LOW
  • Value 1 means HIGH

POST

{
    "cmd": "digitalWrite",
    "pin": 2,
    "value": 1
}

Reply

{
    "status": 0
}

analogWrite

POST

{
    "cmd": "analogWrite",
    "pin": 4,
    "value": 137
}

Reply

{
    "status": 0
}

About

ESP8266 API for controlling GPIO over HTTP

Resources

Stars

Watchers

Forks