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

29 lines
860 B
Python

import socket
import time
# Remplace cette IP par celle affichée par l'ESP32 dans le terminal série
ESP32_IP = "192.168.1.105"
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
commands = [0x01]
send_bytes(commands)