Skip to content

Commit

Permalink
feat(wip): qrcode generator
Browse files Browse the repository at this point in the history
  • Loading branch information
owulveryck committed Oct 30, 2023
1 parent 9742b8c commit 4e1f126
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 9 deletions.
43 changes: 43 additions & 0 deletions tools/qrcodepdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# reMarkable IP Streamer QR Code Generator

This tool is designed to fetch the IP addresses of your reMarkable device and generate a QR code containing these IP addresses in a PDF. The generated PDF can be displayed on the reMarkable and scanned with a mobile device to reveal the IP addresses. Please note that this feature is experimental.

## Installation

To set up the tool, follow these steps:

1. **Upload the PDF File**: First, you need to upload the file `goMarkableStreamQRCode.pdf` to your reMarkable device. You can do this using the official reMarkable tool.

2. **Compile the Tool**:
- On your computer, open a terminal and navigate to the directory containing the source code.
- Run the following command to compile the tool:
```bash
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 go build -o genIP.arm
```

3. **Copy the Binary to reMarkable**:
- Use `scp` or any other SSH tool to copy the `genIP.arm` binary to your reMarkable device.
- Example:
```bash
scp genIP.arm root@<remarkable_ip>:
```

4. **Launch the Tool**:
- SSH into your reMarkable device:
```bash
ssh root@<remarkable_ip>
```
- Run the tool:
```bash
./genIP.arm &
```
Adding `&` at the end of the command will make it run in the background, allowing it to continue running even after you disconnect.

## How it Works

The utility runs in an endless loop, checking every minute to see if the network has changed. If a change in the network is detected, it updates the content of the `goMarkableStreamQRCode.pdf` file with the new IP addresses.

## Notes

- This tool is experimental; use it at your own risk and feel free to contribute or report issues.

52 changes: 52 additions & 0 deletions tools/qrcodepdf/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
)

func searchContentFiles(dirPath string) []string {
matchedFiles := make([]string, 0)
files, err := ioutil.ReadDir(dirPath)
if err != nil {
fmt.Println("Error reading directory:", err)
return matchedFiles
}

for _, file := range files {
if file.IsDir() {
continue // Skip directories
}

if filepath.Ext(file.Name()) == ".metadata" {
fullPath := filepath.Join(dirPath, file.Name())
if checkFileForJSONContent(fullPath) {
matchedFiles = append(matchedFiles, fullPath)
}
}
}
return matchedFiles
}

func checkFileForJSONContent(filePath string) bool {
content, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Println("Error reading file:", err)
return false
}

var jsonData map[string]interface{}
if err := json.Unmarshal(content, &jsonData); err != nil {
fmt.Println("Error decoding JSON in file:", filePath, err)
return false
}

if visibleName, ok := jsonData["visibleName"]; ok {
if visibleNameStr, ok := visibleName.(string); ok && visibleNameStr == qrPDFName {
return true
}
}
return false
}
Binary file added tools/qrcodepdf/goMarkableStreamQRCode.pdf
Binary file not shown.
29 changes: 20 additions & 9 deletions tools/qrcodepdf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,46 @@ package main
import (
"flag"
"fmt"
"log"
"net"
"os"
"path/filepath"
"time"

"github.com/jung-kurt/gofpdf"
"github.com/skip2/go-qrcode"
)

var outputFile string
var (
outputFile string
qrPDFName string
)

func init() {
flag.StringVar(&outputFile, "output", "output.pdf", "The output PDF file")
flag.StringVar(&qrPDFName, "output", "goMarkableStreamQRCode.pdf", "The output PDF file")
}

func main() {
flag.Parse()
matchedFiles := searchContentFiles(".local/share/remarkable/xochitl/")
if len(matchedFiles) != 1 {
log.Fatal("did not find the " + qrPDFName)
}
outputFile = matchedFiles[0]
outputFile = outputFile[:len(outputFile)-len(filepath.Ext(outputFile))] + ".pdf"
log.Println("using ", outputFile)

// Fetch initial IP addresses
ips, err := getIPAddresses()
if err != nil {
fmt.Println("Error fetching IP addresses:", err)
log.Println("Error fetching IP addresses:", err)
return
}

// Generate initial PDF
err = generatePDF(ips, outputFile)
if err != nil {
fmt.Println("Error generating PDF:", err)
log.Println("Error generating PDF:", err)
return
}

Expand All @@ -41,25 +53,22 @@ func main() {
// Fetch current IP addresses
currentIPs, err := getIPAddresses()
if err != nil {
fmt.Println("Error fetching IP addresses:", err)
log.Println("Error fetching IP addresses:", err)
continue
}

// Check if the IP addresses have changed
if !isEqual(ips, currentIPs) {
fmt.Println("IP addresses have changed. Regenerating PDF...")

// IP addresses have changed, update the PDF
err = generatePDF(currentIPs, outputFile)
if err != nil {
fmt.Println("Error generating PDF:", err)
log.Println("Error generating PDF:", err)
continue
}

// Update the known IP addresses
ips = currentIPs

fmt.Println("PDF successfully regenerated.")
}
}
}
Expand Down Expand Up @@ -112,6 +121,8 @@ func generatePDF(ips []net.IP, outputFile string) error {
y += height + labelHeight + 10
}
}
pdf.SetXY(x, y+height)
pdf.MultiCell(width, labelHeight, time.Now().String(), "0", "C", false)

// Save PDF to file
err := pdf.OutputFileAndClose(outputFile)
Expand Down

0 comments on commit 4e1f126

Please sign in to comment.