5 Commits
v2 ... v4

Author SHA1 Message Date
Arti Zirk
647a90c0f2 Enable Wiegand data internal pull-ups
Some checks reported errors
continuous-integration/drone/push Build is failing
continuous-integration/drone Build was killed
Back Door shield needs it as it does not have external pull-ups
2023-08-11 22:09:22 +03:00
Arti Zirk
92469f11b2 Do not error on git describe if tags are missing
Some checks failed
continuous-integration/drone/push Build is failing
2023-08-11 14:35:57 +03:00
a75aeeb8f9 Add Drone config
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-11 14:28:42 +03:00
Arti Zirk
d4f2624635 Fetch tokens after every longpoll close event 2023-08-11 00:57:24 +03:00
Arti Zirk
2259d3ed6b Add build dockerfile 2023-08-10 20:47:03 +03:00
5 changed files with 48 additions and 28 deletions

2
.drone.yml Normal file
View File

@@ -0,0 +1,2 @@
kind: template
load: docker-multiarch.yaml

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM golang:1.21 as build
WORKDIR /godoor
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN make build
FROM scratch
WORKDIR /
COPY --from=build /godoor/godoor /godoor
ENTRYPOINT ["/godoor"]

View File

@@ -2,7 +2,7 @@
all: build
GOBUILDLDFLAGS="-X main.Version=`git describe --dirty`"
GOBUILDLDFLAGS="-X main.Version=`git describe --always --dirty`"
#GOBUILDLDFLAGS="-X main.Version=`git describe --dirty` -linkmode 'external' -extldflags '-static'"
build:

View File

@@ -195,27 +195,6 @@ func setup() {
http.DefaultClient.Timeout = 120 * time.Second
go func() {
for {
err := waitEvents()
if err != nil {
apiFailuresCount.WithLabelValues("longpoll", config.api.longpoll).Inc()
log.Printf("LongPoll for events failed: %v", err)
log.Println("Will try to LongPoll again in 120 seconds")
time.Sleep(120 * time.Second)
go func() {
err := reloadTokens()
if err != nil {
apiFailuresCount.WithLabelValues("allowed", config.api.allowed).Inc()
}
}()
}
time.Sleep(1 * time.Second)
}
}()
log.Println("Initialized longpoll event loop")
for {
log.Println("Start initial token population")
err := reloadTokens()
@@ -230,6 +209,27 @@ func setup() {
log.Println("Initial token population success")
go func() {
for {
err := waitEvents()
if err != nil {
apiFailuresCount.WithLabelValues("longpoll", config.api.longpoll).Inc()
log.Printf("LongPoll for events failed: %v", err)
log.Println("Will try to LongPoll again soon")
}
time.Sleep(1 * time.Second)
go func() {
err := reloadTokens()
if err != nil {
log.Printf("ReloadTokens failed: %q", err)
apiFailuresCount.WithLabelValues("allowed", config.api.allowed).Inc()
}
}()
}
}()
log.Println("Initialized longpoll event loop")
go cardRunner(wiegand)
log.Println("Setup completed")
@@ -290,7 +290,7 @@ func cardRunner(w Wiegand) {
continue
}
printCardId(card)
//printCardId(card)
hashedHex := hash.HashCardUid(card)
log.Println(hashedHex)
@@ -464,11 +464,11 @@ func handleKeepDoorOpenCloseCleanup() {
}
func sendSwipeEvent(cardUidHash string, success bool) error {
swipeEvent := map[string]string{
swipeEvent := map[string]any{
"uid_hash": cardUidHash,
"door": config.door,
"timestamp": time.Now().Format(time.DateTime),
"success": fmt.Sprint(success),
"timestamp": time.Now().Format(time.RFC3339),
"success": success,
}
data, err := json.Marshal(swipeEvent)
@@ -481,6 +481,7 @@ func sendSwipeEvent(cardUidHash string, success bool) error {
return err
}
req.Header.Add("KEY", config.api.key)
req.Header.Add("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err

View File

@@ -113,14 +113,14 @@ func WiegandSetup(a int, b int, bitTimeout time.Duration, solenoid int) *Wiegand
}
wa, err := gpiod.RequestLine("gpiochip0", a, gpiod.AsInput,
gpiod.WithFallingEdge, gpiod.WithEventHandler(wiegand.wiegandAEvent))
gpiod.WithFallingEdge, gpiod.LineBiasPullUp, gpiod.WithEventHandler(wiegand.wiegandAEvent))
if err != nil {
panic(err)
}
wiegand.aLine = wa
wb, err := gpiod.RequestLine("gpiochip0", b, gpiod.AsInput,
gpiod.WithFallingEdge, gpiod.WithEventHandler(wiegand.wiegandBEvent))
gpiod.WithFallingEdge, gpiod.LineBiasPullUp, gpiod.WithEventHandler(wiegand.wiegandBEvent))
if err != nil {
panic(err)
}