Skip to content

npkalala/AWSIoT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Simple Sample of Connect to AWSIoT with C#

This sample code including the following fucntions that you can use.

  • Pushlish Message
  • Subscribe Topics
  • Check MQTT IsConnect

The Steps to use it

  • 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

The Command to create .pfx with OpenSSL

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

Plugins

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]

Development

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));
}

Todos

  • Write Tests
  • Implement others delagate event

License

None

feel free to use it!

About

How to Publish/Subscribe AWSIoT with MQTT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages