ESP32物联网智能硬件开发实战(李永华)-课后习题及答案 第6--8章.docx
《ESP32物联网智能硬件开发实战(李永华)-课后习题及答案 第6--8章.docx》由会员分享,可在线阅读,更多相关《ESP32物联网智能硬件开发实战(李永华)-课后习题及答案 第6--8章.docx(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、ESP32物联网智能硬件开发实战习题及答案第6章1 . ESP32 WiFi连网功能支持配置哪三种模式?答案:站点模式(即STA模式或WiFi客户端模式),此时ESP32连接到接入点(AP)或者 路由器。AP模式(即Soft-AP模式或接入点模式),也就是ESP32作为路由器,此时站点连 接到ESP320AP-STA共存模式(ESP32既是接入点,同时又作为站点连接到另外一个接入点)。2 .在ESP-IDF开发框架中,将ESP32开发板设置为AP模式,SSID为“MyESP32,密 码为“123456789,如何修改AP示例程序?将sdkconfig文件中修改如下字段CONFIG EXAMPL
2、E WIFI SSID=MyESP32 ”C0NFIG_EXAMPLE_WIFI_PASSW0RD=,123456789z,3 .在 Arduino IDE 中,实现 AP 模式,SSID 为 “MyESP32”,密码为 “ 123456789”, 并在串口打印相关信息。include * include WiFi, h”void setup()Serial. bcgin(l 15200);WiFi.softAP(*MyESP32*, ”123456789); 设置 AP 参数,名称和密码)void loopO(Serial, print(主机名:);Serial, print In (WiF
3、i, softAPgetHostname ();Serial. print(主机 IP:);Serial. println(WiFi. softAPIPO);Serial, print (主机 IPV6:);Serial, print In (WiFi. softAPIPv6():Serial, print(主机SSID:*);Serial. println(WiFi. SSIDO):Serial, print(“主机 mac 地址:”);Serial. println(WiFi. softAPmacAddress();Serial, print(主机连接个数:);Serial, print
4、In (WiFi. softAPgetSlalionNumO);Serial. print (主机状态;Serial. println(WiFi. status。); delay(1000);)4.使用microPython开发环境,实现ESP32作为站点连接WiFi时密码的动态输入功 能。import networknewdata =for i, item in enumerate (data): #解码数据j = i % 4newdata. append (chr(datai mskLj) res = .join(newdata) return resprint C my server s
5、tart. ,) try:sta_if = network. WLAN(network. STA_IF)staif. active (True)sta.if. connectC Redmi_77DE12345678)while True:if sta_if. ifconfigO 0 != 0. 0. 0. 01 :breakprint C succ connect wi fi ap, get ipaddr:*)print(sta_if. ifconfigO)except:passsock = socket, socket ()sock, setsockopt (socket. SOL_SOCK
6、ET, socket. SO_REUSEAI)DR, 1)sock, bind(C 0. 0. 0. 0, 8000)sock. 1isten (5)print(*websocket listen at 8000.)while True:conn, address = sock, accept () # 接收到 socketprint (* client connect. / )print(address)websocket_he1per. server_handshake(conn)ws = websocket(conn)print (J websocket connect succ)whi
7、le True:text = ws. read ()print(text)if text = H:led = Pin(2, Pin. OUT, value = 1)el if text = L:led = Pin(2, Pin. OUT, value = 0)9.根据MQTT示例中使用的服务器,在Arduino IDE下,客户端发布“Hello World” 消息、,订阅服务端消息、,控制2引脚上LED亮灭。includeWiFi. hinclude 需要管理库添加/ Update these with values suitable for your network.int BUILTIN_
8、LED=2; LED 引脚const char* ssid = *; 修改 WiFi 名称const char* password =修改 WiFi 密码const char* mqtt_server = *; /修改 MQTT 服务器地址WiFiClient espClient;BubSubClicnt client(espClient);unsigned long lastMsg = 0;define MSG_BIFFER_SIZE (50)char msgMSG BUFFER SIZE;int value = 0;void setup_wifi() delay(10);/连接WiFiSe
9、rial. printlnO :Serial, print(Connecting to );Serial, println(ssid):WiFi, mode(WIFI_STA):WiFi. begin(ssid, password);while (WiFi.statusO != WL_CONNECTED) delay (500):Serial, print (.);randomSeed(micros ():Serial. prinlln);Seiial. print In (WiFi connected*);Serial. println(*TP address:);Serial. print
10、ln(WiFi. localiPO):void callback(char* topic, byte* payload, unsigned int length) Serial, print(Message arrived ”);Serial, print(topic):Serial, print (*);or (int i = 0; i 2000) lastMsg = now;+value;snprintf (msg, MSG_BUFEER_SIZE, hello world value):Serial.print(*Publish message:);Serial, print In(ms
11、g);client.publish(*outTopic*, msg); )第8章1 .简述蓝牙的协议栈。答案:蓝牙协议规定了两个层次,分别为蓝牙核心协议和蓝牙应用层协议。蓝牙核心协 议是对蓝牙技术本身的规范,主要包括控制器(Controller)和主机(Host),不涉及其应 用方式;蓝牙应用层协议(Application)是在蓝牙核心协议的基础匕根据具体的应用需 求定义出的特定策略。2 .简述GATT的作用。答案:通用属性配置文件层(Generic Attribute profile,简写GATT),定义了使用 ATT的服务框架,GATT规定配置文件(profile)的结构。在BLE中,所有
12、被profile或者 服务用到的数据块称为“特性”,两个建立连接设备之间的所有数据通信都是通过GATT子 程序处理。GATT层用于已连接蓝牙设备之间的数据通信,应用程序和proi Ie直接使用GATT 层。当两个设备建立连接之后,它们就处于两种角色之一:GATT服务器端:为GATT客户端 提供数据服务的设备。GATT客户端:从GATT服务器端读写应用数据的设备。3 .简述传统蓝牙和低功耗蓝牙的区别。答案:BT与BLE的区别:当前的蓝牙协议分为基础率/增强数据率和低耗能两种技术类 型。经典蓝牙统称BT,低功耗蓝牙称为BLE。经典蓝牙模块(BT),泛指支持蓝牙协议在4. 0 以卜的模块,一般用于数
13、据量比较大的传输。经典蓝牙模块可再细分为:传统蓝牙模块和高 速蓝牙模块。传统蓝牙模块在2004年推出,.主要代表是支持蓝牙2.1协议的模块,在智能 手机爆发的时期得到广泛支持。高速蓝牙模块在2009年推出,速率提高到约24Mbit/s,是 传统蓝牙模块的八倍。低功耗蓝牙模块(BLE),指支持蓝牙协议4.0或更高的模块,最大的 特点是功耗的降低。4 .使用Arduino IDE通过蓝牙循环向手机端发送Hello World!,手机端使用BLE调 试助手进行读取数据。include include include include BLECharacteristic *pCharacteristic
14、;bool deviceConnected = false;char BLEbuf32 = 0;uint32_t ent = 0;#dcfinc SERVICE_UUID 6E400001-B5A3-F393-E0A9-E50E24DCCA9E* / UART service UUIDdefine CHARACTERISTIC_UUID_RX *6E400002-B5A3-F393-E0A9-E50E24DCCA9E*Olefine C1IARACTERISTIC_UUIDTX ”6E400003-B5A3-F393-E0A9-E50E24DCCA9E”class MyServerCa11ba
15、cks: public BLEServerCa11 backs void onConnect(BLEServer* pServer) deviceConnected = true;;void onDisconncct(BLEScrvcr* pServer) deviceConnected = false;;class MyCal1 backs: pub 1ic BLECharacteristicCalIbacks void onWrite(BLECharacteristic *pCharacteristic) std:string rxValue = pCharacteristic-getVa
16、lue();if (rxValue. length() 0) Serial, print(*Received Value:);for (int i = 0; i setCal1 backs(new MyServerCal1 backs();BLEService *pService = pServer-createService(SERVICE_LUID); / Create the BLE Service pCharacteristic = pSer v i ce-c rea t eCharac t er i s t i c (CHAR/CTER I ST IC UUID TX, BLECha
17、racteristic:PROPERTY_NOTIFY);/ Create a BLE CharacteristicpCharacteri stic-addDescri ptor(new BLE2902():BLECharacteristic *pCharacteristic = pServ i ce-createCharac ter i st i c (CHARACTER I ST I C_UUI D_RX, BLECharac ter i st i c:PKOPERTYJVRITE);pCharacteri stic-setCalIbacks(new MyCa11 backs();pSer
18、vice-start();/ Start the servicepServer-getAdvertising()-start(); / Start advertisingSerial. printlnCWaiting a client connection to notify. w);)void loopO if (deviceConnected) memset (BLEbuf, 0, 32);memepy(BLEbuf, (char*)*Hello World!*, 32);pCharacteri st ic-setValue(BLEbuf):pCharactcristic-nolify()
19、; / Send the value to the app!Serial, print(w* Sent Value:);Serial. print(BLEbuf);Serial, printing *);)delay(1000);)5 .在ESP32开发板上GPIOO引脚接按键开关,按键开关另一端接地。使用Arduino IDE 实现,每按次按键,更改BLE蓝牙设备名字,通过申口监视器和BLE调试助手观察结果。 参考Arduin。IDE的示例程序,代码如下include SimpleBLE. h#ir!defined(CONFIG_BT_ENABLED) | | !defined(CONFTG
20、_BLUEDROID_ENABI.ED)terror Bluetooth is not enabled! Blease run make menuconfig to and enable itSendifSimpleBLE ble;void onButtonO String out = BLE32 name:out += String(millisO / 1000):Serial, print In (out);ble. begin (out);)void setup() Serial, begin(115200);Serial. setDcbugOutput(true);pinMode(0,
21、 INPUT PULLUP);Serial, print(*ESP32 SDK: *);Serial, print In (ESP. getSdkVersionO);ble.begin(*ESP32 SimpleBLE*);Serial. println(*Press the button to change the devices name*);)void loopO static uint8 t lastPinState = 1;uint8_t pinStatc = digitalRcad(O);if(IpinState & lastPinState)onButtonO ;lastPinS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ESP32物联网智能硬件开发实战李永华-课后习题及答案 第6-8章 ESP32 联网 智能 硬件 开发 实战 李永华 课后 习题 答案
限制150内