Compare commits

17 Commits

Author SHA1 Message Date
152b541a6c Test
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 5s
2026-04-22 13:49:12 +02:00
44fe3361a3 Now working
All checks were successful
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 5s
2026-04-22 13:41:39 +02:00
e43aee9b13 Wrong direction and also not enabled on boot
All checks were successful
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 6s
2026-04-22 12:51:31 +02:00
d4c69e4b32 Frontend test
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Successful in 6s
2026-04-22 12:48:27 +02:00
28457eb200 Frontend test
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Successful in 5s
2026-04-22 12:45:29 +02:00
f1c530e5b1 Motor driver fix
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Successful in 5s
2026-04-22 12:34:26 +02:00
1e3198d09b Motor driver fix
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 5s
2026-04-22 12:31:15 +02:00
965d6dde63 Test Motor
All checks were successful
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 6s
2026-04-22 12:19:49 +02:00
e5a65f2dcf TEst CI
All checks were successful
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 7s
2026-04-22 11:54:16 +02:00
ad6d369dcf TEst CI
Some checks failed
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Failing after 4s
2026-04-22 11:53:18 +02:00
5a4d0b9348 Test CI
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Successful in 4s
2026-04-22 11:49:20 +02:00
42979daaf2 Test CI
Some checks failed
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Failing after 4s
2026-04-22 11:48:31 +02:00
f8172d9323 Test CI
Some checks failed
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Failing after 4s
2026-04-22 11:46:02 +02:00
4256f65161 Test CI
Some checks failed
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 13s
Build / release (push) Failing after 2s
2026-04-22 11:44:47 +02:00
c113139303 Test CI
Some checks failed
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 14s
Build / release (push) Failing after 1s
2026-04-22 11:43:05 +02:00
6ea0479059 Test CI
Some checks failed
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 12s
Build / release (push) Failing after 13s
2026-04-22 11:40:28 +02:00
0c673ab5f1 Test CI
Some checks failed
Build / build-backend (push) Failing after 4s
Build / build-web (push) Failing after 11s
Build / release (push) Has been skipped
2026-04-22 11:39:25 +02:00
8 changed files with 323 additions and 9 deletions

0
.codex Normal file
View File

View File

@@ -1,4 +1,4 @@
name: Build Nuxt App name: Build
on: on:
push: push:
@@ -6,7 +6,7 @@ on:
- master - master
jobs: jobs:
build: build-web:
runs-on: docker runs-on: docker
defaults: defaults:
@@ -43,12 +43,63 @@ jobs:
cd dist_package cd dist_package
zip -r ../quibot-web.zip . zip -r ../quibot-web.zip .
# Create or update release and upload asset - name: Upload Web artifact
- name: Upload Release uses: actions/upload-artifact@v3
uses: softprops/action-gh-release@v1 with:
name: quibot-web
path: quibot-web/quibot-web.zip
build-backend:
runs-on: docker
defaults:
run:
working-directory: backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt update
apt install -y zip
- name: Create zip
run: |
zip -r backend.zip .
- name: Upload Backend artifact
uses: actions/upload-artifact@v3
with:
name: backend
path: backend/backend.zip
release:
runs-on: docker
needs: [build-web, build-backend]
steps:
- name: Download Web Artifact
uses: actions/download-artifact@v3
with:
name: quibot-web
path: dist
- name: Download Backend Artifact
uses: actions/download-artifact@v3
with:
name: backend
path: dist
- name: Create Release
uses: https://gitea.com/actions/gitea-release-action@v1
with: with:
tag_name: latest tag_name: latest
name: Latest Build name: Latest Build
files: quibot-web/quibot-web.zip overwrite_files: true
files: |
dist/quibot-web.zip
dist/backend.zip
env: env:
GITHUB_TOKEN: ${{ secrets.GITEATOKEN }} GITEA_TOKEN: ${{ secrets.GITEATOKEN }}

2
backend/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
__pycache__/
venv/

112
backend/main.py Normal file
View File

@@ -0,0 +1,112 @@
from fastapi import FastAPI, HTTPException
import subprocess
import threading
import time
import RPi.GPIO as GPIO
app = FastAPI()
# -------------------------
# GPIO SETUP
# -------------------------
STEP = 23
DIR = 24
EN = 25
GPIO.setmode(GPIO.BCM)
GPIO.setup(STEP, GPIO.OUT)
GPIO.setup(DIR, GPIO.OUT)
GPIO.setup(EN, GPIO.OUT)
GPIO.output(EN, GPIO.LOW)
motor_thread = None
def step_motor(steps, direction, delay=0.001):
GPIO.output(DIR, direction)
for _ in range(steps):
GPIO.output(STEP, GPIO.HIGH)
time.sleep(delay)
GPIO.output(STEP, GPIO.LOW)
time.sleep(delay)
def motor_step(dir):
dir_pin = GPIO.HIGH if dir == "forward" else GPIO.LOW
time.sleep(0.02) # small delay before starting
print("Motor running...")
step_motor(200, dir_pin, 0.001)
# -------------------------
# SAFE COMMAND WHITELIST
# -------------------------
COMMANDS = {
"restart_nginx": ["sudo", "systemctl", "restart", "nginx"],
"uptime": ["uptime"],
"update": ["sudo", "apt", "update"]
}
# -------------------------
# API ENDPOINTS
# -------------------------
@app.post("/run")
def run_task(task: str, token: str):
if token != "MY_SECRET_TOKEN":
raise HTTPException(status_code=403, detail="Unauthorized")
if task not in COMMANDS:
raise HTTPException(status_code=400, detail="Invalid task")
try:
result = subprocess.check_output(COMMANDS[task], text=True)
return {"output": result}
except subprocess.CalledProcessError as e:
return {"error": e.output}
@app.post("/motor/step/forward")
def start_motor(token: str):
global motor_thread
if token != "MY_SECRET_TOKEN":
raise HTTPException(status_code=403, detail="Unauthorized")
motor_thread = threading.Thread(target=motor_step, args=("forward",), daemon=True)
motor_thread.start()
return {"status": "motor started"}
@app.post("/motor/step/backwards")
def start_motor(token: str):
global motor_thread
if token != "MY_SECRET_TOKEN":
raise HTTPException(status_code=403, detail="Unauthorized")
motor_thread = threading.Thread(target=motor_step, args=("backwards",), daemon=True)
motor_thread.start()
return {"status": "motor started"}
@app.post("/motor/stop")
def stop_motor(token: str):
if token != "MY_SECRET_TOKEN":
raise HTTPException(status_code=403, detail="Unauthorized")
GPIO.output(EN, GPIO.HIGH) # disable driver
return {"status": "motor stopped"}
@app.on_event("shutdown")
def shutdown():
global motor_running
motor_running = False
GPIO.output(EN, GPIO.HIGH)
GPIO.cleanup()

View File

@@ -1,3 +1,120 @@
<template> <template>
<h1>Test</h1> <main class="panel">
<h1>Quibot Motor Control</h1>
<div class="actions">
<button :disabled="pending" @click="callMotor('step/forward')">
{{ pending && action === 'step/forward' ? 'Starting...' : 'Step Forward' }}
</button>
<button :disabled="pending" @click="callMotor('step/backwards')">
{{ pending && action === 'step/backwards' ? 'Starting...' : 'Step Backwards' }}
</button>
<button :disabled="pending" class="stop" @click="callMotor('stop')">
{{ pending && action === 'stop' ? 'Stopping...' : 'Stop' }}
</button>
</div>
<p v-if="message" class="message">
{{ message }}
</p>
<p v-if="error" class="error">
{{ error }}
</p>
</main>
</template> </template>
<script setup lang="ts">
import { ref } from 'vue'
type MotorAction = 'step/forward' | 'step/backwards' | 'stop'
const pending = ref(false)
const action = ref<MotorAction | null>(null)
const message = ref('')
const error = ref('')
async function callMotor(nextAction: MotorAction) {
pending.value = true
action.value = nextAction
message.value = ''
error.value = ''
try {
const response = await $fetch<{ status?: string }>(`/api/motor/${nextAction}`, {
method: 'POST',
})
message.value = response.status || `${nextAction} request sent`
} catch (err: any) {
error.value = err?.data?.statusMessage || err?.data?.message || err?.message || 'Request failed'
} finally {
pending.value = false
action.value = null
}
}
</script>
<style scoped>
:global(body) {
margin: 0;
font-family: Helvetica, Arial, sans-serif;
background: #f3f4f6;
}
.panel {
min-height: 100vh;
display: grid;
place-content: center;
gap: 1rem;
padding: 2rem;
text-align: center;
}
h1 {
margin: 0;
color: #111827;
}
.actions {
display: flex;
gap: 1rem;
justify-content: center;
}
button {
border: 0;
border-radius: 0.75rem;
padding: 0.9rem 1.4rem;
font-size: 1rem;
font-weight: 700;
color: #fff;
background: #2563eb;
cursor: pointer;
}
button.stop {
background: #dc2626;
}
button:disabled {
opacity: 0.7;
cursor: wait;
}
.message,
.error {
margin: 0;
font-size: 0.95rem;
}
.message {
color: #166534;
}
.error {
color: #b91c1c;
}
</style>

View File

@@ -2,6 +2,10 @@
export default defineNuxtConfig({ export default defineNuxtConfig({
compatibilityDate: '2025-07-15', compatibilityDate: '2025-07-15',
devtools: { enabled: true }, devtools: { enabled: true },
runtimeConfig: {
quibotBaseUrl: process.env.QUIBOT_BASE_URL || 'http://quibot:8000',
quibotToken: process.env.QUIBOT_TOKEN || 'MY_SECRET_TOKEN',
},
vite: { vite: {
optimizeDeps: { optimizeDeps: {
include: [ include: [

View File

@@ -0,0 +1,18 @@
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const direction = getRouterParam(event, 'direction')
if (direction !== 'forward' && direction !== 'backwards') {
throw createError({
statusCode: 400,
statusMessage: 'Invalid motor direction',
})
}
return await $fetch(`${config.quibotBaseUrl}/motor/step/${direction}`, {
method: 'POST',
query: {
token: config.quibotToken,
},
})
})

View File

@@ -0,0 +1,10 @@
export default defineEventHandler(async () => {
const config = useRuntimeConfig()
return await $fetch(`${config.quibotBaseUrl}/motor/stop`, {
method: 'POST',
query: {
token: config.quibotToken,
},
})
})