![]() |
|
A8S and Modbus sensor - Printable Version +- Smart Home Automation Forum (https://www.kincony.com/forum) +-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20) +--- Forum: KC868-A8S (https://www.kincony.com/forum/forumdisplay.php?fid=24) +--- Thread: A8S and Modbus sensor (/showthread.php?tid=5864) Pages:
1
2
|
RE: A8S and Modbus sensor - admin - 07-27-2024 it's not easy to change address, you can try to open the sensor, there is a tiny PCB, if you can weld, you can change the i2c address. RE: A8S and Modbus sensor - martinvysnovsky - 08-20-2024 In your e-shop you write that the address should be editable. So is it? https://shop.kincony.com/products/rs485-temperature-and-humidity-sensor-modbus-rtu-use-by-sht30 RE: A8S and Modbus sensor - admin - 08-20-2024 use PC software to config the RS485 address. after click "set" button, then power off the sensor and power on again. PC software download:
Debug.zip (Size: 4.08 MB / Downloads: 399)
RE: A8S and Modbus sensor - martinvysnovsky - 08-21-2024 Finally, it is working. Thank you very much. For anyone else trying to set an address without the provided software. You should set the address to registry `0x0a`. RE: A8S and Modbus sensor - admin - 08-21-2024 ok, thanks share your result. RE: A8S and Modbus sensor - Marc MULEK - 07-09-2025 Do you have all info about this sensor? https://shop.kincony.com/products/rs485-temperature-and-humidity-sensor-modbus-rtu-use-by-sht30 I need to calibrate the sensor, as the temperature and humidity are very off (about 5°C higher than real values and 20% lower than real values). Is there a way to send commands via Modbus to recalibrate the sensor so it can be read correctly later? The goal is to be able to perform certified calibration and supply pre-calibrated sensors to customers. RE: A8S and Modbus sensor - Marc MULEK - 07-09-2025 I tried this buy can't be able to set calibratión with modbus parameters: from pymodbus.client import ModbusSerialClient import struct import time # --- CONFIGURACIÓN DEL SENSOR --- PUERTO_COM = 'COM9' # ⚠️ Cambiar según tu puerto (Windows: COMx, Linux: /dev/ttyUSB0) BAUDRATE = 9600 DIRECCION_MODBUS = 1 # Dirección del sensor (normalmente 1) # --- VALORES DE CALIBRACIÓN --- CALIBRACION_TEMP = 10.0 # °C → valor que se forzará como temperatura CALIBRACION_HUM = -10.0 # %RH → valor que se forzará como humedad OFFSET_TEMP = 20.0 # °C → offset de corrección aplicado a temperatura # --- FUNCIONES AUXILIARES --- def float_to_2regs(value): """Convierte un float IEEE-754 a 2 registros Modbus (32 bits)""" raw = struct.pack('>f', value) # Big-endian float hi, lo = struct.unpack('>HH', raw) return hi, lo def read_float_from_registers(regs, index): """Convierte 2 registros consecutivos a float IEEE-754""" hi = regs[index] lo = regs[index + 1] raw = struct.pack('>HH', hi, lo) return struct.unpack('>f', raw)[0] # --- INICIO DEL PROGRAMA --- client = ModbusSerialClient( port=PUERTO_COM, baudrate=BAUDRATE, stopbits=1, bytesize=8, parity='N', timeout=1 ) if client.connect(): print("✅ Conectado al sensor\n") # --- Escribir calibraciones --- print("✏️ Enviando parámetros de calibración...\n") registros_calibracion = { 0x000C: float_to_2regs(CALIBRACION_TEMP), # Temp en 0x000C–0x000D 0x000E: float_to_2regs(CALIBRACION_HUM), # Hum en 0x000E–0x000F 0x0010: float_to_2regs(OFFSET_TEMP) # Offset en 0x0010–0x0011 } for reg_base, (hi, lo) in registros_calibracion.items(): response = client.write_registers(address=reg_base, values=[hi, lo], slave=DIRECCION_MODBUS) if response.isError(): print(f"❌ Error escribiendo en registros 0x{reg_base:04X} y 0x{reg_base+1:04X}") else: print(f"✅ Registros 0x{reg_base:04X}-{reg_base+1:04X} ← [{hi}, {lo}]") print("\n⌛ Esperando 2 segundos para aplicar calibración...\n") time.sleep(2) # --- Leer temperatura y humedad --- result = client.read_holding_registers(address=0, count=6, slave=DIRECCION_MODBUS) if not result.isError(): regs = result.registers temp_int = regs[0] / 10 hum_int = regs[1] / 10 temp_float = read_float_from_registers(regs, 2) hum_float = read_float_from_registers(regs, 4) print("? Lectura del sensor:") print(f"?️ Temperatura (int): {temp_int:.1f} °C") print(f"? Humedad (int): {hum_int:.1f} %RH") print(f"?️ Temperatura (float): {temp_float:.3f} °C") print(f"? Humedad (float): {hum_float:.3f} %RH") else: print("❌ Error al leer los registros del sensor.") client.close() else: print("❌ No se pudo conectar al sensor.") |