From 7913792a6a9c5b651e7caa79fe4f0610272e0f58 Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 25 Mar 2024 13:10:02 +0200 Subject: feat: mqtt client --- .vscode/extensions.json | 13 +++++++++++++ .vscode/launch.json | 15 +++++++++++++++ .vscode/settings.json | 7 +++++++ index.html | 2 ++ index.js | 2 +- robot.js | 20 ++++++++++---------- robot/main.py | 4 ++-- 7 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..f8f1a44 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,13 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "lego-education.ev3-micropython" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + "ms-python.python" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d933aeb --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Download and Run", + "type": "ev3devBrowser", + "request": "launch", + "program": "/home/robot/${workspaceRootFolderName}/main.py", + "interactiveTerminal": false + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b0968c1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.eol": "\n", + "debug.openDebug": "neverOpen", + "python.linting.enabled": false, + "python.languageServer": "None" +} diff --git a/index.html b/index.html index 6036bd3..f24f75a 100644 --- a/index.html +++ b/index.html @@ -13,6 +13,8 @@
+ + diff --git a/index.js b/index.js index 8dabb25..4498115 100644 --- a/index.js +++ b/index.js @@ -47,8 +47,8 @@ const drawCross = (x, y) => { canvas.addEventListener('mousedown', (e) => { isPainting = true; - drawCross(e.clientX - canvasOffsetX, e.clientY - canvasOffsetY); + }); /* canvas.addEventListener('mouseup', (e) => { diff --git a/robot.js b/robot.js index 5c259fe..f318441 100644 --- a/robot.js +++ b/robot.js @@ -1,5 +1,4 @@ -const mqtt = require("mqtt"); -const client = mqtt.connect("mqtt://marcelus.net"); +const client = mqtt.connect("ws://marcelus.net:9001"); function wait(ms) { @@ -47,18 +46,19 @@ async function moveTo(x,y) } -client.on('connect', function () { +client.on('connect', () => { + console.log(client) console.log('Connecté au courtier MQTT'); - client.subscribe('move'); - client.publish('move','ULT1') + client.subscribe('move') + moveTo(1000,1000) }); +// client.publish('move','ULT1') -client.on('message', function (topic, message) { +/* client.on('message', function (topic, message) { console.log('Received from ', topic, ' : ', message.toString()); -}); +}); */ -client.on('close', function () { +/* client.on('close', function () { console.log('Déconnecté du courtier MQTT'); -}); +});*/ -moveTo(1000,1000) \ No newline at end of file diff --git a/robot/main.py b/robot/main.py index dadde2d..722a533 100644 --- a/robot/main.py +++ b/robot/main.py @@ -29,7 +29,7 @@ get_tick_rate = 0.1 send_tick_rate = 0.5 sensitivity = 400 safe_distance = 150 -ultraSend = [False] +ultraSend = [True] # Functions @@ -70,7 +70,7 @@ ev3.screen.print("Connected") client.set_callback(listen) client.subscribe(MQTT_Topic_Status) time.sleep(0.5) -ev3.screen.print("Listenning...") +ev3.screen.print("Listening...") # Code ############################################################ -- cgit v1.2.3