forked from tanchou/Verilog
Refactor LED handling in fpga_wifi_led module and remove obsolete readSerial.py script
This commit is contained in:
28
Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py
Normal file
28
Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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 = [0x02] # Tu peux aussi faire ["0x01", "0x96", "0xA4"]
|
||||
send_bytes(commands)
|
Reference in New Issue
Block a user