Coder Social home page Coder Social logo

librarylight_pi's Introduction

liveTest

liveTest for RPi / Bookcheck

  • Python3
  • C++

librarylight_pi's People

Contributors

haryunio avatar

Watchers

James Cloos avatar  avatar

librarylight_pi's Issues

TestCode

-*-coding:utf-8

import serial
import urllib
import urllib.request
import time
import json
import RPi.GPIO as GPIO

red = 17
green = 18
blue = 27

GPIO.setmode(GPIO.BCM)
GPIO.setup(red, GPIO.OUT)
GPIO.setup(green, GPIO.OUT)
GPIO.setup(blue, GPIO.OUT)

Freq = 100 #Hz

bookcaseNumber = '1'
data = ["3A 9B AA A7"]
url = "http://henocks.dothome.co.kr/f6.php"
url2 = "https://ll.0o0.moe/API/login"
url_rfid = "https://ll.0o0.moe/API/takeMyBooks"
delaycount = 0
Token = "########################################################################"

ser = serial.Serial('/dev/ttyACM0', 9600, timeout=10)

RED = GPIO.PWM(red, Freq)
RED.start(0)
GREEN = GPIO.PWM(green, Freq)
GREEN.start(0)
BLUE = GPIO.PWM(blue, Freq)
BLUE.start(0)

class RGB:
def on(color):
print("RGB LED on with color : "+color)
this.color(100,100,100)

def off():
    print("RGB LED off")
    this.color(0,0,0)

def color(R, G, B):
    RED.ChangeDutyCycle(R)
    GREEN.ChangeDutyCycle(G)
    BLUE.ChangeDutyCycle(B)

class server:
def req(dat):
sdata = urllib.parse.urlencode({'flag': dat}).encode('utf-8')
request = urllib.request.Request(url)
request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
f = urllib.request.urlopen(request, sdata)
return f.read().decode('utf-8')

def req_rfid(dat, URL):
    sdata = urllib.parse.urlencode({'libraryAPIToken': Token, 'bookcaseNumber': bookcaseNumber, "bookCodes" : dat}).encode('utf-8')
    request = urllib.request.Request(URL)
    request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
    f = urllib.request.urlopen(request, sdata)
    return f.read().decode('utf-8')

def req_login(dat, URL):
    sdata = urllib.parse.urlencode({"ID": "abcde12345", "password" : "abcde12345"}).encode('utf-8')
    request = urllib.request.Request(URL)
    request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
    f = urllib.request.urlopen(request, sdata)
    return f.read().decode('utf-8')

#jsObj = json.loads(server.req_login(data))
    #reason = jsObj["reason"]
    #succ = jsObj["success"]


def checkRequest():  #서버와 통신해서 서버의 응답에 데이터가 있는지 확인
    a = server.req(1)
    print("checked server call : " + a)
    if(int(a) == 1):
        return 1
    else:
        return 0

def receiveRequest(): #서버에서 명령 데이터를 받아옴
    a = server.req(2)
    print("received server call : " + a)
    return a

def sendData(RfidData):  #서버에 데이터 전송
    server.req(RfidData)
    print("RFID Data Sent")

try:
while 1:
response = ser.readline()
if response != '':
if data.count(response[2:-3]) == 0:
data.append(response[2:-3])
print (response)
if delaycount > 5000000:
if server.checkRequest() == 1:
delaycount = 0
stat = str(server.receiveRequest())
if stat[0:1] == "1":
server.sendData(data)
elif stat[0:1] == "2":
RGB.off()
else:
RGB.on(stat)
delaycount += 1

except KeyboardInterrupt:
print("QUITTTING")
RUNNING = False
ser.close()
GPIO.cleanup()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.