Skip to content

Commit

Permalink
display cyberfrog uuid during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lermchair committed Nov 5, 2024
1 parent 35d8fd1 commit ae13c84
Show file tree
Hide file tree
Showing 2 changed files with 829 additions and 913 deletions.
14 changes: 10 additions & 4 deletions apps/api/src/setup_cyberfrog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SerialPort } from "serialport";
import { ReadlineParser } from "@serialport/parser-readline";
import { spawn } from "child_process";
import { logger } from "@frogcrypto/shared";
import { publicKeyToUUID } from "./utils";

/**
* pnpm run setup-cyberfrog will set up a Cyberfrog device for FrogCrypto.
Expand All @@ -28,7 +29,7 @@ interface PortInfo {
async function findESP32Port(): Promise<string> {
const ports: PortInfo[] = await SerialPort.list();
const esp32Port = ports.find((port: PortInfo) =>
port.manufacturer?.toLowerCase().includes("espressif"),
port.manufacturer?.toLowerCase().includes("espressif")
);

if (!esp32Port) {
Expand Down Expand Up @@ -67,18 +68,18 @@ function flashFirmware(port: string): Promise<void> {
const esptool = spawn("esptool.py", args, { env: process.env });

esptool.stdout.on("data", (data: string) => {
console.log(data);
console.log(data.toString());
});

esptool.stderr.on("data", (data: string) => {
console.error(data);
console.error(data.toString());
});

esptool.on("close", (code: number) => {
if (code !== 0) {
console.error(`esptool.py process exited with code ${code.toString()}`);
reject(
new Error(`esptool.py process exited with code ${code.toString()}`),
new Error(`esptool.py process exited with code ${code.toString()}`)
);
} else {
console.info("Flashing complete.");
Expand Down Expand Up @@ -126,6 +127,11 @@ async function main() {
// now we can do whatever we want with the pubkey:
console.log("Public key captured successfully:");
console.log(publicKey);

// get the uuid from the public key
const uuid = publicKeyToUUID(publicKey);
console.log("UUID captured successfully:");
console.log(uuid);
// setupCyberFeed(publicKey)
} catch (error) {
console.error(`An error occurred: ${(error as Error).message}`);
Expand Down
Loading

0 comments on commit ae13c84

Please sign in to comment.