2024年11月21日星期四 下午9:37:25

ASR-PRO离线语音模块LU asrpro-01语音模块接入home assistant

3 个月 前
#44522 引用
Esp8266 12f 刷固件 -  编译固件

删除hassos  esphome 面板下面的目录和文件

ESPHome Dashboard里编译固件、然后下载固件到本地
0
3 个月 前
#44531 引用
Homeassistant直接api接入


esphome:
  name: test1
  includes:
    - my_custom_component.h

  friendly_name: test1

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "+wajSSS60UBPdF+Sn9uDMv+E7ShZr5M44t4p7xYccqU="

ota:
  - platform: esphome
    password: "0d2bdf9bf0bc188e8154c8d455dcd474"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test1 Fallback Hotspot"
    password: "JvHSBje0vtFq"

captive_portal:

uart:
  id: uart_bus
  rx_pin: 3
  tx_pin: 1
  baud_rate: 9600
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

text_sensor:
  - platform: custom
    lambda: |-
      auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
      App.register_component(my_custom_sensor);
      return {my_custom_sensor};
    text_sensors:
      name: "yykz"
      id: "uart_readline"  

0
3 个月 前
#44532 引用
1
0
3 个月 前
#44533 引用
Custom UART Text Sensor
Lots of devices communicate using the UART protocol. If you want to read lines from uart to a Text Sensor you can do so using this code example.

With this you can use automations or lambda to set switch or sensor states.








https://esphome.io/cookbook/lambda_magic.html?highlight=text_sensor#custom-uart-text-sensor
0
3 个月 前
#44534 引用

Compiling .pioenvs/test1/src/esphome/core/string_ref.cpp.o
Compiling .pioenvs/test1/src/esphome/core/util.cpp.o
Compiling .pioenvs/test1/src/main.cpp.o
Linking .pioenvs/test1/firmware.elf
RAM:   [====      ]  42.4% (used 34696 bytes from 81920 bytes)
Flash: [=====     ]  48.9% (used 500553 bytes from 1023984 bytes)
Building .pioenvs/test1/firmware.bin
esp8266_copy_factory_bin([".pioenvs/test1/firmware.bin"], [".pioenvs/test1/firmware.elf"])
esp8266_copy_ota_bin([".pioenvs/test1/firmware.bin"], [".pioenvs/test1/firmware.elf"])
========================= [SUCCESS] Took 27.68 seconds =========================
INFO Successfully compiled program.

0
3 个月 前
#44539 引用
增加my_custom_component.h文件

ESPHOME要读取uart内容转换为text_sensor,要增加my_custom_component.h才能编译,在ESPHOME目录新建my_custom_component.h文件,拷贝以下内容就可以。

https://esphome.io/cookbook/lambda_magic.html?highlight=text_sensor


#include "esphome.h"

class UartReadLineSensor : public Component, public UARTDevice, public TextSensor {
public:
  UartReadLineSensor(UARTComponent *parent) : UARTDevice(parent) {}

  void setup() override {
    // nothing to do here
  }

  int readline(int readch, char *buffer, int len)
  {
    static int pos = 0;
    int rpos;

    if (readch > 0) {
      switch (readch) {
        case '\n': // Ignore new-lines
          break;
        case '\r': // Return on CR
          rpos = pos;
          pos = 0;  // Reset position index ready for next time
          return rpos;
        default:
          if (pos < len-1) {
            buffer[pos++] = readch;
            buffer[pos] = 0;
          }
      }
    }
    // No end of line has been found, so return -1.
    return -1;
  }

  void loop() override {
    const int max_line_length = 80;
    static char buffer[max_line_length];
    while (available()) {
      if(readline(read(), buffer, max_line_length) > 0) {
        publish_state(buffer);
      }
    }
  }
};




https://bbs.hassbian.com/thread-23907-1-1.html
0
3 个月 前
#44540 引用
1
0
3 个月 前
#44541 引用
ha里text_sensor状态没有输出

核心板需要用串口输出,输出成字符.

后面16进制的那边改成字符输出,十六进制前面那个空格改成串口0,也就是pb5,pb6。这样相当于语音指令的时候,那个aspro的板,输出字符串到串口0,也就是pb5和pb6。原理就是通过串口0将数据通过9600的波特率和mini D1版的串口实现通信,从而实现homeassitant接收到相应的字符串。然后通过这个字符串,给出相应的动作。
0
3 个月 前
#44551 引用
在web界面中调试
首先需要在路由器的配置页面找到ESPhome设备的IP地址,然后在浏览器端输入XXX.XXX.XXX.XXX:80打开web调试页面,该页面可以读取输入,触发输出,查看调试日志和OTA固件升级。

http://test1.local/

or

http://192.168.2.116/

output


Time  level  Tag  Message
16:00:00  [W]  [component:237]  
Component api took a long time for an operation (289 ms).
16:00:00  [W]  [component:238]  
Components should block for at most 30 ms.
16:00:01  [D]  [api.connection:1375]  
ESPHome Logs 2024.7.2 (192.168.2.120): Connected successfully
16:00:01  [I]  [app:100]  
ESPHome version 2024.7.2 compiled on Aug  4 2024, 10:23:22
16:00:01  [C]  [wifi:599]  
WiFi:
16:00:01  [C]  [wifi:427]  
  Local MAC: 9C:9C:1F:44:55:D0
16:00:01  [C]  [wifi:432]  
  SSID: 'ChinaNet-S5S7XA'
16:00:01  [C]  [wifi:435]  

0