1
0
forked from tanchou/Verilog
Files
Verilog_Louis/Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py

29 lines
907 B
Python
Raw Normal View History

import socket
import time
# Remplace cette IP par celle affichée par l'ESP32 dans le terminal série
2025-06-03 09:04:26 +02:00
ESP32_IP = "192.168.1.107"
ESP32_PORT = 1234
def send_bytes(commands):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print(f"Connexion a {ESP32_IP}:{ESP32_PORT}...")
s.connect((ESP32_IP, ESP32_PORT))
print("Connecté.")
for cmd in commands:
if isinstance(cmd, str):
cmd = int(cmd, 16) # Exemple : "0x01"
print(f"Envoi : 0x{cmd:02X}")
s.send(bytes([cmd]))
time.sleep(0.1) # Petite pause pour laisser respirer le FPGA
print("Tous les octets ont été envoyés.")
except Exception as e:
print("Erreur :", e)
# Exemple d'envoi
2025-06-03 09:04:26 +02:00
commands = [0x31] # Tu peux aussi faire ["0x01", "0x96", "0xA4"]
send_bytes(commands)