Apr-18-2019, 12:55 PM
(Apr-17-2019, 06:32 PM)Alfalfa Wrote: The error is caused by the indentation, simply remove "@QtCore.pyqtSlot()" which is useless there, and reduce the indentation of lines 14 and 15 so it is coherent with the rest of your code.
import sys, time, socket from PyQt5 import QtWidgets, QtCore HOST = '192.168.1.38' # The server's hostname or IP address, NodeMCU IP Address PORT = 80 # The port used by the server, PORT NUMBER in ARDUINO CODE class WorkerThread(QtCore.QObject): signal = QtCore.pyqtSignal(int) def __init__(self): super().__init__() with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) s.sendall(b'Hello, world') def run(self): while True: data = s.recv(1024) print('Received distance value', repr(data)) self.signal.emit(int(data))
Error:Traceback (most recent call last):
File "c:/Users/User/Desktop/PYQT/work_1.py", line 20, in run
data = s.recv(1024)
NameError: name 's' is not defined
I tried