Skip to content

Commit

Permalink
add wifi stub
Browse files Browse the repository at this point in the history
  • Loading branch information
previ committed Jun 16, 2024
1 parent fb0f02e commit fee8487
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 6 deletions.
2 changes: 1 addition & 1 deletion coderbot/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pyaudio
import alsaaudio

from six.moves import queue
import queue
# [END import_libraries]

# Audio recording parameters
Expand Down
5 changes: 1 addition & 4 deletions docker/stub/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# API framework
connexion==2.14.2
Flask==2.2.5
Flask-Cors==3.0.10
connexion[uvicorn,flask,swagger-ui]==3.0.5
tinydb==4.8.0
Werkzeug==2.2.3

# Misc utils
setuptools==69.2.0
Expand Down
2 changes: 1 addition & 1 deletion docker/stub/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

export PYTHONPATH=./stub:./test:./coderbot
cd /coderbot
python3 coderbot/main.py
python3 coderbot/main.py & python3 stub/wifi/main.py
19 changes: 19 additions & 0 deletions stub/wifi/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logging

def list_access_points():
return {"ssids": [{"ssid": "my_wifi"}]}

def connection_status():
return {"wifi": "true", "internet": "true"}

def connect():
return "ok"

def forget():
return "ok"

def sset_hotspot_ssid():
return "ok"

def set_hotspot_password():
return "ok"
35 changes: 35 additions & 0 deletions stub/wifi/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python

import os
import logging
import logging.handlers
import connexion
from connexion.middleware import MiddlewarePosition
from starlette.middleware.cors import CORSMiddleware

# Logging configuration
logger = logging.getLogger()
logger.setLevel(os.environ.get("LOGLEVEL", "INFO"))

## (Connexion) Flask app configuration

# Serve a custom version of the swagger ui (Jinja2 templates) based on the default one
# from the folder 'swagger-ui'. Clone the 'swagger-ui' repository inside the backend folder

app = connexion.App(__name__)
app.add_middleware(
CORSMiddleware,
position=MiddlewarePosition.BEFORE_EXCEPTION,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

## New API and web application

# API v1 is defined in v1.yml and its methods are in api.py
app.add_api('v1.yml')

if __name__ == "__main__":
app.run(host="0.0.0.0", port=9090)
64 changes: 64 additions & 0 deletions stub/wifi/v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
openapi: "3.0.0"
info:
version: "1.0"
title: OpenAPI 3.0 definition of WiFi API

servers:
- url: http://coderbot.local/v1

# Paths supported by the server application
paths:
/list_access_points:
get:
operationId: "api.list_access_points"
summary: "list Access Points"
responses:
200:
description: "ok"
tags:
- Wifi
/connection_status:
get:
operationId: "api.connection_status"
summary: "connection Status"
responses:
200:
description: "ok"
tags:
- Wifi
/connect:
post:
operationId: "api.connect"
summary: "connect"
responses:
200:
description: "ok"
tags:
- Wifi
/forget:
post:
operationId: "api.forget"
summary: "forget"
responses:
200:
description: "ok"
tags:
- Wifi
/sset_hotspot_ssid:
post:
operationId: "api.sset_hotspot_ssid"
summary: "sset_hotspot_ssid"
responses:
200:
description: "ok"
tags:
- Wifi
/set_hotspot_password:
post:
operationId: "api.set_hotspot_password"
summary: "set_hotspot_password"
responses:
200:
description: "ok"
tags:
- Wifi

0 comments on commit fee8487

Please sign in to comment.