summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2024-03-25 13:10:02 +0200
committerMartial Simon <msimon_fr@hotmail.com>2024-03-25 13:10:02 +0200
commit7913792a6a9c5b651e7caa79fe4f0610272e0f58 (patch)
treee7a233122e690d9eabb1b1ba90db2744e09577f4
parent5b759155d891fb8348d0b6a44f794db345127a45 (diff)
feat: mqtt client
-rw-r--r--.vscode/extensions.json13
-rw-r--r--.vscode/launch.json15
-rw-r--r--.vscode/settings.json7
-rw-r--r--index.html2
-rw-r--r--index.js2
-rw-r--r--robot.js20
-rw-r--r--robot/main.py4
7 files changed, 50 insertions, 13 deletions
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 @@
<div id="robot"></div>
</canvas>
+ <script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
+ <script src="./robot.js"></script>
<script src="./index.js"></script>
</body>
</html>
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
############################################################