Works sorta
This commit is contained in:
55
godoor.go
55
godoor.go
@@ -1,6 +1,11 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
import "time"
|
||||
|
||||
const wiegand_a = 17
|
||||
@@ -8,12 +13,56 @@ const wiegand_b = 18
|
||||
const wiegand_bit_timeout = time.Millisecond * 8
|
||||
const solenoid = 21
|
||||
|
||||
type card struct {
|
||||
UidHash string `json:"uid_hash"`
|
||||
}
|
||||
|
||||
type cardToken struct {
|
||||
Token card `json:"token"`
|
||||
}
|
||||
|
||||
type cardList struct {
|
||||
AllowedUids []cardToken `json:"allowed_uids"`
|
||||
}
|
||||
|
||||
type ValidUids map[string]bool // bool has no meaning
|
||||
|
||||
func main() {
|
||||
|
||||
wiegand := WiegandSetup(wiegand_a, wiegand_b, wiegand_bit_timeout, solenoid)
|
||||
|
||||
//openDoor(solenoid_line)
|
||||
go wiegand.cardRunner()
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest(http.MethodGet, "urlrul", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
req.Header.Add("KEY", "keykey")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%v\n", resp)
|
||||
|
||||
var cl cardList
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &cl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
validUids := make(ValidUids)
|
||||
for i, val := range cl.AllowedUids {
|
||||
fmt.Printf("%d: %+v\n", i, val.Token.UidHash)
|
||||
validUids[val.Token.UidHash] = false
|
||||
}
|
||||
|
||||
go wiegand.cardRunner(validUids)
|
||||
|
||||
fmt.Printf("Sleeping\n")
|
||||
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user