In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to obtain sensor data through Siri speech recognition, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
How to obtain sensor data through Siri speech recognition.
Project Overview
In the previous article, I showed you in detail how to use Siri to control ESP32 and LED lights. This article is an advanced step from the previous article, and I will continue to teach you how to use Siri to read data from various sensors.
Friends who have not read the previous article suggest to take a look at the content of part 1 first.
Jump link: control panel Siri speech recognition part 1: LED lamp control
This time the main control board is still the control board (ESP32), of course, as I said in the previous chapter, you can also choose other ESP32 or ESP8266 series development boards, the implementation method and effect is similar. The sensor data read include the sound sensor, the light sensor, and the external DHT11 temperature and humidity sensor. After learning this chapter, I hope you can learn to modify the corresponding code and replace it with other sensors.
In this project, we also set the dashboard ESP32 as a Web server, and when users access the server's domain name address (or IP address) on a web page, they will jump to the following interface. The final effect is that not only Siri speech recognition can be used to obtain sensor data, but also sensor data can be viewed directly on the web page.
We can control the RGB LED on the control board by clicking the switch switch of LED, or we can access the corresponding domain name address of the switch to control the light of LED.
For sensors, we can directly read the data of all sensors on the web page at one time, or we can access the corresponding domain name address of each sensor separately to read the corresponding data. In this way, the basic functions of controlling the control board and reading data through the Web page are completed.
After this foundation, we can set up some voice assistants, such as Siri, Tmall voice wizard, etc., to access the corresponding domain name address through voice commands, so as to achieve the function of speech recognition switch lights and read sensor data.
Circuit connection
In this project, we need to connect an external DHT11 temperature and humidity sensor to the P0 pin of the controller board through the expansion board, as shown in the following figure. Sound data and light data can be read directly through the two sensors on the account of the control board.
Library file installation
This project requires four Arduino libraries: in addition to the Adafruit_NeoPixel, ESPAsyncWebServer and AsyncTCP used in the previous chapter, we also add the DHT function library, which is mainly used to read the values of DHT11 temperature and humidity sensors. no, no, no.
Arduino library installation tutorials are not the focus of this article, here will not repeat, only give 4 libraries URL, you can find their own Baidu Arduino how to install the library.
Adafruit_NeoPixel: https://github.com/adafruit/Adafruit_NeoPixel
ESPAsyncWebServer: https://github.com/me-no-dev/ESPAsyncWebServer
AsyncTCP: https://github.com/me-no-dev/AsyncTCP
DHT: https://github.com/adafruit/DHT-sensor-library
Arduino code
The code of this chapter is modified on the basis of the previous chapter, so the basic part will not be repeated, only the differences and additions will be explained.
Header file and initialization definition
At the beginning of the program, we first introduced the library functions that we need to use:
# include "WiFi.h" # include "ESPAsyncWebServer.h" # include "Adafruit_NeoPixel.h" # include "Adafruit_Sensor.h" # include "DHT.h"
Then set the account and password of the network:
Const char * ssid = "wifi_name"; const char * password = "wifi_password"
Then define some sensor and actuator pins and initialize them:
# define SOUNDPIN 36 / / P10#define LIGHTPIN 39 / / P4#define LEDPIN 17 / / P7#define DHTPIN 33 / / P0
Then the DHT object, NeoPixel object (RGB LED lamp) and WebServer object are defined:
# define DHTTYPE DHT11DHT dht (DHTPIN, DHTTYPE); Adafruit_NeoPixel pixels (3, LEDPIN, NEO_GRB + NEO_KHZ800); AsyncWebServer server (80); Web page design
Then there is the interface design of the control board Web server, the interface design uses the HTML language, here first put a most basic interface design. The HTML-related code is stored in the index_html variable.
Const char index_html [] PROGMEM = R "rawliteral (/ / HTML code here) rawliteral"
The basic HTML page design code is as follows:
Html {font-family: "Microsoft Yahei"; text-align: center;} Dashboard Home data Center Light On
Light Off
Voice:% SOUND%
Light:% LIGHT%
Temperature:% TEMPERATURE% ℃
Humidity:% HUMIDITY%%
The effect of this code on the web page is as follows. We can see that a lot of data is between two percent signs (%). For example,% SOUND%, is a placeholder. After we read the data of the corresponding sensor in the program, we can automatically replace it. There will be a special function program to replace it, which will be discussed below.
Sensor data reading function
First of all, read the function of DHT11 temperature and humidity sensor, this part is relatively simple, just refer to the routine of DHT function library directly:
String readDHTTemperature () {float temperature = dht.readTemperature (); if (isnan (temperature)) {Serial.println ("Failed to read from DHT sensor!"); return "-";} else {Serial.println (temperature); return String (temperature);}} String readDHTHumidity () {float humidity = dht.readHumidity (); if (isnan (humidity)) {Serial.println ("Failed to read from DHT sensor!"); return "-" } else {Serial.println (humidity); return String (humidity);}}
Then there is the processor () function, which mainly replaces all placeholders in the web page with the corresponding sensor values. It returns the corresponding data based on the name of the placeholder.
/ / Replaces placeholder with sensor valuesString processor (const String& var) {if (var = = "SOUND") {return String (analogRead (SOUNDPIN));} if (var = = "LIGHT") {return String (analogRead (LIGHTPIN));} if (var = = "TEMPERATURE") {return readDHTTemperature ();} if (var = = "HUMIDITY") {return readDHTHumidity ();} return String ();} setup ()
In the initialization function setup (), we first initialize the serial port, RGB lamp, and DHT11 sensor:
Serial.begin (9600); pixels.begin (); dht.begin ()
Then connect the control board to the network and print the IP address in the serial port:
/ / Connect to Wi-FiWiFi.begin (ssid, password); while (WiFi.status ()! = WL_CONNECTED) {delay (1000); Serial.println ("Connecting to WiFi..");} Serial.println ("WiFi connected"); / / Print ESP32 Local IP Address and Some TipsSerial.print ("Open your brower, and visit: http://");Serial.println(WiFi.localIP());Serial.println();"
Finally, there is the most important Web server setting. For a detailed tutorial on Web server setup, you can check out the official website: https://github.com/me-no-dev/ESPAsyncWebServer
Only the code needed for this article is released here. When you access the root directory "/", all the data and related control buttons are displayed. The data that is shown here calls the processor function mentioned above.
/ / Root / Webpageserver.on ("/", HTTP_GET, [] (AsyncWebServerRequest * request) {request- > send_P (200, "text/html", index_html, processor);})
Set the LED light to on when accessing the "/ led=on" path, and set the LED light to off when accessing the "/ led=off" path.
/ Webpage to turn on lightserver.on ("/ led=on", HTTP_GET, [] (AsyncWebServerRequest * request) {pixels.setPixelColor (0, 0xFF0000); pixels.setPixelColor (1, 0xFF0000); pixels.setPixelColor (2, 0xFF0000); pixels.show (); Serial.println ("LED is on"); request- > send_P (200, "text/plain", "led on");}) / Webpage to turn off lightserver.on ("/ led=off", HTTP_GET, [] (AsyncWebServerRequest * request) {pixels.setPixelColor (0, 0x000000); pixels.setPixelColor (1, 0x000000); pixels.setPixelColor (2, 0x000000); pixels.show (); pixels.clear (); Serial.println ("LED is off"); request- > send_P (200, "text/plain", "led off");})
Then when accessing the corresponding paths of each sensor, such as "/ temperature", "/ humidity", "/ sound", "/ light", the program will call the corresponding functions to read the sensor data, print the data through the serial port, and then convert them into text String types and display them on the web page:
/ Webpage to get the temperature value server.on ("/ temperature", HTTP_GET, [] (AsyncWebServerRequest * request) {Serial.print ("Temperature:"); Serial.println (readDHTTemperature ()); request- > send_P (200, "text/plain", readDHTTemperature (). C_str ();}); / / Webpage to get the humidity value server.on ("/ humidity", HTTP_GET, [] (AsyncWebServerRequest * request) {Serial.print ("Humidity:") Serial.println (readDHTHumidity ()); request- > send_P (200,200, "text/plain", readDHTHumidity (). C_str ();}); / / Webpage to get the sound value server.on ("/ sound", HTTP_GET, [] (AsyncWebServerRequest * request) {Serial.print ("Sound:"); Serial.println (analogRead (SOUNDPIN)); request- > send_P (200," text/plain ", String (analogRead (SOUNDPIN). C_str () }); / / Webpage to get the light value server.on ("/ light", HTTP_GET, [] (AsyncWebServerRequest * request) {Serial.print ("Light:"); Serial.println (analogRead (LIGHTPIN)); request- > send_P (200, "text/plain", String (analogRead (LIGHTPIN)). C_str ();})
At the end of the setup () function, run the Web server:
Server.begin ()
At this point, the whole program is finished, in the loop () function, you do not need to do anything, of course, you can also run other code you want.
Program upload
Select the control board or ESP32-related chip in Arduino, then upload the program, open the serial port monitor, and we can see that the serial port monitor prompts us to visit the corresponding URL. (if you don't see the corresponding message, you can press the RST button behind the control panel to restart the program.)
Open the computer browser or mobile browser, visit the corresponding IP address, here is: 192.168.10.202, we can see the corresponding information displayed on the web page.
Try to access the corresponding address, when accessing 192.168.10.202/led=on, the browser and serial port monitor, both output the corresponding prompt information, at the same time, we can also see that the RGB light on the control board is also on. When visiting 192.168.10.202/led=off, the corresponding prompt information is also output in the browser and serial port monitor, and the RGB light on the control board is also turned off.
When visiting the corresponding URL of 192.168.10.202/sound and other sensors, the corresponding prompt information is also output in the browser and serial port monitor, as shown in the following figure.
Web Design
This section is not the focus of this article, nor will it affect the final voice control, so if you are not interested in web design, you can skip it and skip to the next section.
In the above, we have basically completed the functions of controlling LED lights and reading sensor data through the web page, but this web page is still too crude after all. So we do a little bit of optimization to the web page.
For the specific HTML optimization code, please download the attachment. This part refers to the website of the foreign god: https://randomnerdtutorials.com/
The final effect of the above code is as follows.
Voice Assistant Settings
Then there is the setup of speech recognition, which is similar to the previous Siri tutorial. Since I don't have any other voice assistant or intelligent speaker products on hand, I still take Siri as an example.
Open the shortcut App (English name Shortcuts) that comes with the iOS system. If you don't have it, you can download it at App Store for free:
The shortcut instruction settings are shown in the following figure. The principle of setting up shortcuts is simple, which is to access a given URL address.
Because the shortcut in iPhone supports the call of Siri speech recognition, we can run this shortcut directly through Siri to achieve the effect of obtaining sensor data by speech recognition.
If you don't know how to set up shortcut instructions, you can also download the author's instructions directly. Copy the link below to your iPhone browser and you will be prompted to add this command to your phone.
Https://www.icloud.com/shortcuts/4e20f185da76479a90f0716c9521cc7a
Effect demonstration
Wake up your Siri and see how it works. However, it is important to note that your iPhone and control board must be in the same local area network.
The above is all the contents of the article "how to obtain sensor data through Siri speech recognition". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.