Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # URL http:// URL /queue/request.php?print=true&category=1&json=json"
- # response ex. {"category":"Queue", "number":"001", "date":"2021-02-02 12:34:56"}
- import network,socket,json
- from machine import Pin,time_pulse_us,UART
- from time import sleep,sleep_ms,sleep_us
- blk=Pin(13,Pin.OUT,value=1)
- buz=Pin(12,Pin.OUT,value=0)
- trg=Pin(14,Pin.OUT,value=0)
- ech=Pin(0,Pin.IN)
- prt=UART(1,9600,bits=8,parity=None,stop=1)
- sta=network.WLAN(network.STA_IF)
- def dbg(s):
- print(s)
- def htG(u):
- print(u);_,_,h,f=u.split('/',3);h,p,_=(h+":80:").split(':',2);p=int(p);a=socket.getaddrinfo(h,p)[0][-1];s=socket.socket();s.connect(a);s.send(bytes("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n"%(f,h),'utf8'));d=bytes([]);w=0
- while 1:
- d=d+s.recv(1024)
- if w==len(d)or len(d)>1024:
- break
- w=len(d)
- while s.recv(64):
- pass
- s.close();_,d=str(d,'utf8').split("\r\n\r\n",1)
- return d
- cnt=0
- while 1:
- try:
- dbg("ite")
- if not sta.isconnected():
- dbg("Con")
- blk.off();sleep(1);blk.on();
- sta.active(True);sta.connect(" SSID "," PASSWORD ");sleep(1)
- trg.on();sleep_us(10);trg.off();mm=time_pulse_us(ech,1,30000)*100//582
- if 10<mm<300:
- cnt=cnt+1
- else:
- cnt=0
- dbg("mm="+str(mm)+" cnt="+str(cnt))
- if cnt==0:
- blk.on();sleep_ms(250)
- elif cnt in(1,3,4,5,7,8,9,11,12,13):
- blk.off();sleep_ms(250)
- elif cnt in(2,6,10):
- blk.on();buz.on();sleep_ms(100);buz.off();blk.off();sleep_ms(150)
- elif cnt==14:
- blk.on();buz.on();sleep_ms(250);buz.off()
- a=(" __ _ ___ ____ _ _ ___ __ ____ ___ ___ "+
- " / \ / | |_ ) |__ / | | | | __| / / |__ |( _ ) / _ \ "+
- "| () | | | / / |_ \ |_ _||__ \ / _ \ / / / _ \ \_ / "+
- " \__/ |_| /___| |___/ |_| |___/ \___/ /_/ \___/ /_/ ")
- obj=json.loads(htG("http:// URL /queue/request.php?print=true&category=1&json=json"))
- dbg("cat="+obj['category']+" no="+obj['number']+" date="+obj['date'])
- prt.write(" COMPANY NAME \r\nCategory: "+obj['category']+"\r\n")
- x,y,z=[int(i)for i in obj['number']]
- for i in range(0,4):
- prt.write(" "+a[60*i+6*x:60*i+6*x+6]+a[60*i+6*y:60*i+6*y+6]+a[60*i+6*z:60*i+6*z+6]+"\r\n")
- prt.write(obj['date']+"\r\n")
- prt.write(b"\x0a\x0a\x1d\x56\x00\r\n")
- else:
- sleep_ms(250)
- except KeyboardInterrupt:
- break
- except:
- pass
- sleep(250)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement