Contact Sales

All fields are required

Communicate Temperature and Humidity Data with… | SignalWire

Communicate Temperature and Humidity Data with SignalWire AI Agent

Build with ESP8266, a DHT11 sensor, and SignalWire's AI Agent

FreeSWITCH Enterprise Support Lead

Len Graham

SignalWire's AI Agent for voice allows you to build and deploy your own digital employee with intelligent, personalized interactions that redefine customer experiences. Powered by advanced natural language processing (NLP), these digital employees understand caller intent, retain context, and generally behave like a human.

If you’re interested in using AI to gather and communicate environmental data, this code walkthrough will show you how to integrate an ESP8266, a popular microcontroller, with a DHT11 sensor to gather temperature and humidity data. You can then leverage the power of SignalWire's AI Agent to process and respond to user queries regarding this data.

In this post, we'll explore how to leverage ESP8266,, and the DHT11 sensor data to interact seamlessly with SignalWire's AI technology. For a more straightforward demo that uses public APIs and has no hardware requirements, check out the Weather Bot example.

How It Works

This example shows you how to create an AI voice agent that a caller can contact to ask for data on the temperature and humidity of a specified location. Then, if the caller asks, it can send a text message reiterating that information.

In the GitHub repository, you'll find all the necessary files and resources to kickstart your own sensor bot project.

sensor_data Function

Perl modules:

  • LWP::Simple for fetching data from the web,

  • JSON for parsing JSON data,

  • Plack for creating a simple web application, and

  • SignalWire::ML for constructing responses (assuming this is part of your application's architecture).

Setting Up Your Perl Script

To begin, ensure you have Perl installed on your system along with the required modules. You can easily install missing modules using CPAN.

Import the required modules at the beginning of your script to lay the foundation for seamless integration:

Fetching JSON Data

Now, define the URL for the JSON data containing environmental information from a specified channel using ThingSpeak's API.

We'll use LWP::Simple's get function to retrieve the data securely:

Processing the JSON Data

Once we have the JSON data in hand, it's time to decode it into a Perl data structure using the JSON module.

From there, we'll extract the temperature and humidity values from the latest feed entry:

Constructing the HTTP Response

With the sensor data, craft a response using Plack::Response. Set the content type to application/json:

Include the temperature and humidity information in the response body:

Finalizing the Response

Our response is primed and ready to go. We'll finalize it and return it from our application, completing the interaction loop:

The Prompt

The prompt is the backbone of your AI agent, used to define its personality, functions, and parameters. You can easily customize it with plain language instructions.

With ESP8266, the DHT11 sensor, and SignalWire's AI agent, we've created a sophisticated sensor bot capable of providing real-time environmental insights. You can use this to monitor the climate of an attic or basement or just explore new IoT horizons!

Have any questions as you’re building an AI agent? Bring them to our community discord, forum, or Slack!

Related Articles