Open mhaberler opened 4 months ago
Hi @mhaberler, I believe it is posible, let me get you the keys:
void ReaderMqttPacket::readMqttPacket(WiFiClient client){
1ª auxBuffer = First read all data from client, to extract WebSocket packet from tcp/ip buffer, mqtt packet is contained in WebSocket packet.
2ª mqttPacketBuffer = extract mqtt packet from auxBuffer.
3ª now replace calls to client.ReadBytes() and client.read() with mqttPacketBuffer, simulating these functions, according to the original readMqttPacket(WiFiClient client) method:
client.ReadBytes(buffer,n bytes), store first n bytes in buffer, so you need to read first n bytes from mqttPacketBuffer and store them in the respective buffer, for example, in fixedHeader.
client.read(), read the next 1 byte from buffer, so you need to read the next 1 byte of mqttPacketBuffer.
// original method to adapt: // 1º reading fixed header. //client.readBytes(fixedHeader,1);
// 2º reading and decoding remainingLengt of this mqtt packet from fixedHeader remainingLengt = readRemainLengtSize(client);
// 3ª reading remaining lengt bytes packet.
remainingPacket = (uint8_t*) malloc(remainingLengt);
client.readBytes(remainingPacket,remainingLengt);
}
Notice that you need to change ReaderMqttPacket::readRemainLengtSize(WiFiClient client) method to, changing client for mqttPacketBuffer.
Lastly, change mqtt port from 1883 to 80 to listen webSockets connections, when you creating MqttBroker object. I hope this helps!.
thanks
I will give it a stab and report here, would appreciate if you can look over my shoulder
any suggestions for the websockets part of the code? several libraries out there looking applicable
this should become be a subclass of MqttBroker, right?
-m
I've taken an intermediate step: put a websockets-to-tcp proxy in front of the broker:
https://github.com/mhaberler/EmbeddedMqttBroker-example/blob/websockets/src/example/main.cpp#L125
seems to work fine
I was looking you example, I don't know ProxyWebSocketsServer.h, but I assume that it is similar to other web sockets libraries:
I will glad to know about your progress.
do you see a way to make this code work over websockets so it's compatible with paho-mqtt js?
thanks in advance
Michael