diff --git a/.env b/.env new file mode 100644 index 0000000..8a24119 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +REACT_APP_COMPILER_URL=https://compiler.sensebox.de +REACT_APP_BOARD=sensebox-mcu diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 2bf4c11..fae6d5c 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -30,6 +30,29 @@ class WorkspaceFunc extends Component { this.setState({ open: !this.state }); } + compile = () => { + const data = { + "board": process.env.REACT_APP_BOARD, + "sketch": this.props.arduino + }; + + fetch(`${process.env.REACT_APP_COMPILER_URL}/compile`, { + method: "POST", + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(data) + }) + .then(response => response.json()) + .then(data => { + console.log(data) + this.download(data.data.id) + }); + } + + download = (id) => { + const filename = 'sketch' + window.open(`${process.env.REACT_APP_COMPILER_URL}/download?id=${id}&board=${process.env.REACT_APP_BOARD}&filename=${filename}`, '_self'); + } + render() { return (