How To Send Data From ESP32 to Machinechat JEDI
Overview
Machinechat JEDI provides a versatile platform for IoT projects, allowing easy data aggregation from various sensors. In this how-to, you will learn the process of setting up an Arduino-based board (ESP32) to collect data from a sensor and send it to Machinechat JEDI.
Setting Up Your Arduino Environment
Step 1: Gather Your Components
- ESP32 Board
- DHT11 or BME280 Sensor
- Connecting Wires
- Computer with Arduino IDE installed
Step 2: Install Arduino IDE
- Download and install the Arduino IDE from Arduino's official website.
- Launch the Arduino IDE after installation.
Step 3: Configure ESP32 Board in Arduino IDE
- Open Arduino IDE.
- Go to
File
>Preferences
. - In the "Additional Board Manager URLs" field, enter:
https://dl.espressif.com/dl/package_esp32_index.json
- Click "OK".
- Go to
Tools
>Board
>Boards Manager
. - Search for “ESP32” and install the latest version.
Step 4: Install Sensor Libraries
- Go to
Sketch
>Include Library
>Manage Libraries
. - Search and install the following libraries:
- For DHT11: “DHT sensor library” by Adafruit.
- For BME280: “Adafruit BME280 Library” by Adafruit.
Connecting the Sensor to ESP32
Step 1: Wiring the Sensor
- For DHT11:
- Connect the VCC of DHT11 to the 3V3 pin on ESP32.
- Connect the GND to the GND pin on ESP32.
- Connect the DATA pin of DHT11 to a digital pin on ESP32, like GPIO23.
- For BME280:
- Connect VCC to the 3V3 pin on ESP32.
- Connect GND to GND on ESP32.
- Connect SCL to GPIO22 on ESP32.
- Connect SDA to GPIO21 on ESP32.
Step 2: Testing the Sensor
- Open Arduino IDE.
- Load the example sketch for your sensor.
- For DHT11:
File
>Examples
>DHT sensor library
>DHTtester
. - For BME280:
File
>Examples
>Adafruit BME280 Library
>bme280test
. - Modify the pin numbers in the sketch to match your wiring.
- Select your ESP32 board and port under
Tools
. - Upload the sketch to your ESP32.
- Open the Serial Monitor to see if the sensor readings are displayed.
Integrating with Machinechat JEDI
Step 1: Choose a Data Collector Method
For sending data from ESP32 to Machinechat JEDI, you can use either the HTTP Data Collector or MQTT Broker Data Collector. We'll use the HTTP Data Collector for this example.
Step 2: Setting up the HTTP Data Collector in Machinechat JEDI
- Open Machinechat JEDI in a web browser.
- Navigate to the Data Collectors section.
- Enable the HTTP Data Collector, noting the configured port (default is 8100).
Step 3: Preparing the Arduino Sketch
- In the Arduino IDE, create a new sketch.
- Include libraries for WiFi and HTTPClient (for ESP32).
- Define your WiFi credentials.
- Connect to WiFi in the
setup()
function.
Step 4: Send Sensor Data
- In the
loop()
function, read the sensor data. - Formulate an HTTP POST request with the sensor data in JSON format.
void loop() { // Read sensor data (e.g., temperature, humidity) float temperature = readTemperature(); // Replace with actual function to read temperature float humidity = readHumidity(); // Replace with actual function to read humidity // Prepare JSON data String jsonData = "{\"context\":{\"target_id\":\"esp32_sensor\",\"target_ip\":\"" + WiFi.localIP().toString() + "\"},\"data\":{\"temperature\":" + String(temperature) + ",\"humidity\":" + String(humidity) + "}}"; // Send data to Machinechat JEDI HTTPClient http; http.begin("http://[IP_ADDRESS]:8100/v1/data/mc"); // Replace [IP_ADDRESS] with the IP of your Machinechat JEDI http.addHeader("Content-Type", "application/json"); int httpResponseCode = http.POST(jsonData); if (httpResponseCode > 0) { String response = http.getString(); Serial.println(httpResponseCode); Serial.println(response); } else { Serial.print("Error on sending POST: "); Serial.println(httpResponseCode); } http.end(); delay(5000); // Send data every 5 seconds }
- Replace
[IP_ADDRESS]
with the actual IP address of your Machinechat JEDI instance.
Testing and Validating Data Transmission
Step 1: Upload and Run the Sketch
- Connect your ESP32 to your computer.
- In the Arduino IDE, select the correct board and port under
Tools
. - Upload the sketch to your ESP32.
- Open the Serial Monitor to observe the output. It should show successful HTTP responses indicating data transmission to Machinechat JEDI.
Step 2: Verify Data
- In Machinechat JEDI, navigate to the dashboards section.
- Create a new Data View Dashboard if you haven't already.
- Add a chart to the dashboard.
- Select the data source corresponding to your ESP32 (e.g.,
esp32_sensor
). - Choose the metric you want to display (e.g., temperature, humidity).
- Save the dashboard and view the real-time data coming from your ESP32.
Step 3: Troubleshoot if Necessary
- If data is not appearing:
- Check your WiFi connection on the ESP32.
- Ensure the HTTP Data Collector is enabled in Machinechat JEDI.
- Verify the IP address and port number in the sketch match those of Machinechat JEDI.
- Look for any errors in the Serial Monitor output.
Step 4: Final Validation
- Once you see the sensor data reflected in the Machinechat JEDI's dashboard, your integration is successful.
- You can now use this setup to monitor real-time data from your sensor and make adjustments or set alerts.
You've now successfully mastered how to send data from Arduino-based boards to Machinechat JEDI. You can use this knowledge to leverage Machinechat JEDI's powerful data visualization and monitoring capabilities for building innovative IoT projects and sophisticated IoT solutions.