As we are using 8-bit resolution, thus the duty cycle value will vary between 0-255 which we will map to 0-100%. Although you can use resolution between 1-16 bits. Additionally, we have set the PWM resolution to 8 bits as it is the optimal resolution to obtain the maximum frequency. We have set the PWM channel to 0, 1, 2 for three LEDs respectively. For defining the PWM channel we can choose between a total of sixteen PWM channels in ESP32. When we define the PWM parameters for each LED it includes the frequency of the signal, led channels and resolution. The brightness of the LED will be controlled through the duty cycle. The following variables define the PWM frequency, channels and the bit resolution. You can use any suitable output pin of ESP32. Here we are using the same GPIO pins as shown in the schematic diagram above. The following lines specify the GPIO pins of ESP32 connected with each of the colour pins of the RGB LED. The following three float variables will store the temperature, humidity and pressure readings acquired from the BME280 sensor. Then, we define the Adafruit_BME280 object named bme by setting it on the default I2C GPIO pins of ESP32. This will be the port where the server will listen to the requests. We will pass the default HTTP port which is 80, as the input to the constructor. The WebServer object will be used to set up the ESP32 web server. The Adafruit_Sensor and the Adafruit_BME280 libraries which we installed earlier are also included as they are necessary as we have to interface the sensor with the ESP32. The ArduinoJSON.h will be used for the JSON script. WiFi.h library is used to connect our ESP32 module with the local WIFI network. Importing Librariesįirstly, we will import the relevant libraries which are necessary for this project. Now, let us understand how each part of the code works. Serial.println("BME280 not found! Check Circuit") LedcSetup(blueChannel, frequency, resolution) LedcSetup(greenChannel, frequency, resolution) LedcSetup(redChannel, frequency, resolution) Void create_json(char *tag, float value, char *unit) ") Server.on("/led", HTTP_POST, handlePost) Server.on("/temperature", getTemperature) Setting PWM frequency, channels and bit resolution For this code to work with your ESP32 board you will have to replace the Wi-Fi network credentials. Open your Arduino IDE and go to File > New to open a new file. We will require the following components for this project: Pressure reading from BME280 (IP_address/pressure).Humidity reading from BME280 (IP_address/humidity).Temperature reading from BME280 (IP_address/temperature).In summary, ESP32 rest API web server will present four different JSON based Rest APIs Whereas, we will use POST method to control the RGB LED. The ESP32 will acquire temperature, pressure, and humidity readings from the BME280 that we can get from ESP32 using an HTTP GET request. Additionally, we will interface ESP32 with a BME280 sensor and an RGB LED. To send and receive data from ESP32 through REST APIs, we will use the postman application. We will create APIs that will be used to communicate with ESP32 using GET and POST requests. 7.3.In this tutorial, we will learn how to build a rest API web server using ESP32 that implements different REST APIs. Since the double-brace syntax is not valid JavaScript, we use the pm.variables.get() function to access the id variable.įinally, let's save the changes as we've done before. Pm.expect(pm.response.json().id).to.equal(pm.variables.get("id")) ) Pm.expect(pm.response.json().name).to.equal("Transformers")) We can use the id variable to do that: pm.test("success status", () => pm.response.to.be.success ) Secondly, we know which id to expect this time, so let's verify that id. Because the tests are similar, we can copy the tests from the POST request, then make a few changes.įirstly, we don't need to set the id variable again, so let's not copy that line. Since there's no body for a GET request, let's proceed directly to the Tests tab. Variables, when appearing outside of scripts, are referenced using the double-brace syntax. Thus, the GET request should retrieve the same instance that was created by the POST. In this URL, we're referencing the id variable that we previously set during the POST request.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |