turbomatte / M5Stack_E2FS

M5Stacks with Arduino
3 stars 0 forks source link

WEB/IMP: Anbindung MQTT und Webseite #17

Closed turbomatte closed 3 months ago

turbomatte commented 6 months ago

Done when:

Wir die Daten auf die Webseite erlesen können.

turbomatte commented 4 months ago

KAMAL CODE 19.04.2024

const mqtt = require('mqtt')

/***

* Browser 

* This document explains how to use MQTT over WebSocket with the ws and wss protocols. 

* EMQX's default port for ws connection is 8083 and for wss connection is 8084. 

* Note that you need to add a path after the connection address, such as /mqtt. 

*/ 

//const url = 'ws://broker.emqx.io:8083/mqtt'

const url = 'mqtt-broker.zdw31.cloud'

/***

* Node.js 

* This document explains how to use MQTT over TCP with both mqtt and mqtts protocols. 

* EMQX's default port for mqtt connections is 1883, while for mqtts it is 8883. 

*/ 

// const url = 'mqtt://broker.emqx.io:1883'

// Create an MQTT client instance

const options = {

// Clean session

clean: true,

connectTimeout: 4000,

// Authentication

clientId: 'user1',

username: 'user1',

password: 'HWSFI2024!',

}

const client = mqtt.connect(url, options)

client.on('connect', function () {

console.log('Connected')

// Subscribe to a topic

client.subscribe('test', function (err) {

if (!err) { 

  // Publish a message to a topic 

  client.publish('test', 'Hello mqtt') 

} 

})

})

// Receive messages

client.on('message', function (topic, message) {

// message is Buffer

console.log(message.toString())

client.end()

})

lastmainstring commented 4 months ago

26.04.2024 Marius erster Test und Fehler suche zwischen M5Stack und MQTT, Website

lastmainstring commented 4 months ago

26.04.2024 Marius

Änderung des Namen im Code von User1 zu Parkinglot

lastmainstring commented 4 months ago

26.04.2024 Marius

Fehler im Code gefunden Name vom Wlan war falsch

lastmainstring commented 4 months ago

26.04.2024 Marius

änderung im Code erneuter push

WiFiClient client; Adafruit_MQTT_Client mqtt(&client, mqtt_server, mqtt_port, mqtt_username, mqtt_password, "Client69");

Image

lastmainstring commented 4 months ago

26.04.2024 Marius

Änderung im Code erneuter push: Username und Topic geändert

Image

lastmainstring commented 4 months ago

26.04.2024 Marius

Änderung im Code erneuter push:

Diesmal Client ID und umbau von Adafruit auf Pubsubclient Mit test

lastmainstring commented 4 months ago

26.04.2024 Marius

Änderung im Code erneuter push: neue Libarys hinzufügt

Image

Kamalsito commented 3 months ago

Alternative Lösung (Wenn nicht der Hauptcode funktioniert):

<!DOCTYPE html>

MQTT-Verbindung mit Paho JavaScript

MQTT-Verbindung mit Paho JavaScript

turbomatte commented 3 months ago

Website wurde von Kamal nicht weitergemacht.

Ich bin reingesprungen und habe es übernommen.

06.06.2024

Anbindung MQTT und Website funktioniert,

turbomatte commented 3 months ago

Code für die funktionierende website folgt

Ready 2 go critieria erfüllt - wurde in die runde besprochen - und abgegeben.

`<!DOCTYPE html>

MQTT Distance Data

Distance Data

Website Design by Kamal, Leo, and Matte

Implemented by Marius

Scrum Master: Matte | Coder: Leo

`