在Python中使用TCP接收数据需要帮助

时间:2016-12-10 08:09:50

标签: python-2.7 raspberry-pi3

当我将接收到的数据与char进行比较时,LED没有打开。

这是我的代码:

import RPi.GPIO as GPIO
import time
from time import sleep
import socket
from socket import *
from operator import eq

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)

def led():
    IP="192.168.0.105"
    port=2525
    s=socket(AF_INET, SOCK_STREAM)
    s.connect((IP,port))
    msg=s.recv(1024)
    print msg
    s.close()
    if eq(msg,'a'):
        GPIO.output(17,GPIO.HIGH)
    if eq(msg,'b'):
        GPIO.output(17,GPIO.LOW)
    else:
        print 'Pls Enter Valid Key'

while True:
    led()`

0 个答案:

没有答案
相关问题