Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,409
» Latest member: danielrio
» Forum threads: 3,660
» Forum posts: 18,959

Full Statistics

Online Users
There are currently 21 online users.
» 0 Member(s) | 7 Guest(s)
AhrefsBot, Amazonbot, Bytespider, PetalBot, bot

Latest Threads
N30 Energy entry not work...
Forum: N30
Last Post: admin
6 hours ago
» Replies: 30
» Views: 544
flash Kincony software to...
Forum: DIY Project
Last Post: admin
6 hours ago
» Replies: 11
» Views: 60
KC868-A6 - how to connect...
Forum: KC868-A6
Last Post: admin
8 hours ago
» Replies: 8
» Views: 133
KC868-A16 v1 with KCS v2....
Forum: "KCS" v2 firmware system
Last Post: admin
8 hours ago
» Replies: 7
» Views: 46
Separate +12V to Kincony,...
Forum: T128M
Last Post: admin
8 hours ago
» Replies: 1
» Views: 14
linux command line / bash...
Forum: TA
Last Post: almman
8 hours ago
» Replies: 2
» Views: 28
KC868-A16 ethernet work w...
Forum: KC868-A16
Last Post: admin
Yesterday, 12:53 PM
» Replies: 14
» Views: 15,949
KC868-M16v2 configure yam...
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
Yesterday, 11:24 AM
» Replies: 145
» Views: 26,568
KC868-HAv2 work with F24 ...
Forum: KC868-HA /HA v2
Last Post: admin
Yesterday, 11:19 AM
» Replies: 9
» Views: 682
how to compile new tasmot...
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
Yesterday, 11:16 AM
» Replies: 5
» Views: 3,835

  A8S and Modbus sensor
Posted by: milan.net - 06-10-2024, 10:34 AM - Forum: KC868-A8S - Replies (16)

Hello,

I would like to ask for help setting up A8S with RS485 Temperature and Humidity Sensor Modbus RTU Use By SHT30 an ESPHome

https://shop.kincony.com/products/rs485-...e-by-sht30

Thank you

Print this item

Lightbulb Request for Free Sample of KinCony Product for Project by TEXVO DEVELOPERS
Posted by: mickey - 06-08-2024, 05:28 PM - Forum: Apply for free sample product - No Replies

Dear KinCony Team,

I am reaching out to you on behalf of TEXVO DEVELOPERS, a company based in India that develops IoT smart control systems and solutions. We are very interested in your KC868-A4 ESP32 board and KC101 Tuya electronic DIY kit for an upcoming project.

Our project falls under the "Start a Project" category, as we plan to create an open-source software and hardware solution using KinCony products. This project aims to benefit the public welfare and education sectors by providing an accessible and user-friendly IoT solution.

We would greatly appreciate the opportunity to receive free samples of the KC868-A4 and KC101 to kickstart our project. These samples will allow us to test and integrate your products into our solution, ensuring compatibility and optimal performance.

As part of our commitment to the open-source community, we will share our project processes, results, and insights with others through the KinCony community forum. We believe that our achievements can help and inspire more people to adopt and benefit from IoT technologies.

If our application is approved, we would be happy to provide you with more details about our project and keep you updated on its progress. Additionally, as our project moves forward, we anticipate requiring bulk orders of KinCony products to scale our solution.

Please find below our company information:
Company Name: TEXVO DEVELOPERS
Website: https://texvo.co.in/
WhatsApp: +916294745109
Email: mickeypc94@gmail.com

Thank you for considering our request. We look forward to the possibility of collaborating with KinCony and creating a meaningful impact through our project.
Best regards,
Mickey Sharma
TEXVO DEVELOPERS

Print this item

  KC868-AM work with DS18B20 DHT11 sensor ESPHome yaml
Posted by: admin - 06-06-2024, 05:58 AM - Forum: KC868-AM - Replies (4)

Code:
esphome:
  name: am

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Example configuration entry
api:

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
 
  manual_ip:
    static_ip: 192.168.1.211
    gateway: 192.168.1.1
    subnet: 255.255.255.0

switch:
  - platform: gpio
    name: "am-light1"
    pin: 15
    inverted: False

sensor:
  - platform: dht
    pin: 33
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"
    update_interval: 10s


  - platform: dallas
    dallas_id: hub_1
    address: 0xde0b23585c42fb28
    name: "Temperature #1"
  - platform: dallas
    dallas_id: hub_1
    address: 0xd20b2210b8edbd28
    name: "Temperature #2"
  - platform: dallas
    dallas_id: hub_3
    address: 0x690b2210c2ff4a28
    name: "Temperature #3"
  - platform: dallas
    dallas_id: hub_2
    address: 0x3f0b2210c07d1b28
    name: "Temperature #4"


dallas:
  - pin: 5
    id: hub_1
    update_interval: 10s
  - pin: 13
    id: hub_2
    update_interval: 20s
  - pin: 14
    id: hub_3
    update_interval: 30s

yaml file download: 
.txt   esphome_AM.txt (Size: 1.13 KB / Downloads: 348)

Print this item

  add M30 to home assistant "Energy" dashboard
Posted by: admin - 06-05-2024, 12:19 PM - Forum: KC868-M16 / M1 / MB / M30 - Replies (2)

add all "kwh sensor" these two options:
state_class: total_increasing
device_class: energy

for example:
  - platform: modbus_controller
    state_class: total_increasing
    device_class: energy
    modbus_controller_id: modbus_hub_m30
    address: 121
    register_type: holding
    name: m30_1_energy_1
    id: m30_1_energy_1
    unit_of_measurement: kWh
    accuracy_decimals: 2
    value_type: U_WORD


   
   

Print this item

  Maximum Cable Length?
Posted by: speedmeup - 06-05-2024, 07:45 AM - Forum: KC868-AI - Replies (1)

Hi all!

What is the maximum cable length that can be used between the KCOM and each input terminals? Would 50 metres of AWG24 cable (0.215mm2 / 14/0.2mm stranded) be OK? How can we calculate the acceptable voltage drop? Thanks.

Print this item

  KC868-E8T added Tuya module yaml file for ESPHome
Posted by: admin - 06-05-2024, 04:32 AM - Forum: KC868-E8T - No Replies

Code:
esphome:
  name: e8t-tuya
  friendly_name: e8t-tuya
  platformio_options:
    board_build.extra_flags:
      # WIFI_CONTROL_SELF_MODE = 0
      # WIFI_CONTROL_SELF_MODE = 1
      - "-DWIFI_CONTROL_SELF_MODE=1"
  platform: ESP32
  board: esp32dev
  on_boot:  #Power chip BL0939 initialization
    priority: 600
    then:
      - uart.write:
          id: uart_1
          data: [0xA5, 0x39, 0x42, 0x00, 0x00, 0xDF]
      - delay: 1ms
      - uart.write:
          id: uart_1
          data: [0xA5, 0x38, 0x3C, 0x00, 0x00, 0xE6]
      - delay: 1ms
      - uart.write:
          id: uart_1
          data: [0xA5, 0x39, 0x42, 0x00, 0x00, 0xDF]
      - delay: 1ms
      - uart.write:
          id: uart_1
          data: [0xA5, 0x3A, 0x01, 0x00, 0x00, 0x1F]
      - delay: 1ms
      - uart.write:
          id: uart_1
          data: [0xA5, 0x39, 0x00, 0x00, 0x00, 0x21]

external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-wifi-mcu
      ref: v1.1.0

uart:
  - id: uart_1
    tx_pin: GPIO12
    rx_pin: GPIO39
    baud_rate: 4800
    parity: NONE
    stop_bits: 2   
 
  # - id: uart_2
  #   tx_pin: GPIO33
  #   rx_pin: GPIO36
  #   baud_rate: 4800
  #   parity: NONE
  #   stop_bits: 2 

  - id: tuya_mcu_uart
    tx_pin: GPIO13
    rx_pin: GPIO16
    baud_rate: 9600

tuya_wifi_mcu:
  # tuya mcu product id
  product_id: d8vwzka9smrcjznp
  uart_id: tuya_mcu_uart
  wifi_reset_pin: 28
  wifi_led_pin: 16


# Enable logging
logger:
  # baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: "d83d604e4f0ae287fb041dbaf31524d9"


# Example configuration entry
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
 


sensor:
  - platform: bl0939
    uart_id: uart_1
    update_interval: 10s
    voltage:
      name: 'BL0939A Voltage'
    current_1:
      name: 'BL0939A Current 1'
    current_2:
      name: 'BL0939A Current 2'
    active_power_1:
      name: 'BL0939A Active Power 1'
    active_power_2:
      name: 'BL0939A Active Power 2'
    energy_1:
      name: 'BL0939A Energy 1'
    energy_2:
      name: 'BL0939A Energy 2'
    energy_total:
      name: 'BL0939A Energy Total'
     
     
     
  # - platform: bl0939
  #   uart_id: uart_2
  #   update_interval: 10s
  #   voltage:
  #     name: 'BL0939B Voltage'
  #   current_1:
  #     name: 'BL0939B Current 1'
  #   current_2:
  #     name: 'BL0939B Current 2'
  #   active_power_1:
  #     name: 'BL0939B Active Power 1'
  #   active_power_2:
  #     name: 'BL0939B Active Power 2'
  #   energy_1:
  #     name: 'BL0939B Energy 1'
  #   energy_2:
  #     name: 'BL0939B Energy 2'
  #   energy_total:
  #     name: 'BL0939B Energy Total'
     

# Example configuration entry for ESP32
i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a
 
pcf8574:
  - id: 'pcf8574_hub_out_1'  # for output channel 1-8
    address: 0x24

  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x22

   
# Individual outputs
switch:
  - platform: gpio
    name: "e8t_output1"
    id: "e8t_output1"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 0
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output1-tuya
    dp_id: 1
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output1"


  - platform: gpio
    name: "e8t_output2"
    id: "e8t_output2"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 1
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output2-tuya
    dp_id: 2
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output2"
     
  - platform: gpio
    name: "e8t_output3"
    id: "e8t_output3"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 2
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output3-tuya
    dp_id: 3
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output3"
     
  - platform: gpio
    name: "e8t_output4"
    id: "e8t_output4"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 3
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output4-tuya
    dp_id: 4
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output4"
     
  - platform: gpio
    name: "e8t_output5"
    id: "e8t_output5"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 4
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output5-tuya
    dp_id: 5
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output5"
     
  - platform: gpio
    name: "e8t_output6"
    id: "e8t_output6"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 5
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output6-tuya
    dp_id: 6
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output6"

  - platform: gpio
    name: "e8t_output7"
    id: "e8t_output7"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 6
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output7-tuya
    dp_id: 123
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output7"
     
  - platform: gpio
    name: "e8t_output8"
    id: "e8t_output8"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 7
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e8t-output8-tuya
    dp_id: 124
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e8t_output8"

binary_sensor:
  - platform: gpio
    name: "e8t_input1"
    id: "e8t_input1"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input1 Tuya
    dp_id: 122
    bind_binary_sensor_id: e8t_input1
    internal: true

  - platform: gpio
    name: "e8t_input2"
    id: "e8t_input2"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input2 Tuya
    dp_id: 121
    bind_binary_sensor_id: e8t_input2
    internal: true

  - platform: gpio
    name: "e8t_input3"
    id: "e8t_input3"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input3 Tuya
    dp_id: 120
    bind_binary_sensor_id: e8t_input3
    internal: true

  - platform: gpio
    name: "e8t_input4"
    id: "e8t_input4"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input4 Tuya
    dp_id: 119
    bind_binary_sensor_id: e8t_input4
    internal: true

  - platform: gpio
    name: "e8t_input5"
    id: "e8t_input5"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input5 Tuya
    dp_id: 118
    bind_binary_sensor_id: e8t_input5
    internal: true

  - platform: gpio
    name: "e8t_input6"
    id: "e8t_input6"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input6 Tuya
    dp_id: 117
    bind_binary_sensor_id: e8t_input6
    internal: true

  - platform: gpio
    name: "e8t_input7"
    id: "e8t_input7"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 6
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input7 Tuya
    dp_id: 116
    bind_binary_sensor_id: e8t_input7
    internal: true

  - platform: gpio
    name: "e8t_input8"
    id: "e8t_input8"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 7
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e8t_input8 Tuya
    dp_id: 115
    bind_binary_sensor_id: e8t_input8
    internal: true

web_server:
  port: 80

download yaml file: 
.txt   KC868-E8T-HA-Tuya.txt (Size: 8.39 KB / Downloads: 314)
   

Print this item

  KC868-E16T added Tuya module yaml file for ESPHome
Posted by: admin - 06-05-2024, 02:16 AM - Forum: KC868-E16T - Replies (4)

Code:
esphome:
  name: e16t
  platform: ESP32
  board: esp32dev
  platformio_options:
    board_build.extra_flags:
      # WIFI_CONTROL_SELF_MODE = 0
      # WIFI_CONTROL_SELF_MODE = 1
      - "-DWIFI_CONTROL_SELF_MODE=0"


external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-wifi-mcu
      ref: v1.1.0

uart:
  tx_pin: 33
  rx_pin: 14
  id: tuya_mcu_uart
  baud_rate: 9600

tuya_wifi_mcu:
  # tuya mcu product id
  product_id: tfj1dtlneyxp5uya
  uart_id: tuya_mcu_uart
  wifi_reset_pin: 5
  wifi_led_pin: 12

 
# Example configuration entry for ESP32
i2c:
  sda: 16
  scl: 15
  scan: true
  id: bus_a


# Example configuration entry
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0

# Example configuration entry
pcf8574:
  - id: 'pcf8574_hub_out_1'  # for output channel 1-8
    address: 0x21

  - id: 'pcf8574_hub_out_2'  # for output channel 9-16
    address: 0x25

  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x22

  - id: 'pcf8574_hub_in_2'  # for input channel 9-16
    address: 0x24

# Individual outputs
switch:
  - platform: gpio
    name: "e16t_output1"
    id: "e16t_output1"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 0
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output1-tuya
    dp_id: 1
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output1"


  - platform: gpio
    name: "e16t_output2"
    id: "e16t_output2"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 1
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output2-tuya
    dp_id: 2
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output2"

  - platform: gpio
    name: "e16t_output3"
    id: "e16t_output3"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 2
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output3-tuya
    dp_id: 3
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output3"

  - platform: gpio
    name: "e16t_output4"
    id: "e16t_output4"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 3
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output4-tuya
    dp_id: 4
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output4"

  - platform: gpio
    name: "e16t_output5"
    id: "e16t_output5"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 4
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output5-tuya
    dp_id: 5
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output5"

  - platform: gpio
    name: "e16t_output6"
    id: "e16t_output6"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 5
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output6-tuya
    dp_id: 6
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output6"

  - platform: gpio
    name: "e16t_output7"
    id: "e16t_output7"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 6
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output7-tuya
    dp_id: 101
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output7"

  - platform: gpio
    name: "e16t_output8"
    id: "e16t_output8"
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 7
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output8-tuya
    dp_id: 102
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output8"

  - platform: gpio
    name: "e16t_output9"
    id: "e16t_output9"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 0
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output9-tuya
    dp_id: 103
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output9"

  - platform: gpio
    name: "e16t_output10"
    id: "e16t_output10"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 1
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output10-tuya
    dp_id: 104
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output10"

  - platform: gpio
    name: "e16t_output11"
    id: "e16t_output11"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 2
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output11-tuya
    dp_id: 105
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output11"

  - platform: gpio
    name: "e16t_output12"
    id: "e16t_output12"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 3
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output12-tuya
    dp_id: 106
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output12"

  - platform: gpio
    name: "e16t_output13"
    id: "e16t_output13"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 4
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output13-tuya
    dp_id: 107
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output13"

  - platform: gpio
    name: "e16t_output14"
    id: "e16t_output14"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 5
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output14-tuya
    dp_id: 108
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output14"

  - platform: gpio
    name: "e16t_output15"
    id: "e16t_output15"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 6
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output15-tuya
    dp_id: 109
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output15"

  - platform: gpio
    name: "e16t_output16"
    id: "e16t_output16"
    pin:
      pcf8574: pcf8574_hub_out_2
      number: 7
      mode: OUTPUT
      inverted: true

  - platform: tuya_wifi_mcu
    name: e16t-output16-tuya
    dp_id: 110
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "e16t_output16"

binary_sensor:
  - platform: gpio
    name: "e16t-input1"
    id: "e16t_input1"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI01 Tuya
    dp_id: 111
    bind_binary_sensor_id: e16t_input1
    internal: true

  - platform: gpio
    name: "e16t-input2"
    id: "e16t_input2"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI02 Tuya
    dp_id: 112
    bind_binary_sensor_id: e16t_input2
    internal: true

  - platform: gpio
    name: "e16t-input3"
    id: "e16t_input3"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI03 Tuya
    dp_id: 113
    bind_binary_sensor_id: e16t_input3
    internal: true

  - platform: gpio
    name: "e16t-input4"
    id: "e16t_input4"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI04 Tuya
    dp_id: 114
    bind_binary_sensor_id: e16t_input4
    internal: true

  - platform: gpio
    name: "e16t-input5"
    id: "e16t_input5"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI05 Tuya
    dp_id: 115
    bind_binary_sensor_id: e16t_input5
    internal: true

  - platform: gpio
    name: "e16t-input6"
    id: "e16t_input6"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI06 Tuya
    dp_id: 116
    bind_binary_sensor_id: e16t_input6
    internal: true

  - platform: gpio
    name: "e16t-input7"
    id: "e16t_input7"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 6
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI07 Tuya
    dp_id: 117
    bind_binary_sensor_id: e16t_input7
    internal: true

  - platform: gpio
    name: "e16t-input8"
    id: "e16t_input8"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 7
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI08 Tuya
    dp_id: 118
    bind_binary_sensor_id: e16t_input8
    internal: true

  - platform: gpio
    name: "e16t-input9"
    id: "e16t_input9"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 0
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI09 Tuya
    dp_id: 119
    bind_binary_sensor_id: e16t_input9
    internal: true

  - platform: gpio
    name: "e16t-input10"
    id: "e16t_input10"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 1
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI10 Tuya
    dp_id: 120
    bind_binary_sensor_id: e16t_input10
    internal: true

  - platform: gpio
    name: "e16t-input11"
    id: "e16t_input11"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 2
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI11 Tuya
    dp_id: 121
    bind_binary_sensor_id: e16t_input11
    internal: true

  - platform: gpio
    name: "e16t-input12"
    id: "e16t_input12"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 3
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI12 Tuya
    dp_id: 122
    bind_binary_sensor_id: e16t_input12
    internal: true

  - platform: gpio
    name: "e16t-input13"
    id: "e16t_input13"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 4
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI13 Tuya
    dp_id: 123
    bind_binary_sensor_id: e16t_input13
    internal: true

  - platform: gpio
    name: "e16t-input14"
    id: "e16t_input14"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 5
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI14 Tuya
    dp_id: 124
    bind_binary_sensor_id: e16t_input14
    internal: true

  - platform: gpio
    name: "e16t-input15"
    id: "e16t_input15"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 6
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI15 Tuya
    dp_id: 125
    bind_binary_sensor_id: e16t_input15
    internal: true

  - platform: gpio
    name: "e16t-input16"
    id: "e16t_input16"
    pin:
      pcf8574: pcf8574_hub_in_2
      number: 7
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: e16t DI16 Tuya
    dp_id: 126
    bind_binary_sensor_id: e16t_input16
    internal: true

# Enable logging
logger:

# Enable Home Assistant API
api:


download yaml file: 
.txt   E16T-HA-Tuya.txt (Size: 11.91 KB / Downloads: 412)

Print this item

Question ESP32-S3 and DI8
Posted by: AVS412 - 06-03-2024, 06:58 PM - Forum: News - Replies (1)

Hello,

I am unable to merge the yaml files for the ESP32-S3 Core Board and the I2C IO Expander inoput board DI8. 
I merged them, and I think the SCL and SDA lines are set up correctly (GPIO38 and GPIO39). When compiling, I get an error in ESP-HOME every time.


I get the error below:

Reading CMake configuration...
Dependency Graph
|-- noise-c @ 0.1.4
|-- ArduinoJson @ 6.18.5
Linking .pioenvs/controller_avs412/firmware.elf
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/controller_avs412/src/main.o:(.literal._Z5setupv+0x70): undefined reference to `vtable for esphome::i2c::IDFI2CBus'
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/controller_avs412/src/main.o:(.literal._Z5setupv+0x74): undefined reference to `vtable for esphome::i2c::IDFI2CBus'
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/controller_avs412/src/main.o:(.literal._Z5setupv+0x94): undefined reference to `vtable for esphome::pcf8574::PCF8574Component'
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: .pioenvs/controller_avs412/src/main.o:(.literal._Z5setupv+0x1f4): undefined reference to `vtable for esphome::pcf8574::PCF8574GPIOPin'
collect2: error: ld returned 1 exit status
*** [.pioenvs/controller_avs412/firmware.elf] Error 1
========================= [FAILED] Took 11.95 seconds =========================




Can anyone tell you what's going wrong?
Thank you.

Code:
# =============================================================
# Diversen I/O Modules.
# IP range gereserveerd van 192.168.200.101 t/m 192.168.200.109
# =============================================================

esphome:
  name: controller_avs412
  friendly_name: CONTROLLER_AVS412
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# Enable logging
logger:
  hardware_uart: USB_SERIAL_JTAG

# Instellen I/O voor de RJ45 poort
ethernet:
  type: W5500
  clk_pin: GPIO43
  mosi_pin: GPIO44
  miso_pin: GPIO42
  cs_pin: GPIO41
  interrupt_pin: GPIO2
  reset_pin: GPIO1

# Instellen statisch IP adres
  manual_ip:
    static_ip: 192.168.200.101
    gateway: 192.168.200.1
    subnet: 255.255.255.0

# Enable Home Assistant API
api:
  encryption:
    key: "pKeAagi+vmlVVS45THS6padK2DpyOx+KYxlztZsxvQo="

ota:


i2c:
  sda: GPIO39
  scl: GPIO38
  scan: true
# id: bus_a

pcf8574:
  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x20    #replace by your PCF8574 address


# Activeren Web server.
web_server:
  port: 80


#  Instellen seriele communicatiepoort voor RS485
uart:
  - id: uart_485
    baud_rate: 9600
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
    tx_pin: 16
    rx_pin: 15

#  Instellen seriele communicatiepoort voor de 4G communicatiemodule

  - id: uart_sim7600
    baud_rate: 115200
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
      sequence:
        - lambda: UARTDebug::log_string(direction, bytes);
    tx_pin: 18
    rx_pin: 17

# Software schakelaars voor RS485 en de 4G module aan/ uit te zetten
switch:
  - platform: uart
    uart_id: uart_485
    name: "RS485 Button"
    data: [0x11, 0x22, 0x33, 0x44, 0x55]

  - platform: uart
    uart_id: uart_sim7600
    name: "UART 4G"
    data: "AT+CGSN\r\n" # read 4G SIM7600 ID

# In- en uitgangen instellen
binary_sensor:

  - platform: gpio
    name: "ESP_CPU01_AVS412 TMP1"
    pin:
      number: 8
      inverted: true

  - platform: gpio
    name: "ESP_CPU01_AVS412 TMP2"
    pin:
      number: 40
      inverted: true

  - platform: gpio
    name: "ESP_CPU01_AVS412 DL"
    pin:
      number: 0
      inverted: true

  #- platform: gpio
  #  name: "ESP_CPU01_AVS412 SDA"
  #  pin:
  #    number: 39
  #    inverted: true
  #    mode:
  #      input: true
  #      pullup: true

  #- platform: gpio
  #  name: "ESP_CPU01_AVS412 SCL"
  #  pin:
  #    number: 38
  #    inverted: true
  #    mode:
  #      input: true
  #      pullup: true

  - platform: gpio
    name: "ESP_CPU01_AVS412 IO10"
    pin:
      number: 10
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "ESP_CPU01_AVS412 IO11"
    pin:
      number: 11
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "CONTROLLER_AVS412 IO12"
    pin:
      number: 12
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "CONTROLLER_AVS412 IO13"
    pin:
      number: 13
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "CONTROLLER_AVS412 IO14"
    pin:
      number: 14
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "CONTROLLER_AVS412 IO21"
    pin:
      number: 21
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "CONTROLLER_AVS412 IO47"
    pin:
      number: 47
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "CONTROLLER_AVS412 IO48"
    pin:
      number: 48
      inverted: true
      mode:
        input: true
        pullup: true

  - platform: gpio
    name: "a8-input1"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input2"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input3"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input4"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input5"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input6"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input7"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 6
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a8-input8"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 7
      mode: INPUT
      inverted: true

sensor:

  - platform: adc
    pin: 4
    name: "CONTROLLER_AVS412 IO04 Current"
    update_interval: 2s
    unit_of_measurement: V
    attenuation: 11db
    filters:
      - multiply: 5

  - platform: adc
    pin: 5
    name: "CONTROLLER_AVS412 IO05 Current"
    update_interval: 2s
    unit_of_measurement: V
    attenuation: 11db
    filters:
      - multiply: 5

  - platform: adc
    pin: 6
    name: "CONTROLLER_AVS412 IO06 Current"
    update_interval: 2s
    unit_of_measurement: V
    attenuation: 11db
    filters:
      - multiply: 5

  - platform: adc
    pin: 7
    name: "CONTROLLER_AVS412 IO07 Current"
    update_interval: 2s
    unit_of_measurement: V
    attenuation: 11db
    filters:
      - multiply: 5



Attached Files Thumbnail(s)
   
Print this item

  KC868-A16 : RF is not displayed on screen Monitor
Posted by: Brouk - 06-03-2024, 11:37 AM - Forum: KC868-A16 - Replies (1)

I uploaded the KCS_KC868-A16V2.2.2.bin file to the A16 module. There is RF 433MHz receiver/transmitter in the module. Modul have used/learned 4 signals from my key remote controler.

How can I start displaying the RF inputs on the Monitor screen?



Attached Files Thumbnail(s)
   
Print this item

  Tuya adapter V2 arduino source code - control KinCony KC868-Hx series relay board
Posted by: admin - 06-03-2024, 12:28 AM - Forum: KC868-ATC / Tuya adapter V2 - Replies (7)

these BIN file firmware and arduino source code work for KinCony KC868-Hx series relay board:
KC868-H32, KC868-H32L, KC868-H32W, KC868-H32BS, KC868-H32B
KC868-H16, KC868-H16W, KC868-H16B
KC868-H8, KC868-H8W, KC868-H8B

you not need connect any cable between Tuya adapter v2 and relay board. Because of it use by TCP connection, it use network. 
fimrware download:

.zip   H8x_0x0.zip (Size: 478.35 KB / Downloads: 513)

.zip   H16x_0x0.zip (Size: 478.44 KB / Downloads: 493)

.zip   H32x_0x0.zip (Size: 478.7 KB / Downloads: 498)
download file and unzip, then download BIN file by ESP DOWNLOAD TOOL, write code at 0x0 address.
   
ESP DOWNLOAD TOOL download link:
https://www.kincony.com/wp-content/uploa..._3.9.2.zip
if you want modify arduino source code, which relay board model to use, just uncomment the model command line.
first time run code, you need to set relay board's IP address, port, your router's ssid and password for Tuya adapter v2 by usb-serial port.
just send command as this: SSID:KinCony,PSW:a12345678,192.168.3.141,4196
serial port baud rate: 115200bps
serial port debug tool download:

.zip   UartAssist.zip (Size: 468.4 KB / Downloads: 544)
here is arduino source code:

Code:
// USB set command     SSID:XXXXX,PSW:XXXXX,X.X.X.X,YYYY
// X.X.X.X is relay board IP address,  YYYY is relay board port.  SSID and PSW is your router's ssid and password
// for example         SSID:KinCony,PSW:a12345678,192.168.3.141,4196
// make sure your H8,H16,H32 relay board work with "TCP Server" mode.
#include <Arduino.h>
#include <TuyaWifi.h>
#include <Preferences.h>

#include "HardwareSerial.h"

///ADD TCP CLIENT FOR TUYA ADAPT
//#include <WiFiUdp.h>
#include <WiFi.h>
#include <WiFiClient.h>

//uncomment the relay board model you are using
//#define KINCONY_H8X    //// 
//#define KINCONY_H16X    ////
#define KINCONY_H32X    ////

#if defined(KINCONY_H8X)
#define RLY_NUMS  8
#elif defined(KINCONY_H16X)
#define RLY_NUMS  16
#elif defined(KINCONY_H32X)
#define RLY_NUMS  32
#endif

//---------RS485 setting
#define DEBUG   1

#define SERIAL_BAUD   9600
#define RX_PIN    32
#define TX_PIN    33
#define ADAPT485_NUM  2
#define SLAVE_ADDR  1
#define READ_ADDR  0
#define READ_NUM   32 

////SERIAL COMMAND IS
////SSID,
char ssid_buf[30] = {0};
char password_buf[20] = {0};
char server_ip[20] = {0};
uint16_t server_port = 4096;
uint8_t str[]={"client_me"};
//uint8_t Rece[256]={0};
uint8_t Send[128]={0};
Preferences prefs;

//IPAddress staticIP(192, 168, 10, 12);
//IPAddress gateway(192, 168, 10, 1);
//IPAddress subnet(255, 255, 255, 0);
//IPAddress dns(192, 168, 10,1);

WiFiClient client;
typedef enum{INIT_STATUS=0,RDY_STATUS,CONNECT_STATUS,TCP_COMM,STOP_STATUS,}STATUS_MACHINE;

static int statusMachine = INIT_STATUS;

static void InitWifi(void)
{
  //WiFi.mode(WIFI_STA);    
  //WiFi.setSleep(false); // disable STA mode wifi sleep mode
  /*if(WiFi.config(staticIP, gateway, subnet, dns, dns)==false)
  {
    Serial1.println("Configuration failed.");
  }*/
  /*IPAddress ip = WiFi.localIP();
  Serial1.print("IP address: ");     
  Serial1.println(WiFi.localIP()); */ 

  Serial1.print("rcv SSID is: "); 
  Serial1.println(ssid_buf);
  Serial1.print("rcv PSW is: "); 
  Serial1.println(password_buf);   
  Serial1.print("rcv server ip is: "); 
  Serial1.println(server_ip);
  Serial1.print("rcv server port is: "); 
  Serial1.println(server_port);
   
  WiFi.begin(ssid_buf, password_buf);//link wifi hotspot
  Serial1.println("WiFi try to connect~");
  statusMachine = RDY_STATUS;
}

static bool bFlagConnWifi = false;
static bool bFlagConnTcp = false;
static String serial_cmd_rcv = "";
static String tcp_cmd_rcv = "";
static char command_str_arr[30]={0};
bool rt_coils_status[RLY_NUMS] = {0};
void dp_update_all(void);

////online check for wifi&tcp connections for 500ms
static void SetRlyByChannel(uint8_t ch,bool value)
{
  memset(command_str_arr,0,sizeof(command_str_arr));
  sprintf(command_str_arr,"RELAY-SET-255,%d,%d",ch+1,value?1:0);
  return;
}
static void ReadAllRlyStatus()
{
  memset(command_str_arr,0,sizeof(command_str_arr));
  memcpy(command_str_arr,(char*)"RELAY-STATE-255",15);
  return;
}

static void WifiConnect(void)
{
  if (WiFi.status() != WL_CONNECTED) //wait wifi connection success
  {
    Serial1.print(".");
    //WiFi.begin(ssid_buf, password_buf);//link wifi hotspot
    //Serial1.println("WiFi try to connect~");
    bFlagConnWifi = bFlagConnTcp = false;
    return ;
  }
  bFlagConnWifi = true;
  statusMachine = CONNECT_STATUS;
  Serial1.println("WiFi connected");
 
  
}

static void TcpServerConn(void)
{
  if(WiFi.status() != WL_CONNECTED)
  {
    if(bFlagConnTcp) client.stop();
    bFlagConnWifi = bFlagConnTcp = false;
    statusMachine = RDY_STATUS;
    Serial1.println("WiFi exception 0");
    return;
  }

  if (!bFlagConnTcp)//begin connect to tcp server///if (client.connected() != 0)
  {   
      if (!client.connect(server_ip, server_port,2000))
      {
          Serial1.println("try to connect host....");
          bFlagConnTcp = false;
          //delay(5);
         
      }
      else
      {
        bFlagConnTcp = true;
        statusMachine = TCP_COMM;
        Serial1.println("TCP connected Succeed");
      }
  }
  
}

static void SendPeriodCheckCommand(void)
{
  if(WiFi.status() != WL_CONNECTED)
  {
    if(bFlagConnTcp) client.stop();
    bFlagConnWifi = bFlagConnTcp = false;
    statusMachine = RDY_STATUS;
    Serial1.println("WiFi exception 1");
    return;
  }
  if(client.connected())
  Serial1.println("send period check cmd~");
  statusMachine = TCP_COMM;
  ReadAllRlyStatus();
  //SetRlyByChannel();
  client.write(command_str_arr,strlen(command_str_arr));
}

static void GetCoilStatus(String data)
{///ACK STANDARD FORMAT IS "RELAY-STATE-255,D1,D0,OK" ///16x
////ACK STANDARD FORMAT IS "RELAY-STATE-255,D0,OK"  ///8x
////ACK STANDARD FORMAT IS "RELAY-STATE-255,D3,D2,D1,D0,OK" ///32x
 
   String rcv_data = data;
   if(rcv_data.substring(15,16) != "," ) return;
  
   uint8_t rlys_arr[4] = {0};
   uint32_t rly_status = 0;
   rcv_data = rcv_data.substring(16);
   //Serial1.println("Remain strs1:" + rcv_data);
   int index_find = rcv_data.indexOf(',');
   rlys_arr[0] = atoi(rcv_data.substring(0,index_find).c_str());
   
   #if defined(KINCONY_H16X) || defined(KINCONY_H32X)
   rcv_data = rcv_data.substring(index_find+1);
   //Serial1.println("Remain strs2:" + rcv_data);
   index_find = rcv_data.indexOf(',');
   rlys_arr[1] = atoi(rcv_data.substring(0,index_find).c_str());
   #endif
   #if defined(KINCONY_H32X)
   rcv_data = rcv_data.substring(index_find+1);
   index_find = rcv_data.indexOf(',');
   rlys_arr[2] = atoi(rcv_data.substring(0,index_find).c_str());
  
   rcv_data = rcv_data.substring(index_find+1);
   index_find = rcv_data.indexOf(',');
   rlys_arr[3] = atoi(rcv_data.substring(0,index_find).c_str());
   #endif
  
   #if defined(KINCONY_H8X)
  rly_status = rlys_arr[0];
   #elif defined(KINCONY_H16X)
  rly_status = (rlys_arr[0]<<8 ) | rlys_arr[1];
   #else
  rly_status = (rlys_arr[3]<<24 ) | (rlys_arr[2]<<16 )| (rlys_arr[1]<<8 )| (rlys_arr[0] );
   #endif
  

   Serial1.print("rly_status = 0x");
   Serial1.println(rly_status,HEX);
  
   for(int i=0;i<RLY_NUMS;i++)
   {
     rt_coils_status[i] = (rly_status&(1<<i))?true:false;
   }
}

static char rece_tcp_buf[100] = {0};

static bool CheckClientRcv(void)
{
  uint8_t i=0;
  if(client.available() == 0) return false;
  memset(rece_tcp_buf,0,sizeof(rece_tcp_buf));
 
  tcp_cmd_rcv = "";
   while (client.available()>0)  //whether received data from server
   {
       rece_tcp_buf[i++] = client.read();//receive data from server
    //tcp_cmd_rcv += client.read();//store data from server
    delay(1);
   }
  
   tcp_cmd_rcv = String(rece_tcp_buf);
     
   Serial1.print("Ack:");
   Serial1.println(tcp_cmd_rcv.c_str());
   if (tcp_cmd_rcv.length() < 22 ||
      tcp_cmd_rcv.substring(0,15) != "RELAY-STATE-255" )  {tcp_cmd_rcv="";return false;}
  //Serial1.println("OKAY COILS VALUE"); 
  GetCoilStatus(tcp_cmd_rcv);
  tcp_cmd_rcv="";
  return true;
}


static bool ProtocolDeal(const char* buf)
{
  char deal_str[100] = {0};
  char tmp[30];
  char *pos,*pos1,*pos2,*pos3;

  memcpy(deal_str,buf,strlen(buf));

  Serial1.println("check1");
 
  if ((pos = strchr(deal_str,','))!=0)    //find','
  {
    *pos = '\0';    //","replace with ‘\0’
    pos++;
    pos1 = pos;
    memset(tmp,0,30);
    //memcpy(tmp,buf,strlen(buf));
    strcpy(tmp,deal_str);
    if(tmp[0]=='S' && tmp[1]=='S' && tmp[2]=='I' && tmp[3]=='D' &&
      tmp[4]==':') 
    {
      memset(ssid_buf,0,sizeof(ssid_buf));
      memcpy(ssid_buf,&tmp[5],strlen(tmp)-5);
      Serial1.println("rcv ssid ok.");
    }    
  }
  else
    {
      Serial1.println("end1");
      return  false;
     
    }

  Serial1.println("check2");
  if ((pos = strchr(pos1,','))!=0)    //find','
  {
    *pos = '\0';    //","replace with‘\0’
    pos++;
    pos2 = pos;
    memset(tmp,0,30);
    //memcpy(tmp,pos1,strlen(pos1));
    strcpy(tmp,pos1);
    if(tmp[0]=='P' && tmp[1]=='S' && tmp[2]=='W' && tmp[3]==':' ) 
    {
      memset(password_buf,0,sizeof(password_buf));
      memcpy(password_buf,&tmp[4],strlen(tmp)-4);
      Serial1.println("rcv psw ok.");
    } 
  }
  else{
    return false;
    Serial1.println("end2");}
   
  Serial1.println("check3");
  if ((pos = strchr(pos2,','))!=0)    //find','  IP:XXXX,PORT:XXXX
  {
    *pos = '\0';    //","replace with‘\0’
    pos++;
    pos3 = pos;
    memset(server_ip,0,sizeof(server_ip));
    memcpy(server_ip,pos2,strlen(pos2));
 
    server_port = atoi(pos3);

    Serial1.print("rcv SSID is: "); 
    Serial1.println(ssid_buf);
    Serial1.print("rcv PSW is: "); 
    Serial1.println(password_buf);    
    Serial1.print("rcv server ip is: "); 
    Serial1.println(server_ip);
    Serial1.print("rcv server port is: "); 
    Serial1.println(server_port);
   
    /*bFlagConnWifi = bFlagConnTcp = false;
    statusMachine = INIT_STATUS;
    
    if(client.connected())
    {
      client.stop();
    }
   
    if (WiFi.status() == WL_CONNECTED) //等待WiFi热点连接成功
    {
      Serial1.print("stop wifi second.");
      WiFi.disconnect();
      delay(3000);
    }*/

    ///Preferences param here...
    prefs.begin("myns_netcfg");
    prefs.putString("ns_ssid",ssid_buf);
    prefs.putString("ns_psw",password_buf);
    prefs.putString("ns_ip",server_ip);
    prefs.putUShort("ns_port",server_port);
  
    prefs.end();
    ESP.restart();
  }
  else
    {
    return false;
    Serial1.println("end3");
    }

 
}

static void GetSerialCmd()
{ ////format: SSID:REALTIME2SENS-2.4G,PSW:12345678,IP:192.168.1.100,PORT:4196
  if(Serial1.available() == 0) return;
  serial_cmd_rcv = "";
  while (Serial1.available() > 0)
  {
    serial_cmd_rcv += char(Serial1.read());
    delay(1); 
  }
  Serial1.println(serial_cmd_rcv);
  if (serial_cmd_rcv.length() < 36 ||
      serial_cmd_rcv.substring(0,4) != "SSID" )  {serial_cmd_rcv="";return;}

  ProtocolDeal(serial_cmd_rcv.c_str());
 
  serial_cmd_rcv = "";
}

/* Current device DP values */


HardwareSerial My485Serial(ADAPT485_NUM);


//---RS485 setting end----

TuyaWifi my_device;



/* Current LED status */
unsigned char led_state = 0;
/* Connect network button pin */
int key_pin = 25;


/* Data point define */
typedef enum
{
  DPID_SWITCH01 = 1,
  DPID_SWITCH02,DPID_SWITCH03,
  DPID_SWITCH04,DPID_SWITCH05,DPID_SWITCH06,
 
  DPID_SWITCH07 = 101,
  DPID_SWITCH08,DPID_SWITCH09,DPID_SWITCH10,
  DPID_SWITCH11,DPID_SWITCH12,DPID_SWITCH13,
  DPID_SWITCH14,DPID_SWITCH15,DPID_SWITCH16,
  
  DPID_SWITCH17,DPID_SWITCH18,DPID_SWITCH19,
  DPID_SWITCH20,DPID_SWITCH21,DPID_SWITCH22,
  DPID_SWITCH23,DPID_SWITCH24,DPID_SWITCH25,
 
  DPID_SWITCH26,DPID_SWITCH27,DPID_SWITCH28,
  DPID_SWITCH29,DPID_SWITCH30,DPID_SWITCH31,
  DPID_SWITCH32,

}HXBS_DPID_DEF;

#define LED_WiFi  26
//#define LED_User  33



/* Stores all DPs and their types. PS: array[][0]:dpid, array[][1]:dp type.
*                                     dp type(TuyaDefs.h) : DP_TYPE_RAW, DP_TYPE_BOOL, DP_TYPE_VALUE, DP_TYPE_String, DP_TYPE_ENUM, DP_TYPE_BITMAP
*/
#if defined(KINCONY_H16X)
unsigned char dp_array[][2] =
{
  {DPID_SWITCH01, DP_TYPE_BOOL},{DPID_SWITCH02, DP_TYPE_BOOL},
  {DPID_SWITCH03, DP_TYPE_BOOL},{DPID_SWITCH04, DP_TYPE_BOOL},
  {DPID_SWITCH05, DP_TYPE_BOOL},{DPID_SWITCH06, DP_TYPE_BOOL},
  {DPID_SWITCH07, DP_TYPE_BOOL},{DPID_SWITCH08, DP_TYPE_BOOL},

  {DPID_SWITCH09, DP_TYPE_BOOL},{DPID_SWITCH10, DP_TYPE_BOOL},
  {DPID_SWITCH11, DP_TYPE_BOOL},{DPID_SWITCH12, DP_TYPE_BOOL},
  {DPID_SWITCH13, DP_TYPE_BOOL},{DPID_SWITCH14, DP_TYPE_BOOL},
  {DPID_SWITCH15, DP_TYPE_BOOL},{DPID_SWITCH16, DP_TYPE_BOOL},
};

unsigned char pid[] = {"7en1hzfnjtvprt35"}; ////change pid here....

#elif defined(KINCONY_H8X)
unsigned char dp_array[][2] =
{
  {DPID_SWITCH01, DP_TYPE_BOOL},{DPID_SWITCH02, DP_TYPE_BOOL},
  {DPID_SWITCH03, DP_TYPE_BOOL},{DPID_SWITCH04, DP_TYPE_BOOL},
  {DPID_SWITCH05, DP_TYPE_BOOL},{DPID_SWITCH06, DP_TYPE_BOOL},
  {DPID_SWITCH07, DP_TYPE_BOOL},{DPID_SWITCH08, DP_TYPE_BOOL}, 
};

unsigned char pid[] = {"zyauvyer5insa2ne"}; ////change pid here....

#elif defined(KINCONY_H32X)
unsigned char dp_array[][2] =
{
  {DPID_SWITCH01, DP_TYPE_BOOL},{DPID_SWITCH02, DP_TYPE_BOOL},
  {DPID_SWITCH03, DP_TYPE_BOOL},{DPID_SWITCH04, DP_TYPE_BOOL},
  {DPID_SWITCH05, DP_TYPE_BOOL},{DPID_SWITCH06, DP_TYPE_BOOL},
  {DPID_SWITCH07, DP_TYPE_BOOL},{DPID_SWITCH08, DP_TYPE_BOOL},

  {DPID_SWITCH09, DP_TYPE_BOOL},{DPID_SWITCH10, DP_TYPE_BOOL},
  {DPID_SWITCH11, DP_TYPE_BOOL},{DPID_SWITCH12, DP_TYPE_BOOL},
  {DPID_SWITCH13, DP_TYPE_BOOL},{DPID_SWITCH14, DP_TYPE_BOOL},
  {DPID_SWITCH15, DP_TYPE_BOOL},{DPID_SWITCH16, DP_TYPE_BOOL},

  {DPID_SWITCH17, DP_TYPE_BOOL},{DPID_SWITCH18, DP_TYPE_BOOL},
  {DPID_SWITCH19, DP_TYPE_BOOL},{DPID_SWITCH20, DP_TYPE_BOOL},
  {DPID_SWITCH21, DP_TYPE_BOOL},{DPID_SWITCH22, DP_TYPE_BOOL},
  {DPID_SWITCH23, DP_TYPE_BOOL},{DPID_SWITCH24, DP_TYPE_BOOL},

  {DPID_SWITCH25, DP_TYPE_BOOL},{DPID_SWITCH26, DP_TYPE_BOOL},
  {DPID_SWITCH27, DP_TYPE_BOOL},{DPID_SWITCH28, DP_TYPE_BOOL},
  {DPID_SWITCH29, DP_TYPE_BOOL},{DPID_SWITCH30, DP_TYPE_BOOL},
  {DPID_SWITCH31, DP_TYPE_BOOL},{DPID_SWITCH32, DP_TYPE_BOOL},
};

unsigned char pid[] = {"ytgvxhy4zoaxdqtp"}; ////change pid here....

#endif

unsigned char mcu_ver[] = {"1.0.0"};
/* last time */
unsigned long last_time = 0;

 

/**
* @description: DP download callback function.
* @param {unsigned char} dpid
* @param {const unsigned char} value
* @param {unsigned short} length
* @return {unsigned char}
*/
unsigned char dp_process(unsigned char dpid,const unsigned char value[], unsigned short length)
{
  int16_t index_out_coil = -1;
  unsigned char get_down_cmd = false;
 
  for(int16_t i=0;i<RLY_NUMS;i++)
  {
    if(dpid == dp_array[i][0])
    {
      index_out_coil = i;
      break;
    }
  }

    #if DEBUG
    Serial1.print("Rcv Command:<dpid,");
    Serial1.print(dpid,DEC);
    Serial1.print(" value,");
    Serial1.print(value[0],DEC);
    Serial1.print(" len,");
    Serial1.print(length,DEC);
    Serial1.println("> ");
  #endif
 
  if(index_out_coil < 0) return TY_ERROR;


   
  get_down_cmd = my_device.mcu_get_dp_download_data(dpid,value,length);

  #if DEBUG
    Serial1.print("get_down_cmd value is:<");
    Serial1.print(get_down_cmd,DEC); 
    Serial1.println("> ");
  #endif
 
  SetRlyByChannel(index_out_coil,get_down_cmd?true:false);
  Serial1.print("Send board control command:");
  Serial1.println(command_str_arr);
  uint16_t result = client.write(command_str_arr,strlen(command_str_arr)); 
  #if DEBUG
    Serial1.print("client WriteCoilAddr<");
    Serial1.print(index_out_coil,DEC);
    Serial1.print("> result:<");
    Serial1.print(result,DEC); 
    Serial1.println("> ");
  #endif
 
  my_device.mcu_dp_update(dpid, value, length);
  return TY_SUCCESS;
}

void setup()
{

  My485Serial.begin(SERIAL_BAUD, SERIAL_8N1, RX_PIN, TX_PIN); //RS485 serial port
  
  Serial.begin(9600,SERIAL_8N1,22,19);  //Tuya module serial port
  Serial1.begin(115200,SERIAL_8N1,3,1);   //USB serial port

 
  // Serial with tuyawifi
 
 

  //Initialize led port, turn off led.
  pinMode(LED_WiFi, OUTPUT);
  digitalWrite(LED_WiFi, LOW);

/*  pinMode(LED_User, OUTPUT);
  digitalWrite(LED_User, LOW);*/

  //Initialize networking keys.
  pinMode(key_pin, INPUT_PULLUP);

  //Enter the PID and MCU software version
  my_device.init(pid, mcu_ver);
  //incoming all DPs and their types array, DP numbers
  my_device.set_dp_cmd_total(dp_array, 2);
  //register DP download processing callback function
  my_device.dp_process_func_register(dp_process);
  //register upload all DP callback function
  my_device.dp_update_all_func_register(dp_update_all);
 
  //delay(300);
  last_time = millis();


  ///Preferences param here...
  prefs.begin("myns_netcfg");
  String ns_ssid = prefs.getString("ns_ssid","123");
  String ns_psw = prefs.getString("ns_psw","123");
  String ns_ip = prefs.getString("ns_ip","127.0.0.1");
  server_port = prefs.getUShort("ns_port",4096);

  memcpy(ssid_buf,ns_ssid.c_str(),ns_ssid.length());
  memcpy(password_buf,ns_psw.c_str(),ns_psw.length());
  memcpy(server_ip,ns_ip.c_str(),ns_ip.length());
  prefs.end();

  WiFi.mode(WIFI_STA);     //set to STA mode
}

static void FuncStatusMachine(int status)
{
  switch(status)
  {
    case INIT_STATUS:
    InitWifi();break;
    case RDY_STATUS:
    WifiConnect();break;
    case CONNECT_STATUS:
    TcpServerConn();break;
    case TCP_COMM:
    SendPeriodCheckCommand();break;
    case STOP_STATUS:
    break;
    default:break;
  }
}

void loop()
{
  FuncStatusMachine(statusMachine);  // read RS485 sensor
  delay(100);
  CheckClientRcv();
 
  my_device.uart_service();
  delay(100);
  GetSerialCmd();
 
  //Enter the connection network mode when Pin7 is pressed.
  if (digitalRead(key_pin) == LOW) {
    delay(80);
    if (digitalRead(key_pin) == LOW) {
      my_device.mcu_set_wifi_mode(SMART_CONFIG);
    }
  }
  /* LED blinks when network is being connected */
  if ((my_device.mcu_get_wifi_work_state() != WIFI_LOW_POWER) && (my_device.mcu_get_wifi_work_state() != WIFI_CONN_CLOUD) && (my_device.mcu_get_wifi_work_state() != WIFI_SATE_UNKNOW)) {
    if (millis()- last_time >= 500) {
      last_time = millis();

      if (led_state == LOW) {
        led_state = HIGH;
      } else {
        led_state = LOW;
      }
      digitalWrite(LED_WiFi, led_state);
    }
  }

  /* report the temperature and humidity */
  if ((my_device.mcu_get_wifi_work_state() == WIFI_CONNECTED) ||
      (my_device.mcu_get_wifi_work_state() == WIFI_CONN_CLOUD)) {
    dp_update_all();
  }

  delay(800);
}

static bool coils_old_status[RLY_NUMS] = {0};

static void CompareAndReport(void)
{
  for(int16_t i=0;i<RLY_NUMS;i++)
  {
    if(coils_old_status[i] != rt_coils_status[i])
    {
      coils_old_status[i] = rt_coils_status[i];
      my_device.mcu_dp_update(dp_array[i][0],rt_coils_status[i], 1);
      break;
    }
  }
}
/**
* @description: Upload all DP status of the current device.
* @param {*}
* @return {*}
*/
void dp_update_all(void)
{
  CompareAndReport();
}
here is arduino source code download link:

.zip   Hx.zip (Size: 5.12 KB / Downloads: 495)

Print this item