uWebsocket can not connect via domain

91 Views Asked by At

I have an esp8266 running micro python. i use the library uWebsocket to make a websocket connection to my server. The problem is that I can not connect through the domain I get the following error:

WLAN-Verbindung hergestellt. IP-Adresse: 192.168.178.87
URI(protocol='ws', hostname='smarthome.this-co.de', port=80, path='/cable')
/cable
<closure>
b'HTTP/1.1 301 Moved Permanently'
Traceback (most recent call last):
File "<stdin>", line 27, in <module>
File "/lib/uwebsockets/client.py", line 63, in connect
AssertionError: b'HTTP/1.1 301 Moved Permanently'

I can connect via Postman or other tools. Can it be that uWebsocket does not accept domains and I have to use an Ip? because if I address a local server via the Ip it works.

This is my code up to the point where it makes the websocket call:

import network
from machine import ADC
import uwebsockets.client as websocket
import ujson as json
from machine import Pin
import time

sensor_pin = Pin(14, Pin.IN)

wifi_ssid = "wifi-ssid"
wifi_password = "password"
websocket_server_url = "ws://smarthome.this-co.de/cable"

# WLAN-Verbindung herstellen
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect(wifi_ssid, wifi_password)

# Warten, bis die WLAN-Verbindung hergestellt ist
while not sta_if.isconnected():
    pass

print("WLAN-Verbindung hergestellt. IP-Adresse:", sta_if.ifconfig()[0])


# WebSocket-Verbindung herstellen
ws = websocket.connect(websocket_server_url)
0

There are 0 best solutions below