This sample code including the following fucntions that you can use.
- Pushlish Message
- Subscribe Topics
- Check MQTT IsConnect
- A. Download your .pem and private key from AWSIot.
- B. Create .pfx file in the command line using OpenSSL with above.
- C. Including the .pfx and .pem files to your project
For Unix based system
$ openssl pkcs12 -export -out certificate.pfx -inkey ***.private.key -in ***.cert.pem
For Windowsbased system...
$ winpty openssl pkcs12 -export -out certificate.pfx -inkey MyIoT.private.key -in MyIoT.cert.pem
This sample is currently extended with the following plugins/references. Instructions on how to use them in your own application are linked below.
Plugin | README |
---|---|
M2MQTT | [https://m2mqtt.wordpress.com/m2mqtt-and-amazon-aws-iot/] |
AWSIoT | [http://docs.aws.amazon.com/iot/latest/developerguide/iot-sdks.html] |
Create an AuMQTT object :
$ var publisher = new AuMQTT("YourDeviceId");
Settings
//'Qos'
publisher.MqttPolicy = 1;
//'pfx file'
publisher.YourPfxCertificate = "YourCertificate.pfx";
//'password'
publisher.YourPfxCertificatePassword = "YourPassword";
//'Pem file'
publisher.YourPemFile = "YourPemFile.pem";
Setup Topic :
publisher.Topic = "YourTopic";
Publish Message :
publisher.Publish("Message");
Subscribe Topic :
publisher.Subscribe();
//implement the delegate event
publisher.ReceiveMqttMsgEvent += Publisher_ReceiveMqttMsgEvent;
private static void Publisher_ReceiveMqttMsgEvent(uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
{
Console.WriteLine(Encoding.UTF8.GetChars(e.Message));
}
- Write Tests
- Implement others delagate event
None
feel free to use it!