# Console **Repository Path**: jarlen_git/Console ## Basic Information - **Project Name**: Console - **Description**: 此示例演示如何使用控制台组件创建交互式shell。 - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2019-02-15 - **Last Updated**: 2022-10-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Console example 此示例演示如何使用控制台组件创建交互式shell。 ## **V1.4版本 更新** ### v1.4版本 很适合新手学习参考!!! 19-03-02: ​ vscode整体环境配置完成,支持idf.py编译系统,兼容make编译系统!理顺CMakeLists.txt的编写规则! 重新调整原来的wifi体系,融合了web配网相关项目。 wifi运行在ap_sta模式下,通过连接ap:esp32进行配网,密码esp32pwd web地址:192.168.1.1 因为代码量越来越大里,为了敲代码方便(代码自动补全)添加里一个半残废的vscode配置!代码补全可以正常动作 ## **V1.3版本更新 重大更新** 完善NVS 、WIFI与sntp 相关功能! 实现正确连接wifi后通过nvs保存ssid和pass,上电自动查找nvs保存的参数,找到并尝试自动连接wifi, wifi建立连接后自动初始化sntp,进行自动时间同步 ![1550045568236](C:\Users\Jarlen\AppData\Roaming\Typora\typora-user-images\1550045568236.png) ## **v1.2版本 更新** 完善sntp时间同步命令 **v1.1版本更新 ** 新增 tuling命令 新增 curl命令 新增 sntp命令 新增 http client测试任务 新增 tm1638与esp_enevt结合测试任务 wifi第一次正常连接后,保存参数,可以自动连接! ### **在此基础上,个人增加了LED、PWM、UART通信、NVS键值增删查、task测试等命令组!!!!** ### **所有命令** help Print the list of registered commands free 获取可用堆内存的总大小. restart 重启esp32 deep_sleep [-t ] [--io=] [--io_level=<0|1>] 进入深度睡眠模式。 支持两种唤醒模式:定时器和GPIO。 果未指定唤醒选项,则将无限期地休眠。 -t, --time= Wake up time, ms --io= If specified, wakeup using GPIO with given number --io_level=<0|1> GPIO level to trigger wakeup light_sleep [-t ] [--io=]... [--io_level=<0|1>]... 进入轻度睡眠模式。 支持两种唤醒模式:定时器和GPIO。 以使用成对的多个GPIO引脚来指定 'io' and 'io_level' 参数. 会唤醒UART输入。 -t, --time= 唤醒时间,ms --io= 如果指定,则使用给定数字的GPIO唤醒 --io_level=<0|1> GPIO级别触发唤醒 pwm freq duty time pwm out freq duty time -f, --freq= pwm freq Hz. -d, --duty= pwm duty. -t, --time= pwm time. led freq duty LEDC out freq duty -f, --freq= led freq Hz. -d, --duty= led duty. uart read | write uart read//write data test. -r, --read read uart. -w, --write= write data to uart tasks 获取关于运行任务的信息 join [--timeout=] [] 连接 WiFi AP station --timeout= Connection timeout, ms SSID of AP PSK of AP nvsr [name] -s|i key nvs 读取指定name空间的key值 -n, --name= 名称空间. -i, --int32= int key. str key. nvsw [name] key -s|i value nvs 写入 name key value -n, --name= key name. key. -s, --str= str key. -i, --int32= int key. nvss name | all nvs 状态信息. -n, --name= 名称空间. -a, --all 全部信息. nvsd name | key | all nvs del name key all -n, --name= key name. --key= key. -a, --all name all key. sntp sntp 时间服务 i2cconfig [--port=<0|1>] [--freq=] --sda= --scl= 配置I2C总线 --port=<0|1> 设置I2C总线端口号 --freq= 设置I2C总线的频率(Hz) --sda= 设置I2C SDA的gpio --scl= 设置I2C SCL的gpio i2cdetect 扫描I2C总线以查找设备 i2cget -c [-r ] [-l ] 通过I2C总线读取可见的寄存器 -c, --chip= 指定该总线上芯片的地址 -r, --register= 指定要读取的芯片上的地址 -l, --length= 指定从该数据地址读取的长度 i2cset -c [-r ] []... 设置通过I2C总线可见的寄存器 -c, --chip= 指定该总线上芯片的地址 -r, --register= 指定要读取的芯片上的地址 指定要写入该数据地址的数据 i2cdump -c [-s ] 检查通过I2C总线可见的寄存器.help =“检查通过I2C总线可见 的寄存器”, -c, --chip= 指定该总线上芯片的地址 -s, --size= 指定每次读取的大小 test name test task task名字. tl 聊天信息 图灵聊天命令行工具 -a url地址. -k 应用授权key. -u 用户id. 聊天信息. curl -h -m -d url 简易版curl命令行 -m 请求方式,默认get. -h 头部键值对 -d 请求数据. url地址. ## 配置UART和VFS `initialize_console` 函数配置与控制台操作相关的UART和VFS的一些方面: - 默认情况下,`stdin`和`stdout`是缓冲流。这意味着写入`stdout`的文本不会立即发送到`UART`。这不是控制台的理想行为,因此使用`setvbuf`函数禁用`stdin`和`stdout`的缓冲。 - 行尾被配置成与普通串行监控程序(如`screen`)所期望/生成的行尾相匹配,`minicom`, 和`idf_monitor`。包括在SDK中。这些命令的默认行为是: - 当按下键盘上的`enter`键时,`CR`(0x13)代码被发送到串行设备。 - 要将光标移动到下一行的开头,串行设备需要发送`CR LF`(0x13 0x10)序列。 - UART 驱动程序初始化, 与 VFS 配置为使用UART驱动程序的中断驱动程序的读写函数。 ## 行编辑 示例的主源文件演示了如何使用`linenoise`库,包括行补全、提示和历史记录。 ## 命令行 使用注册了几个命令 `esp_console_cmd_register` 函数. See `register_wifi` and `register_system` functions in `cmd_wifi.c` and `cmd_system.c` files. ## 命令处理 `app_main`函数内的主循环说明了如何使用`linenoise`和`esp_console_run`来实现读/ eval循环。 ## 参数解析 在`cmd_wifi.c`和`cmd_system.c`中实现的几个命令使用Argtable3库来解析和检查参数。 ## 命令历史 每次从`linenoise`获取新的命令行时,它将被写入历史记录并将历史记录保存到闪存中的文件中。重置时,将从该文件初始化历史记录。 # 示例输出 这是一个带控制台示例的示例会话。 GPIO15连接到GND以移除引导日志输出。 ``` This is an example of ESP-IDF console component. Type 'help' to get the list of commands. Use UP/DOWN arrows to navigate through command history. Press TAB when typing command name to auto-complete. [esp32]> help help Print the list of registered commands free Get the total size of heap memory available restart Restart the program deep_sleep [-t ] [--io=] [--io_level=<0|1>] Enter deep sleep mode. Two wakeup modes are supported: timer and GPIO. If no wakeup option is specified, will sleep indefinitely. -t, --time= Wake up time, ms --io= If specified, wakeup using GPIO with given number --io_level=<0|1> GPIO level to trigger wakeup join [--timeout=] [] Join WiFi AP as a station --timeout= Connection timeout, ms SSID of AP PSK of AP [esp32]> free 257200 [esp32]> deep_sleep -t 1000 I (146929) deep_sleep: Enabling timer wakeup, timeout=1000000us I (619) heap_init: Initializing. RAM available for dynamic allocation: I (620) heap_init: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM I (626) heap_init: At 3FFB7EA0 len 00028160 (160 KiB): DRAM I (645) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (664) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (684) heap_init: At 40093EA8 len 0000C158 (48 KiB): IRAM This is an example of ESP-IDF console component. Type 'help' to get the list of commands. Use UP/DOWN arrows to navigate through command history. Press TAB when typing command name to auto-complete. [esp32]> join --timeout 10000 test_ap test_password I (182639) connect: Connecting to 'test_ap' I (184619) connect: Connected [esp32]> free 212328 [esp32]> restart I (205639) restart: Restarting I (616) heap_init: Initializing. RAM available for dynamic allocation: I (617) heap_init: At 3FFAE2A0 len 00001D60 (7 KiB): DRAM I (623) heap_init: At 3FFB7EA0 len 00028160 (160 KiB): DRAM I (642) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (661) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (681) heap_init: At 40093EA8 len 0000C158 (48 KiB): IRAM This is an example of ESP-IDF console component. Type 'help' to get the list of commands. Use UP/DOWN arrows to navigate through command history. Press TAB when typing command name to auto-complete. [esp32]> ``` --- 有关示例的更多信息,请参阅上级“examples”目录中的README.md文件。