def read(): sleep(2) hx.tare() print(hx.read()) sleep(2) while True: try: global rfid rfid = do_read() if rfid is None: rfid = '[0, 0, 0, 0]' global distancia distancia = sensor.distance_cm() global peso peso = hx.read() # estado pronta = 2 quer dizer que esta so lendo. msg = (b'{0}|{1}|{2:3}|{3:3}|{4:3}'.format(CLIENT_ID, 2, distancia, str(rfid), peso)) #msg = (b'{0}|{1:3}|{2:3}|{3:3}'.format(pronta, distancia, str(rfid), peso)) client.publish(TOPIC, msg) # Publish sensor data to MQTT topic print(msg) except OSError as er: print(er.args[0]) print('Erro na coleta.') continue sleep(1)
def rfid_read(): global device, led1, wdt led1.open('led1') rdr = mfrc522.MFRC522() while True: ret, cardid = read.do_read(rdr) if ret == True: print('card authen ok!') senddata = { 'cardinfo': 'findCard', 'cardid': "0x%02x%02x%02x%02x" % (cardid[0], cardid[1], cardid[2], cardid[3]) } data = {'params': ujson.dumps(senddata)} device.postProps(data) level = led1.read() if level == 1: led1.write(0) else: led1.write(1) else: print('card authen failed!') time.sleep(1) wdt.feed()
def run(): hx.tare() while True: try: rfid = do_read() if rfid is None: rfid = '0' distance = sensor.distance_cm() peso = hx.read() msg = (b'ultrasonic: {0:3}, rfid: {1:3}, peso: {2:3}'.format( distance, str(rfid), peso)) client.publish(TOPIC, msg) # Publish sensor data to MQTT topic print(msg) except OSError: print('Failed to read sensor.') sleep(4)
import read p = read.do_read() print(p) """ import write write.do_write() """
import read read.do_read()
def nfc_read(): read.do_read()