/Esp32-API-Rest

Basic example of an ESP32 API server using PlatformIO

Primary LanguageC++

Esp32 API Rest

Basic example of an ESP32 API server using PlatformIO

In this API, the Esp32 is connected to a DHT11 sensor to read temperature and humidity data. Also included is a ws2812b rgb ribbon for sending and color changing. In addition, for practical purposes, the reading of the internal temperature of the device was included. Therefore, the API server on Esp32 will expose 4 different endpoints:

  • read the temperature
  • read the internal temperature
  • read humidity
  • send rgb color

lib_deps

lib_deps = 
	bblanchon/ArduinoJson@^6.19.4
	adafruit/Adafruit NeoPixel@^1.10.4
	adafruit/DHT sensor library@^1.4.3
	adafruit/Adafruit Unified Sensor@^1.1.5

Api

Use GET temperature

http://192.168.0.17/temperature

Response

{
	"type": "temperature",
	"value": 27.29999924,
	"unit": "°C"
}

Use GET humidity

http://192.168.0.17/humidity

Response

{
	"type": "humidity",
	"value": 43,
	"unit": "%"
}

Use GET internal

http://192.168.0.17/internal

Response

{
	"type": "internal",
	"value": 53.33333206,
	"unit": "mBar"
}

Use POST led

http://192.168.0.17/led

Body

{
	"red":133,
	"blue":222,
	"green":244
}