odelot / aws-mqtt-websockets

Implementation of a middleware to use AWS MQTT service through websockets, aiming the ESP8266 plataform
GNU Lesser General Public License v3.0
231 stars 67 forks source link

mqtt-websockets for mosquitto #21

Closed zenonasz closed 6 years ago

zenonasz commented 7 years ago

Hi,

Any chance of porting the library so it can support the mosquitto broker?

Havent try to use it as it is with the mosquitto broker but as i understand the technology is similar.

Thanks,

Zen

odelot commented 7 years ago

probably the mosquito broker secures the connection via https, so you don't need to use MQTT over websockets as we need to use with AWS

You can use a MQTT library directly, like the Paho MQTT library I am using in this solution.

zenonasz commented 7 years ago

of course you need to. if you want to reach mqtt through 443 or port 80 and not punch a hole in your router.

odelot commented 7 years ago

The idea of this library is provide a way to use AWS MQTT with ESP8266. The use of the websockets protocol is needed because when the library was created, the esp cannot handle tls 1.2 and thus cannot connect to the MQTT server.

when I was building the library, I designed it to override the AWS signing step to use mqtt over websockets (they use their sv4 sign procedure together with HTTPs.

I never tested it, but here is how to use it:

Instead of configure the library with AWS stuff like this:

awsWSclient.setAWSRegion(aws_region);
awsWSclient.setAWSDomain(aws_endpoint);
awsWSclient.setAWSKeyID(aws_key);
awsWSclient.setAWSSecretKey(aws_secret);

you use just:

awsWSclient.setPath ("mypahomqttwebsocketpath.com");

if you want to use https, please add:

awsWSclient.setUseSSL(true);

If it works, it would be nice to publish as an example of use :-)

AND PLEASE DO NOT PUNCH A HOLE IN YOUR ROUTER! use the firewall ha ha ha

Vayatoalla commented 6 years ago

Well. I tried this with a Mosquitto server and it works. I am using SSL. Only thing that I cannot resolve yet is how to configure the connection with user and password.

Regards!

odelot commented 6 years ago

@Vayatoalla

using paho, you can send username and password like this:

MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.MQTTVersion = 4;
    data.clientID.cstring = clientID;
    data.username.cstring = "username";
    data.password.cstring = "password";

you can also use pubsubclient mqtt client instead of paho. see the example folder