Я работаю над модулем Pycom lopy4 , который является модулем на основе ESP32, версия прошивки 1.8.6-849.
Я получаю ошибку OSError: -1
по команде s.connect(addr)
Вот код Есть ли инструмент для проверки SSL-соединения.
Моя цель - использовать MQTT с SSL.
import socket
from network import WLAN
import machine
import time
import ssl
import gc
import ussl
gc.collect()
wlan = WLAN(mode=WLAN.STA)
print("Connecting to wifi")
wlan.connect(SSID, auth=(WLAN.WPA2, PASSWORD), timeout=5000)
while not wlan.isconnected():
machine.idle()
print('WAN connection failed!')
time.sleep(10)
wlan.connect('My ASUS', auth=(WLAN.WPA2, 'chaipass'), timeout=5000)
print("Connected wifi")
############# SSL connection #################
KEY_PATH = "flash/cert/client.key"
CERT_PATH = "flash/cert/client.crt"
HOST= "www.google.com"
PATH="/"
PORT =443
with open(KEY_PATH, 'rb') as f:
key1 = f.read()
with open(CERT_PATH, 'rb') as f:
cert1 = f.read()
print("Create socket object")
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
# time.sleep(3)
print("Now getting address")
# addr = usocket.getaddrinfo(HOST, PORT)[0][-1]
addr = ('172.217.31.196', 443)
print(addr)
print("Connecting to the server")
time.sleep(3)
s.connect(addr)
print("Certificate exchange")
time.sleep(10)
sock = ssl.wrap_socket(s) #, key = key1, cert = cert1)
print("Write to server")
time.sleep(2)
sock.write(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (PATH, HOST), 'utf8'))
time.sleep(2)
print(sock.read(100))
############### End of SSL connection