Skip to content

Commit

Permalink
Fix serial line comms
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSanza committed Nov 25, 2022
1 parent 3d716c8 commit d05ae30
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 39 deletions.
10 changes: 6 additions & 4 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from flask import Flask, request
import flask
from flask_cors import CORS
import arduino_comm
import json
Expand All @@ -8,7 +7,7 @@
app = Flask(__name__)
CORS(app)
database = db.InMemoryDB()
arduino = arduino_comm.SerialLine(port="/dev/ttyACM0", baudrate=9600, timeout=0.1)
arduino = arduino_comm.SerialLine(port="COM3", baudrate=9600, timeout=0.1)

@app.route('/get_logs', methods=['GET'])
def get_logs():
Expand All @@ -17,5 +16,8 @@ def get_logs():

@app.route('/valve_control', methods=['POST'])
def valve_control():
print(request.json)
arduino.write(request.json["angle"])
angle = request.get_json()['angle']
print(f"send: {angle}")
arduino.write_byte(request.json["angle"])

return f"angle"
115 changes: 83 additions & 32 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions frontend/src/components/ManualControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ const ManualControl = () => {

const [angle, setValveAngle] = useState(0);

const url_angle = "http://localhost8080/valve_control"
const url_angle = "http://localhost:5000/valve_control"

const changeValveAngle = value => {
setValveAngle(value);
const post = { angle: angle };
try {
// const res = axios.post(url_angle, post);
// console.log(res.data);
const res = axios.post(url_angle, post);
} catch(e) {
alert(e);
}
Expand Down

0 comments on commit d05ae30

Please sign in to comment.