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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 9,584
» Latest member: soicauxsmbioo
» Forum threads: 4,191
» Forum posts: 20,830

Full Statistics

Online Users
There are currently 44 online users.
» 0 Member(s) | 33 Guest(s)
Amazonbot, Applebot, Baidu, Bing, PetalBot, Scrapy, bot

Latest Threads
N60 Sensor channel label
Forum: N60
Last Post: admin
3 hours ago
» Replies: 17
» Views: 2,104
solar production and cons...
Forum: N30
Last Post: admin
4 hours ago
» Replies: 3
» Views: 5
Current direction detecti...
Forum: N30
Last Post: admin
4 hours ago
» Replies: 3
» Views: 7
MQTT Discovery: missing s...
Forum: N30
Last Post: admin
Yesterday, 02:48 PM
» Replies: 1
» Views: 3
ai automation
Forum: KinCony integrate with Loxone home automation
Last Post: mediverticals
Yesterday, 06:56 AM
» Replies: 0
» Views: 5
Connecting sensors to Kin...
Forum: F16
Last Post: admin
Yesterday, 12:18 AM
» Replies: 1
» Views: 11
CT Sensor Direction
Forum: N60
Last Post: admin
08-12-2026, 08:14 AM
» Replies: 1
» Views: 14
N60 Voltage reference
Forum: N60
Last Post: admin
08-11-2026, 11:09 PM
» Replies: 3
» Views: 26
4-20mA loop voltage consi...
Forum: B4M
Last Post: admin
08-11-2026, 08:05 AM
» Replies: 1
» Views: 23
K868-a32 plastic case
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
08-10-2026, 08:48 AM
» Replies: 3
» Views: 1,187

  F8 ESPHome yaml for home assistant with tuya
Posted by: admin - 08-02-2026, 11:00 PM - Forum: F8 - No Replies

Code:
esphome:
  name: f8
  friendly_name: f8
  platformio_options:
    board_build.extra_flags:
      # WIFI_CONTROL_SELF_MODE = 0
      # WIFI_CONTROL_SELF_MODE = 1
      - "-DWIFI_CONTROL_SELF_MODE=1"
esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino
   

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

# Enable logging

  # hardware_uart: USB_SERIAL_JTAG
# Enable Home Assistant API
api:
  encryption:
    key: "WeVOuL5oNhjXcfzXtTirlOwvtWvCD5yqIxd3oV4es1k="

ethernet:
  type: W5500
  clk_pin: GPIO42
  mosi_pin: GPIO43
  miso_pin: GPIO44
  cs_pin: GPIO41
  interrupt_pin: GPIO2
  reset_pin: GPIO1

i2c:
   - id: bus_a
     sda: 8
     scl: 18
     scan: true
     frequency: 400kHz

pcf8574:
  - id: 'pcf8574_hub_in_1'  # for DI1-DI4 Relay1-Relay4
    i2c_id: bus_a
    address: 0x24
    pcf8575: true

uart:
  - id: uart_1    #RS485
    baud_rate: 9600
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
    tx_pin: 16
    rx_pin: 17

  - id: tuya_mcu_uart
    tx_pin: GPIO39
    rx_pin: GPIO38
    baud_rate: 9600

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

switch:
  - platform: uart
    uart_id: uart_1
    name: "RS485 Button"
    data: [0x11, 0x22, 0x33, 0x44, 0x55]

  - platform: gpio
    name: "f8-output01"
    id: "f8_output01"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 8
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output1-tuya
    dp_id: 1
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output01"

  - platform: gpio
    name: "f8-output02"
    id: "f8_output02"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 9
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output2-tuya
    dp_id: 2
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output02"

  - platform: gpio
    name: "f8-output03"
    id: "f8_output03"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 10
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output3-tuya
    dp_id: 3
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output03"

  - platform: gpio
    name: "f8-output04"
    id: "f8_output04"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 11
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output4-tuya
    dp_id: 4
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output04"

  - platform: gpio
    name: "f8-output05"
    id: "f8_output05"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 12
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output5-tuya
    dp_id: 5
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output05"

  - platform: gpio
    name: "f8-output06"
    id: "f8_output06"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 13
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output6-tuya
    dp_id: 6
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output06"

  - platform: gpio
    name: "f8-output07"
    id: "f8_output07"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 14
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output4-tuya
    dp_id: 101
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output07"

  - platform: gpio
    name: "f8-output08"
    id: "f8_output08"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 15
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-output8-tuya
    dp_id: 102
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "f8_output08"

binary_sensor:
  - platform: gpio
    name: "f8-input01"
    id: "f8_input01"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input1-tuya
    dp_id: 111
    bind_binary_sensor_id: f8_input01
    internal: true

  - platform: gpio
    name: "f8-input02"
    id: "f8_input02"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input2-tuya
    dp_id: 112
    bind_binary_sensor_id: f8_input02
    internal: true

  - platform: gpio
    name: "f8-input03"
    id: "f8_input03"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input3-tuya
    dp_id: 113
    bind_binary_sensor_id: f8_input03
    internal: true

  - platform: gpio
    name: "f8-input04"
    id: "f8_input04"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input4-tuya
    dp_id: 114
    bind_binary_sensor_id: f8_input04
    internal: true

  - platform: gpio
    name: "f8-input05"
    id: "f8_input05"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input5-tuya
    dp_id: 115
    bind_binary_sensor_id: f8_input05
    internal: true

  - platform: gpio
    name: "f8-input06"
    id: "f8_input06"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input6-tuya
    dp_id: 116
    bind_binary_sensor_id: f8_input06
    internal: true

  - platform: gpio
    name: "f8-input07"
    id: "f8_input07"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 6
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input7-tuya
    dp_id: 117
    bind_binary_sensor_id: f8_input07
    internal: true

  - platform: gpio
    name: "f8-input08"
    id: "f8_input08"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 7
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: f8-input8-tuya
    dp_id: 118
    bind_binary_sensor_id: f8_input08
    internal: true

##pull-up resistance on PCB
  - platform: gpio
    name: "f8-W1-io48"
    pin:
      number: 48
      inverted: true

  - platform: gpio
    name: "f8-W1-io47"
    pin:
      number: 47
      inverted: true

  - platform: gpio
    name: "f8-W1-io21"
    pin:
      number: 21
      inverted: true

  - platform: gpio
    name: "f8-W1-io15"
    pin:
      number: 15
      inverted: true
## without resistance on PCB
  - platform: gpio
    name: "f8-W1-io14"
    pin:
      number: 14
      inverted:  false

  - platform: gpio
    name: "f8-433M"
    pin:
      number: 40
      inverted:  false

  - platform: gpio
    name: "f8-io0"
    pin:
      number: 0
      inverted:  false

sensor:
  - platform: adc
    pin: 5
    name: "f8 A1 Voltage"
    update_interval: 5s
    attenuation: 11db
    filters:
      - lambda:
          if (x >= 3.11) {
            return x * 1.60256;
          } else if (x <= 0.15) {
            return 0;
          } else {
            return x * 1.51;
          }
  - platform: adc
    pin: 7
    name: "f8 A2 Voltage"
    update_interval: 5s
    attenuation: 11db
    filters:
      # - multiply: 1.51515
      - lambda:
          if (x >= 3.11) {
            return x * 1.60256;
          } else if (x <= 0.15) {
            return 0;
          } else {
            return x * 1.51;
          }
  - platform: adc
    pin: 6
    name: "f8 A3 Current"
    update_interval: 5s
    unit_of_measurement: mA
    attenuation: 11db
    filters:
      - multiply: 6.66666666
  - platform: adc
    pin: 4
    name: "f8 A4 Current"
    update_interval: 5s
    unit_of_measurement: mA
    attenuation: 11db
    filters:
      - multiply: 6.66666666

web_server:
  port: 80

font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 20

display:
  - platform: ssd1306_i2c
    i2c_id: bus_a
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(roboto), "KinCony f8");
esphome yaml:

.txt   F8-HA-tuya.txt (Size: 8.68 KB / Downloads: 32)

Print this item

Thumbs Up Schema A16V3 for Research and Development
Posted by: hamzachaouri - 08-02-2026, 07:47 PM - Forum: KC868-A16v3 - Replies (2)

I am writing to request access to Schema A16V3 for research and development purposes. The objective is to study its structure and functionality, evaluate its technical implementation, and use it in testing and development activities.

I would appreciate it if you could provide Schema A16V3 or any related documentation and send it directly to my email address:
hamzachaouri@gmail.com

Thank you for your time and consideration.

Print this item

  KinCony F8 + ESPHome: Unable to Enter Tuya Pairing Mode (Smart Config)
Posted by: gdidonato - 08-01-2026, 11:49 AM - Forum: F8 - Replies (6)

Hi!

I'm trying to pair a KinCony F8 device with my Tuya account. I flashed it with an ESPHome firmware, and it is working perfectly with Home Assistant.

Now I'd like to add Tuya connectivity. Based on the example code shared in this forum, I installed the firmware on my device, but I can't get it to enter pairing mode.

One thing that seems unusual is that the Tuya module never appears to complete its initialization. As shown in the attached ESPHome logs, the message "begin smart config" is printed repeatedly about every 50 ms, making it look as if the module is continuously trying to enter Smart Config instead of staying in pairing mode. Could this indicate that the Tuya module is not responding correctly or that I'm missing an initialization step?

I've attached the ESPHome firmware and the ESPHome logs.

I would really appreciate your help identifying what I'm doing wrong and how to get it working.

Thank you very much!
Guillermo



Attached Files
.txt   test-logs.txt (Size: 6.34 KB / Downloads: 38)
.txt   Kincony-F8-ESPHome-Tuya.txt (Size: 4.14 KB / Downloads: 26)
Print this item

  B8 ADS1115 current inputs
Posted by: jw1971 - 07-28-2026, 06:12 PM - Forum: B8 - Replies (6)

Hello,

I am using Analog 1 and 2 for voltage inputs (A0_gnd and A1_gnd on the ADS1115) and these are working well.

I am trying to add a 4-20ma sensor to Analog 3 or 4.  It is a 12VDC sensor with 2 wires.  Red to +12VDC power, and black to current sense.  This 12VDC supply is the same supply that powers the B8.

The B8 on either Analog 3 or 4 doesn't show the current consumption - just sits at 1.49mA which is what it shows with nothing connected either.

If I use a DMM on 20mA range between the black wire and 12VDC GND I get 9.9mA which is reasonable.

Does the ADS1115 need some sort of ground bond to work in current mode?  What is the gnd return path for Analog 3 or 4?

Print this item

  E8v3 E16v3 E24v3 relay module ARM CPU firmware
Posted by: admin - 07-27-2026, 01:00 AM - Forum: Extender module - No Replies

bootloader.exe tool: 
[Image: zip.png]   KC868 Controller Bootloader.zip 
[Image: attachment.php?aid=8891]   
1. set baud rate=38400bps.
2. open com port.
3. power on Nx board, during LED fast blink when the "bootloader Detect" button right now. Then board will go to bootloader mode.
4. open BIN file
5. press "Download" button, begin download firmware, after finished, press "Run" button, ARM CPU begin work.
[Image: attachment.php?aid=8892]
E8v3 , E16v3, E24v3 BIN file download:

.zip   E8V3_KU_V102Build20260725.zip (Size: 6.87 KB / Downloads: 48)

.zip   E16V3_KU_V102Build20260725.zip (Size: 6.99 KB / Downloads: 40)

.zip   E24V3_KU_V102Build20260725.zip (Size: 7.14 KB / Downloads: 57)

Print this item

  [arduino code examples for B2]-11 digital INPUT trigger OUTPUT directly
Posted by: admin - 07-25-2026, 06:40 AM - Forum: B2 - No Replies

Code:
/*
   Made by KinCony IoT
   https://www.kincony.com

   Demo: KinCony B2 DI Control Relay
   Board: KinCony B2 (ESP32)

   Digital Input 1 -> GPIO6
   Digital Input 2 -> GPIO7

   Relay 1 -> GPIO4
   Relay 2 -> GPIO46
*/

// Digital Inputs
#define DI1_PIN 6
#define DI2_PIN 7

// Relay Outputs
#define RELAY1_PIN 4
#define RELAY2_PIN 46

// Relay logic (Active LOW)
#define RELAY_ON  LOW
#define RELAY_OFF HIGH

// Store previous DI states
int lastDI1State;
int lastDI2State;

void setup()
{
  // Configure digital inputs
  pinMode(DI1_PIN, INPUT);
  pinMode(DI2_PIN, INPUT);

  // Configure relay outputs
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);

  // Turn OFF relays at startup
  digitalWrite(RELAY1_PIN, RELAY_OFF);
  digitalWrite(RELAY2_PIN, RELAY_OFF);

  // Read initial input states
  lastDI1State = digitalRead(DI1_PIN);
  lastDI2State = digitalRead(DI2_PIN);

}

void loop()
{
  // Read current DI states
  int di1State = digitalRead(DI1_PIN);
  int di2State = digitalRead(DI2_PIN);

  // DI1 changed
  if (di1State != lastDI1State)
  {
    lastDI1State = di1State;

    if (di1State == HIGH)
    {
      digitalWrite(RELAY1_PIN, RELAY_ON);
    }
    else
    {
      digitalWrite(RELAY1_PIN, RELAY_OFF);
    }
  }

  // DI2 changed
  if (di2State != lastDI2State)
  {
    lastDI2State = di2State;

    if (di2State == HIGH)
    {
      digitalWrite(RELAY2_PIN, RELAY_ON);
    }
    else
    {
      digitalWrite(RELAY2_PIN, RELAY_OFF);
    }
  }

  // Small delay for stability
  delay(10);
}
arduino ino file download:

.zip   11-input-trigger-output.zip (Size: 728 bytes / Downloads: 57)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   11-input-trigger-output.ino.merged.zip (Size: 180 KB / Downloads: 50)

Print this item

  [arduino code examples for B2]-10 Print TEXT on SSD1306 OLED displayer
Posted by: admin - 07-25-2026, 06:39 AM - Forum: B2 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program demonstrates how to display text on an SSD1306 128x64 OLED display using the U8g2 library.
* The program draws two lines of text on the display:
* - The first line is "KINCONY" in a larger font.
* - The second line is "www.kincony.com" in a smaller font.
*
* The display is connected via I2C (software implementation) with:
* - SCL (clock) on pin IO18
* - SDA (data) on pin IO8
*
* The display's I2C address is set to 0x3C.
*/

#include <U8g2lib.h>  // Include the U8g2 library for controlling the OLED display
#include <Wire.h>     // Include the Wire library for I2C communication

// Initialize the display using the software I2C method (SCL = IO18, SDA = IO8)
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,  18, 8, U8X8_PIN_NONE);  // Screen rotation: U8G2_R0

// Function to display page 1 content
void page1() {
  // Set font size 18 for the larger "KINCONY" text
  u8g2.setFont(u8g2_font_timR18_tf);  // Use the Times Roman font, size 18
  u8g2.setFontPosTop();               // Set the text position at the top of the display
  u8g2.setCursor(5, 0);               // Position the cursor at coordinates (5, 0)
  u8g2.print("KINCONY");              // Display the text "KINCONY" on the screen

  // Set font size 12 for the smaller "www.kincony.com" text
  u8g2.setFont(u8g2_font_timR12_tf);  // Use the Times Roman font, size 12
  u8g2.setCursor(0, 40);              // Position the cursor at coordinates (0, 40)
  u8g2.print("www.kincony.com");      // Display the text "www.kincony.com"
}

// Setup function, runs once when the program starts
void setup() {
  // Set the I2C address for the display to 0x3C
  u8g2.setI2CAddress(0x3C*2);  // I2C address shift for 8-bit format
 
  // Initialize the display
  u8g2.begin();
 
  // Enable UTF-8 character printing for the display
  u8g2.enableUTF8Print();  // Allow UTF-8 encoded text to be printed
}

// Main loop function, continuously runs after setup()
void loop() {
  // Begin the display drawing process
  u8g2.firstPage();  // Prepare the first page for drawing
  do {
    // Call the page1() function to draw content on the display
    page1();
  } while (u8g2.nextPage());  // Continue to the next page until all pages are drawn
}
arduino ino file download: 

.zip   10-oled-ssd1306.zip (Size: 1.11 KB / Downloads: 61)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   10-oled-ssd1306.ino.merged.zip (Size: 202.58 KB / Downloads: 53)

Print this item

  [arduino code examples for B2]-09 how to communication with Tuya WiFi module
Posted by: admin - 07-25-2026, 06:38 AM - Forum: B2 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program implements communication between ESP32 and the Tuya module
* via UART (serial communication). It listens for specific packets from the Tuya module
* and responds according to the predefined commands.
*
* Functionality:
* 1. When the ESP32 receives a heartbeat packet (55 AA 00 00 00 00 FF),
*    it sends a heartbeat response (55 AA 03 00 00 01 00 03).
* 2. When the ESP32 receives a product information request (55 AA 00 01 00 00 00),
*    it sends a product information response (55 AA 03 01 ...).
* 3. When the ESP32 receives a work mode request (55 AA 00 02 00 00 01),
*    it sends a work mode response (55 AA 03 02 00 03 10 1C 14 47).
* 4. When the ESP32 receives a network status request (55 AA 00 03 00 01 00 03),
*    it sends a network status response (55 AA 03 03 00 00 05).
* 5. Subsequent heartbeat packets (55 AA 00 00 00 00 FF) are responded to with
*    (55 AA 03 00 00 01 01 04).
*/

#include <HardwareSerial.h>

// Create a HardwareSerial object for UART communication on ESP32
HardwareSerial tuyaSerial(1);

// Define the GPIO pins for TXD and RXD used for serial communication
#define TXD_PIN 15
#define RXD_PIN 16

// Set the baud rate for Tuya module communication to 9600
#define BAUD_RATE 9600

// Define the response packets for different commands from the Tuya module

// Heartbeat response: 55 AA 03 00 00 01 00 03
uint8_t heartBeatResponse[] = {0x55, 0xAA, 0x03, 0x00, 0x00, 0x01, 0x00, 0x03};

// Product info response with a detailed payload (e.g., firmware version, product name, etc.)
uint8_t productInfoResponse[] = {
  0x55, 0xAA, 0x03, 0x01, 0x00, 0x2A, 0x7B, 0x22, 0x70, 0x22, 0x3A, 0x22,
  0x63, 0x68, 0x6D, 0x7A, 0x6C, 0x67, 0x6A, 0x70, 0x61, 0x64, 0x70, 0x71,
  0x78, 0x64, 0x6B, 0x6F, 0x22, 0x2C, 0x22, 0x76, 0x22, 0x3A, 0x22, 0x31,
  0x2E, 0x30, 0x2E, 0x30, 0x22, 0x2C, 0x22, 0x6D, 0x22, 0x3A, 0x30, 0x7D, 0xAA
};

// Work mode response: 55 AA 03 02 00 03 10 1C 14 47
uint8_t workModeResponse[] = {0x55, 0xAA, 0x03, 0x02, 0x00, 0x03, 0x10, 0x1C, 0x14, 0x47};

// Network status response: 55 AA 03 03 00 00 05
uint8_t netStatusResponse[] = {0x55, 0xAA, 0x03, 0x03, 0x00, 0x00, 0x05};

// Subsequent heartbeat response: 55 AA 03 00 00 01 01 04
uint8_t secondHeartBeatResponse[] = {0x55, 0xAA, 0x03, 0x00, 0x00, 0x01, 0x01, 0x04};

void setup() {
  // Initialize the serial communication for debugging at 115200 baud rate
  Serial.begin(115200);

  // Initialize the serial communication with Tuya module at 9600 baud rate
  tuyaSerial.begin(BAUD_RATE, SERIAL_8N1, RXD_PIN, TXD_PIN);

  // Debug message to indicate that the serial communication has been initialized
  Serial.println("ESP32-Tuya serial communication initialized.");
}

void loop() {
  // Check if data is available from the Tuya module
  if (tuyaSerial.available()) {
    uint8_t incomingPacket[7];  // Array to store the received packet
    size_t bytesRead = tuyaSerial.readBytes(incomingPacket, 7); // Read 7 bytes from Tuya

    // Check if the packet has a valid header (0x55, 0xAA)
    if (bytesRead >= 2 && incomingPacket[0] == 0x55 && incomingPacket[1] == 0xAA) {
      // If less than 7 bytes were received, wait for more data
      if (bytesRead < 7) {
        Serial.println("Incomplete packet received. Waiting for remaining bytes...");
        delay(50); // Delay to allow more data to be received
        while (tuyaSerial.available()) {
          incomingPacket[bytesRead++] = tuyaSerial.read(); // Continue reading remaining bytes
          if (bytesRead >= 7) break;
        }
      }

      // If still less than 7 bytes, discard the incomplete packet
      if (bytesRead < 7) {
        Serial.println("Error: Incomplete packet discarded.");
        return;
      }

      // Debug: Print the received packet for logging
      Serial.print("Received packet: ");
      for (size_t i = 0; i < 7; i++) {
        Serial.print(incomingPacket[i], HEX);
        Serial.print(" ");
      }
      Serial.println();

      // Call the function to process the received packet
      processTuyaPacket(incomingPacket, 7);

    } else {
      // If the header is invalid, discard the packet and flush the buffer
      Serial.print("Error: Invalid packet header. Data received: ");
      for (size_t i = 0; i < bytesRead; i++) {
        Serial.print(incomingPacket[i], HEX);
        Serial.print(" ");
      }
      Serial.println();
      tuyaSerial.flush(); // Clear the serial buffer
    }
  }

  // Delay to avoid CPU overuse
  delay(100);
}

// Function to process the received packet and send the appropriate response
void processTuyaPacket(uint8_t* packet, size_t size) {
  // Ensure the packet size is 7 and the header is valid
  if (size == 7 && packet[0] == 0x55 && packet[1] == 0xAA) {
    // Determine the command in the packet (packet[2])
    switch(packet[2]) {
      case 0x00:
        if (packet[3] == 0x00 && packet[4] == 0x00 && packet[5] == 0x00 && packet[6] == 0xFF) {
          Serial.println("Heartbeat received.");
          sendPacket(heartBeatResponse, sizeof(heartBeatResponse));
        } else if (packet[3] == 0x01 && packet[4] == 0x00 && packet[5] == 0x00 && packet[6] == 0x00) {
          Serial.println("Product info request received.");
          sendPacket(productInfoResponse, sizeof(productInfoResponse));
        } else if (packet[3] == 0x02 && packet[4] == 0x00 && packet[5] == 0x00 && packet[6] == 0x01) {
          Serial.println("Work mode request received.");
          sendPacket(workModeResponse, sizeof(workModeResponse));
        } else if (packet[3] == 0x03 && packet[4] == 0x00 && packet[5] == 0x01 && packet[6] == 0x00) {
          Serial.println("Network status request received.");
          sendPacket(netStatusResponse, sizeof(netStatusResponse));
        }
        break;

      default:
        Serial.println("Error: Unhandled command received.");
        break;
    }
  }
}

// Function to send the response packet to the Tuya module
void sendPacket(uint8_t* packet, size_t size) {
  // Send the packet via UART to Tuya module
  tuyaSerial.write(packet, size);

  // Debug: Print the sent packet for logging
  Serial.print("Sent packet: ");
  for (size_t i = 0; i < size; i++) {
    Serial.print(packet[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}
arduino ino file download: 

.zip   9-tuya-wifi-config.zip (Size: 2 KB / Downloads: 52)

Print this item

  [arduino code examples for B2]-08 Ethernet W5500 chip work with TCP Server mode
Posted by: admin - 07-25-2026, 06:37 AM - Forum: B2 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module
* as a TCP server. It listens on port 4196 and echoes back any string
* received from a client.
*
* Hardware connections:
* - CLK: GPIO42
* - MOSI: GPIO43
* - MISO: GPIO44
* - CS: GPIO41
* - RST: GPIO1
* - INT: GPIO2
*
* Static IP address: 192.168.3.55
* Subnet Mask: 255.255.255.0
* Gateway: 192.168.3.1
* DNS: 192.168.3.1
*/

#include <SPI.h>
#include <Ethernet.h>

// Define the W5500 Ethernet module pins
#define W5500_CS_PIN  42
#define W5500_RST_PIN 44
#define W5500_INT_PIN 43
#define W5500_CLK_PIN 1
#define W5500_MOSI_PIN 2
#define W5500_MISO_PIN 41

// MAC address for your Ethernet shield (must be unique on your network)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Static IP address configuration
IPAddress ip(192, 168, 3, 55);       // Static IP address
IPAddress subnet(255, 255, 255, 0);   // Subnet mask
IPAddress gateway(192, 168, 3, 1);    // Default gateway
IPAddress dns(192, 168, 3, 1);        // DNS server address

// Create an EthernetServer object to handle TCP connections
EthernetServer server(4196);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }

  // Initialize the W5500 module
  pinMode(W5500_RST_PIN, OUTPUT);
  pinMode(W5500_INT_PIN, INPUT);
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module
  delay(100);                       // Wait for reset to complete
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset

  // Initialize SPI with the correct pin definitions
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);

  // Set up the Ethernet library with W5500-specific pins
  Ethernet.init(W5500_CS_PIN);

  // Start the Ethernet connection with static IP configuration
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  // Print the IP address to the serial monitor
  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  // Start listening for incoming TCP connections
  server.begin();
}

void loop() {
  // Check for incoming client connections
  EthernetClient client = server.available();
  if (client) {
    Serial.println("New client connected");

    // Read data from the client and echo it back
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        server.write(c);
      }
    }

    // Close the connection when done
    client.stop();
    Serial.println("Client disconnected");
  }
}
arduino ino file download: 

.zip   8-Ethernet-W5500.zip (Size: 1.23 KB / Downloads: 58)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   8-Ethernet-W5500.ino.merged.zip (Size: 191.06 KB / Downloads: 58)

Print this item

  [arduino code examples for B2]-07 how to DS3231 RTC clock
Posted by: admin - 07-25-2026, 06:36 AM - Forum: B2 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* DS3231 RTC with Arduino
*
* This program demonstrates how to use the DS3231 RTC (Real-Time Clock) module with the Arduino.
* It includes functionality to:
* - Initialize the DS3231 RTC module
* - Read the current date and time from the RTC
* - Set the RTC time based on a serial command:Command format: DYYYY-MM-DDTHH:MM:SS
*    Set date and time command example: D2024-09-19T11:50:22
*    print current date and time command: current time
*
*
* Hardware Connections:
* - SDA: GPIO 8
* - SCL: GPIO 18
*/

#include <DS3231.h>
#include <Wire.h>

String serial_cmd_rcv = ""; // Serial port receiver

typedef struct
{
  byte year;    // Last two digits of the year, library adds 2000.
  byte month;
  byte day;
  byte hour;
  byte minute;
  byte second;
} MY_DATE_STR;

MY_DATE_STR my_date_str = {0};

// Define constants for relay control
#define OPEN_RLY_DATA    26
#define OPEN_RLY_MONTH   4
#define CLOSE_RLY_DATA   2
#define CLOSE_RLY_MONTH  5

// Define pin connections
#define SDA_PIN   8
#define SCL_PIN   18

DS3231 rtc; // Create an instance of the DS3231 RTC
bool h12Flag;
bool pmFlag;
static bool bCentury = false;
static bool old_level_high = false;
static bool old_level_low = false;


/**
* @brief Print the current time from the RTC to the Serial Monitor.
*/
static void PrintfCurTime()
{
  Serial.print("Current time is: ");
  int year = rtc.getYear() + 2000;
  Serial.print(year);
  Serial.print("-");

  Serial.print(rtc.getMonth(bCentury), DEC);
  Serial.print("-");

  Serial.print(rtc.getDate(), DEC);
  Serial.print(" ");

  Serial.print(rtc.getHour(h12Flag, pmFlag), DEC);
  Serial.print(":");
  Serial.print(rtc.getMinute(), DEC);
  Serial.print(":");
  Serial.println(rtc.getSecond(), DEC);
}

/**
* @brief Process serial commands to set the RTC time.
* Command format: DYYYY-MM-DDTHH:MM:SS
*/
static void GetSerialCmd()
{
  if (Serial.available() > 0)
  {
    delay(100);
    int num_read = Serial.available();
    while (num_read--)
      serial_cmd_rcv += char(Serial.read());
  }
  else return;

  serial_cmd_rcv.trim();

  if (serial_cmd_rcv == "current time")
  {
    PrintfCurTime();
    serial_cmd_rcv = "";
    return;
  }

  Serial.print("Received length: ");
  Serial.println(serial_cmd_rcv.length());

  int indexof_d = serial_cmd_rcv.indexOf('D');
  int indexof_t = serial_cmd_rcv.indexOf('T');

  Serial.print("D index: ");
  Serial.print(indexof_d);
  Serial.print(" T index: ");
  Serial.println(indexof_t);

  if (serial_cmd_rcv.length() != 20 ||
      serial_cmd_rcv.substring(0, 1) != "D" ||
      serial_cmd_rcv.substring(11, 12) != "T") 
  {
    Serial.println(serial_cmd_rcv);
    serial_cmd_rcv = "";
    return;
  }

  Serial.println("Setting time...");

  my_date_str.year = (byte)serial_cmd_rcv.substring(3, 5).toInt();
  my_date_str.month = (byte)serial_cmd_rcv.substring(6, 8).toInt();
  my_date_str.day = (byte)serial_cmd_rcv.substring(9, 11).toInt();
  my_date_str.hour = (byte)serial_cmd_rcv.substring(12, 14).toInt();
  my_date_str.minute = (byte)serial_cmd_rcv.substring(15, 17).toInt();
  my_date_str.second = (byte)serial_cmd_rcv.substring(18).toInt();

  rtc.setYear(my_date_str.year);
  rtc.setMonth(my_date_str.month);
  rtc.setDate(my_date_str.day);
  rtc.setHour(my_date_str.hour);
  rtc.setMinute(my_date_str.minute);
  rtc.setSecond(my_date_str.second);

  serial_cmd_rcv = "";

  Serial.println("Time set.");
}

void setup() {
  // Initialize the I2C interface
  Wire.begin(SDA_PIN, SCL_PIN, 40000);
 
  // Initialize Serial communication
  Serial.begin(115200);
   
  // Set the RTC to 24-hour mode
  rtc.setClockMode(false); // 24-hour format

  // Print current time to Serial Monitor
  PrintfCurTime();

  // Clear any remaining serial data
  while (Serial.read() >= 0) {}
}

void loop() {
  // Process incoming serial commands
  GetSerialCmd();
  delay(1000); // Delay for 1 second
}
arduino ino file download: 

.zip   7-DS3231-RTC.zip (Size: 1.56 KB / Downloads: 48)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   7-DS3231-RTC.ino.merged.zip (Size: 193.65 KB / Downloads: 53)

Print this item