Skip to content

riddlesio/WebSocketStreamClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebSocketStreamClient

A WebSocketClient that implements Client.h so that the PubCubClient MQTT library can use it - with wss or ws.

Adjustments

The mosquitto websocket implementation requires the Sec-WebSocket-Protocol header. To achive this I needed to fork arduino-libraries/ArduinoHttpClient to riddlesio/ArduinoHttpClient

Dependencies

WITH Board version 2.7.X : (don't work on previous versions) no more use of websocketclient250 (websocketstream updated to meet client.h declarations)

<!> IF the size of MQTT MESSAGE is > 128 bytes, the websocket hang => add (pubsubclient) .setBufferSize(512) => change in websocket.h iTxBuffer[512]

Tested with esp8266/2.5.0 AND ALSO 2.6.3 Board libraries. There is an example node.js server that you can use here with this library at web-socket-mqtt.

Usage

See examples folder for a complete program.

void onMqttPublish(char *topic, byte *payload, unsigned int length)
{
  // handle mqtt messages here
}

WiFiClientSecure wiFiClient;
WebSocketClient wsClient(wiFiClient, host, port);
WebSocketStreamClient wsStreamClient(wsClient, path, protocol);
PubSubClient mqtt(wsStreamClient);

wiFiClient.setFingerprint(fingerprint);
mqtt.setCallback(onMqttPublish);

if (mqtt.connect("your_identifier"))
{
  mqtt.publish("topic1", "hello world");
  mqtt.subscribe("topic2");
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%