FEAT : Station météo OK
This commit is contained in:
parent
b33565876c
commit
009f71a7a4
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ __pycache__
|
||||
venv/
|
||||
ssl/
|
||||
password.*
|
||||
archive/
|
||||
|
||||
@ -2,7 +2,7 @@ version: '3'
|
||||
services:
|
||||
esphome:
|
||||
container_name: esphome
|
||||
image: ghcr.io/esphome/esphome:2025.4.2
|
||||
image: ghcr.io/esphome/esphome:2025.5.1
|
||||
volumes:
|
||||
- "${PWD}/config:/config"
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
esphome:
|
||||
name: seeed-studio
|
||||
friendly_name: seeed studio
|
||||
name: meteo
|
||||
friendly_name: meteo
|
||||
|
||||
esp32:
|
||||
board: esp32-s3-devkitc-1
|
||||
@ -10,36 +10,39 @@ esp32:
|
||||
# Enable logging
|
||||
logger:
|
||||
level: DEBUG
|
||||
baud_rate: 0
|
||||
|
||||
# Enable Home Assistant API
|
||||
api:
|
||||
encryption:
|
||||
key: "1tRYVfsGzt8mFr+ay9hE24pdPd8IACedduh9tLWg4xs="
|
||||
key: "lcr/4ePmB78mYjnyTElGrJXa1xM7an6hCUWolhvT684="
|
||||
|
||||
ota:
|
||||
- platform: esphome
|
||||
password: "d68060a1d18b9d61354434595717070c"
|
||||
password: "4d1a5c36ea8858dbece920c9bedeb8db"
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
|
||||
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
||||
ap:
|
||||
ssid: "Meteo Fallback Hotspot"
|
||||
password: "2GJSSrOmscwi"
|
||||
|
||||
captive_portal:
|
||||
|
||||
uart:
|
||||
id: mod_bus_id
|
||||
tx_pin: GPIO44 # Il faut les inverser !!!!
|
||||
rx_pin: GPIO43
|
||||
id: uart_1
|
||||
tx_pin:
|
||||
number: GPIO44
|
||||
rx_pin:
|
||||
number: GPIO43
|
||||
baud_rate: 4800
|
||||
# debug:
|
||||
# direction: BOTH
|
||||
# dummy_receiver: false
|
||||
# after:
|
||||
# delimiter: "\n"
|
||||
# sequence:
|
||||
# - lambda: UARTDebug::log_string(direction, bytes);
|
||||
|
||||
modbus:
|
||||
id: modbus1
|
||||
uart_id: mod_bus_id
|
||||
uart_id: uart_1
|
||||
|
||||
modbus_controller:
|
||||
- id: modbus_controller1
|
||||
@ -59,7 +62,7 @@ sensor:
|
||||
- platform: modbus_controller
|
||||
id: sensor1
|
||||
modbus_controller_id: modbus_controller1
|
||||
name: "Wind speed"
|
||||
name: "Anémomètre"
|
||||
register_type: read
|
||||
address: 0
|
||||
value_type: U_WORD
|
||||
@ -74,11 +77,12 @@ sensor:
|
||||
on_value:
|
||||
then:
|
||||
- mqtt.publish:
|
||||
topic: "rbo2"
|
||||
topic: "data"
|
||||
payload: !lambda 'return "Vent (x 10 en m/s) --> " + to_string(x);'
|
||||
- platform: modbus_controller
|
||||
id: sensor2
|
||||
modbus_controller_id: modbus_controller2
|
||||
name: "Wind direction gear"
|
||||
name: "Girouette"
|
||||
register_type: read
|
||||
address: 0
|
||||
value_type: U_WORD
|
||||
@ -93,16 +97,17 @@ sensor:
|
||||
on_value:
|
||||
then:
|
||||
- mqtt.publish:
|
||||
topic: "rbo2"
|
||||
topic: "data"
|
||||
payload: !lambda 'return "Sens --> " + to_string(x);'
|
||||
|
||||
mqtt:
|
||||
broker: "pc-raymond.home"
|
||||
id: mqtt1
|
||||
log_topic: null
|
||||
# log_topic: log
|
||||
port: 8883
|
||||
username: admin
|
||||
password: !secret mqtt
|
||||
# skip_cert_cn_check: True
|
||||
certificate_authority: |
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDFzCCAf+gAwIBAgIUVQ1Osb4crzbNV4NvXb9K7EmbemYwDQYJKoZIhvcNAQEL
|
||||
@ -124,5 +129,5 @@ mqtt:
|
||||
Ap2FlRX2rpKJFiX5rJbjGuzED4G2wv4QNrLl
|
||||
-----END CERTIFICATE-----
|
||||
birth_message:
|
||||
topic: rbo
|
||||
payload: 'Nouvelle connexion MQTT...'
|
||||
topic: data
|
||||
payload: '---> Nouvelle connexion MQTT...'
|
||||
38
proto/l.py
Executable file
38
proto/l.py
Executable file
@ -0,0 +1,38 @@
|
||||
#!python
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
|
||||
def list_serial_ports():
|
||||
ports = serial.tools.list_ports.comports()
|
||||
for port in ports:
|
||||
print(port.device)
|
||||
|
||||
def read_from_serial_port(port_name, baud_rate=9600):
|
||||
try:
|
||||
# Ouvrir le port série
|
||||
ser = serial.Serial(port_name, baud_rate, timeout=1)
|
||||
print(f"Lecture du port série {port_name}...")
|
||||
|
||||
while True:
|
||||
# Lire une ligne du port série
|
||||
line = ser.readline()
|
||||
if line:
|
||||
hex_line = ' '.join(f'{byte:02x}' for byte in line)
|
||||
print(f"Reçu (hexa): {hex_line}")
|
||||
|
||||
except serial.SerialException as e:
|
||||
print(f"Erreur: {e}")
|
||||
finally:
|
||||
if 'ser' in locals():
|
||||
ser.close()
|
||||
print("Port série fermé.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Lister les ports série disponibles
|
||||
print("Ports série disponibles:")
|
||||
list_serial_ports()
|
||||
|
||||
# Remplacer 'COM3' par le nom de votre port série
|
||||
port_name = input("Entrez le nom du port série à lire (par exemple, COM3 ou /dev/ttyUSB0): ")
|
||||
read_from_serial_port(port_name)
|
||||
|
||||
34
proto/t.py
34
proto/t.py
@ -2,13 +2,17 @@
|
||||
from pymodbus.client import ModbusSerialClient, ModbusTcpClient
|
||||
from pymodbus.pdu.register_read_message import ReadInputRegistersResponse
|
||||
from configModel import Algo, Metrique, Capteur, ModbusType
|
||||
import struct, time
|
||||
import struct, time, logging
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
# log = logging.getLogger('pymodbus.protocol.*')
|
||||
# log.setLevel(logging.DEBUG)
|
||||
|
||||
# client = ModbusTcpClient(host="shellyproem50-08f9e0e79718") # grarage (borne et pac)
|
||||
# client = ModbusTcpClient(host="ShellyPro3EM-FCE8C0D97664") # bureau (prises 1 à 3)
|
||||
client = ModbusSerialClient(
|
||||
port="/dev/ttyACM0",
|
||||
baudrate=4800,
|
||||
port="/dev/ttyUSB1",
|
||||
baudrate=9600,
|
||||
# stopbits=capteur.comConfig.stopbits,
|
||||
# bytesize=capteur.comConfig.bytesize,
|
||||
# parity=capteur.comConfig.parity
|
||||
@ -22,14 +26,11 @@ def uint32(a, b):
|
||||
ret:int = (a << 16) | b
|
||||
return ret
|
||||
|
||||
slave = 1
|
||||
|
||||
def lireMetrique(metrique:Metrique, registre):
|
||||
def lireMetrique(metrique:Metrique, registre:int, slave:int = 1, nom:str = "sans nom"):
|
||||
client.connect()
|
||||
try:
|
||||
data:ReadInputRegistersResponse = client.read_input_registers(registre, 2, slave=slave)
|
||||
data:ReadInputRegistersResponse = client.read_input_registers(registre, 1, slave=slave)
|
||||
if data:
|
||||
print(f"--> {data}")
|
||||
registres = data.registers
|
||||
if metrique.algo == Algo.NORMAL:
|
||||
val = registres[0]
|
||||
@ -41,23 +42,24 @@ def lireMetrique(metrique:Metrique, registre):
|
||||
val = ''.join(chr(register) for register in data.registers)
|
||||
if metrique.algo == Algo.BOOLEAN:
|
||||
val = registres[0]
|
||||
print(f"Captation sur {registre} : {val}")
|
||||
print(f"--> Registre {registre} du périmérique {slave} ({nom}) : {val}")
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de la captation sur {registre} : {e}")
|
||||
print(f"Erreur lors de la lecture du registre {registre} du périmérique {slave} ({nom}) : {e}")
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
registre = -1
|
||||
slave = 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
slave = 2
|
||||
while True:
|
||||
registre = 0
|
||||
# slave = slave + 1
|
||||
m:Metrique = Metrique(
|
||||
idMetrique=1,
|
||||
indexRegistreDepart=registre,
|
||||
idMetrique=0,
|
||||
indexRegistreDepart=0,
|
||||
precision=3,
|
||||
algo=Algo.NORMAL
|
||||
)
|
||||
lireMetrique(m, registre)
|
||||
lireMetrique(m, 1, slave=1)
|
||||
time.sleep(1)
|
||||
# lireMetrique(m, 0, 2, "orientation")
|
||||
# time.sleep(1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user