socketio
-
Re: usocket vs socket
Hi,
I uses socketio when writing for Beaglebone Black Wireless. The code to emit data, sio_emit, in socketio is very simple. I wondered if there is equivalent when writing for Pycom.import time import Adafruit_BBIO.GPIO as GPIO import Adafruit_BBIO.PWM as PWM import socketio # Reed click at slot 4 # Buzz click at slot 3 sio = socketio.Client() GPIO.setup("P8_10", GPIO.IN) # Reed switch setup @sio.event def connect(): print('Connection established.') @sio.event def disconnect(): print('Disconnected from server.') @sio.event def Web_ClientReedEvent(RxData): if RxData["data"] == 1: PWM.start("P8_19", 50) PWM.set_frequency("P8_19", 1000) if RxData["data"] == 0: PWM.stop("P8_19") OldValue = 0 while True: try: sio.connect('http://192.168.1.64:5000') break except: print("Try to connect to the server.") pass while True: if GPIO.input("P8_10"): DigitalValue = 1 else: DigitalValue = 0 # Check if there is a change in reedstatus if (OldValue!=DigitalValue): sio.emit('ClientReedEvent', {'data': DigitalValue}) OldValue = DigitalValue if (OldValue==1): print("Magnet detected") else: print("No Magnet") time.sleep(0.1)