Acest laborator vă va învăța cum să configurați Raspberry Pi Pico pentru:
Cod complet pentru trimiterea unui email:
import network import usocket as socket import ssl import ubinascii import time SSID = 'Numele_Retelei' PASSWORD = 'Parola_Retelei' SMTP_SERVER = "smtp.gmail.com" SMTP_PORT = 465 EMAIL_ADDRESS = "email_tau@gmail.com" EMAIL_PASSWORD = "parola_ta_aplicatie" RECIPIENT = "destinatar@gmail.com" MESSAGE = """From: %s To: %s Subject: Hello from Raspberry Pi Pico Hello World! """ % (EMAIL_ADDRESS, RECIPIENT) def connect_wifi(): wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(SSID, PASSWORD) while not wlan.isconnected(): print("Conectare la Wi-Fi...") time.sleep(1) print("Conectat la Wi-Fi:", wlan.ifconfig()) def send_email(): addr = socket.getaddrinfo(SMTP_SERVER, SMTP_PORT)[0][-1] sock = socket.socket() sock.connect(addr) sock = ssl.wrap_socket(sock) print("Conexiune la serverul SMTP realizată") def send_command(command, expect_response=True): print(f">>> {command.strip()}") sock.write(command.encode('utf-8') + b"\r\n") if expect_response: response = sock.readline().decode('utf-8').strip() print(f"<<< {response}") return response try: send_command("HELO RaspberryPi") send_command("AUTH LOGIN") send_command(ubinascii.b2a_base64(EMAIL_ADDRESS.encode('utf-8')).decode('utf-8').strip()) send_command(ubinascii.b2a_base64(EMAIL_PASSWORD.encode('utf-8')).decode('utf-8').strip()) send_command(f"MAIL FROM:<{EMAIL_ADDRESS}>") send_command(f"RCPT TO:<{RECIPIENT}>") send_command("DATA") send_command(MESSAGE + "\r\n.") send_command("QUIT", expect_response=False) print("Email trimis cu succes!") except Exception as e: print(f"Eroare la trimiterea email-ului: {e}") finally: sock.close() connect_wifi() send_email()
Task: Creați un sistem care: