{"id":546,"date":"2017-07-16T13:56:50","date_gmt":"2017-07-16T12:56:50","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=546"},"modified":"2017-07-16T13:56:50","modified_gmt":"2017-07-16T12:56:50","slug":"how-to-setup-mqtt-server-on-a-windows-10-desktop","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/miscellaneous\/how-to-setup-mqtt-server-on-a-windows-10-desktop\/","title":{"rendered":"How to Setup MQTT Server on a Windows 10 Desktop"},"content":{"rendered":"<ol>\n<li>Download the Win32 installer from the below link (I couldn\u2019t successfully installed the CygWin version)<br \/>\n<a href=\"https:\/\/mosquitto.org\/download\/\">https:\/\/mosquitto.org\/download\/<\/a><\/li>\n<li>Once downloaded, install the package<\/li>\n<li>During the start of the installation process it will show links from where some dependencies will have to be downloaded<br \/>\n<a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2017\/07\/MQTT-Server-Setup-Windows-10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-547\" src=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2017\/07\/MQTT-Server-Setup-Windows-10.png\" alt=\"\" width=\"501\" height=\"389\" srcset=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2017\/07\/MQTT-Server-Setup-Windows-10.png 501w, https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2017\/07\/MQTT-Server-Setup-Windows-10-300x233.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><\/li>\n<li>Copy\/Open the links<\/li>\n<li>Once the installation finishes go to the websites opened in the previous step<\/li>\n<li>Download the <em>OpenSSL<\/em> installer and the <span style=\"color: #800080;\"><em>pthreadVC2.dll<\/em><\/span> file<\/li>\n<li>Install the OpenSSL<\/li>\n<li>Copy the <span style=\"color: #800080;\"><em>pthreadVC2<\/em>.<em>dll<\/em><\/span> file to the directory where mosquitto executable has been installed. Normally <span style=\"color: #ff6600;\"><em>C:\\Program Files (x86)\\mosquitto<\/em><\/span><\/li>\n<li>Open folder where OpenSSL got installed (normally<span style=\"color: #ff6600;\"><em> C:\\OpenSSL\\<\/em><\/span>) and open the <em>lib<\/em> folder (normally <span style=\"color: #ff6600;\"><em>C:\\OpenSSL\\lib<\/em><\/span>)<\/li>\n<li>Copy <span style=\"color: #800080;\"><em>ssleay32.lib<\/em><\/span> and <span style=\"color: #800080;\"><em>libeay32.lib<\/em><\/span> into the folder where mosquitto executable has been installed.<\/li>\n<li>Please note \u2013 while copying the files Windows might ask for giving Admin permission. Go ahead.<\/li>\n<li>At this point Mosquitto should be ready to run&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/li>\n<li>Now <strong>testing<\/strong> mosquitto<\/li>\n<li>Open a Command Prompt<\/li>\n<li>Goto the folder where mosquitto is installed<\/li>\n<li>Give command <span style=\"color: #0000ff;\"><em>mosquitto.exe -v -c mosquitto.conf<\/em><\/span><\/li>\n<li>The server should now start listening on port 1883<\/li>\n<li>Now open another Command Prompt<\/li>\n<li>Give the command <span style=\"color: #0000ff;\"><em>mosquitto_sub -h localhost -t channel1\/data1<\/em><\/span><\/li>\n<li>Open a third Command Prompt and give the command <span style=\"color: #0000ff;\">m<em>osquitto_pub -h localhost -t channel1\/data1 -m &#8220;test data&#8221;<\/em> <\/span><\/li>\n<li>In the command prompt where we used <em>mosquitto_sub <\/em>(step 18 and 19) will show the message \u201c<span style=\"color: #333333;\">test data<\/span>\u201d sent from the third command prompt.<\/li>\n<li>Reaching this point means <em>mosquitto<\/em> is working fine&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/li>\n<li>To <strong>secure<\/strong> the transmission we can username and password authentication<\/li>\n<li>Open a command prompt with Admin privileges<\/li>\n<li>Goto the folder where Mosquitto is installed<\/li>\n<li>Create a password file (for the first time only) using the command<em> <span style=\"color: #0000ff;\">mosquitto_passwd.exe -c passfile.txt username<\/span><\/em><\/li>\n<li>It will ask for password. Give the password and confirm the password<\/li>\n<li>After this point further users can be added using the below command <em><span style=\"color: #0000ff;\">mosquitto_passwd.exe -b passfile.txt username password<br \/>\n<\/span><\/em><span style=\"color: #0000ff;\"><span style=\"color: #333333;\">Please note \u2013 this time we supplied the password also along with the username<\/span><\/span><\/li>\n<li>Now edit the config file (<span style=\"color: #800080;\"><em>mosquitto.conf<\/em><\/span> normally located in <span style=\"color: #ff6600;\"><em>C:\\Program Files (x86)\\mosquitto<\/em><\/span>) to enforce only authenticated data transfers<\/li>\n<li>Uncomment <span style=\"color: #339966;\"><em>allow_anonymous<\/em><\/span> and set it <span style=\"color: #339966;\">false<\/span><\/li>\n<li>Uncomment <span style=\"color: #339966;\"><em>password_file<\/em><\/span> and put the password file name after it. It will look like <span style=\"color: #339966;\"><em>password_file passfile.txt<\/em><\/span><\/li>\n<li>Now onwards all sub and pub requests will have to be with username and password of a user whose details exists in the password file. Examples below\n<pre class='wp-code-highlight prettyprint'>mosquitto_pub -h localhost -t channel1\/data1 -m \"test data\" -u john -P johnpass \r\n\r\nmosquitto_sub -h localhost -t channel1\/data1 -u jane -P janepass<\/pre>\n<\/li>\n<li>Access control can be done using a acl file or using mosquitto-auth-plug (<span style=\"color: #ff6600;\"><em>https:\/\/github.com\/jpmens\/mosquitto-auth-plug<\/em><\/span>)<\/li>\n<li>There should be a <span style=\"color: #ff6600;\"><em>aclfile.example<\/em><\/span> inside your mqtt directory. If not then also no problem we will shortly see the contents of the file below.<\/li>\n<li>Create a file with any name. Here we will use <span style=\"color: #ff6600;\"><em>aclFile.txt<\/em><\/span><\/li>\n<li>In the <span style=\"color: #ff6600;\"><em>mosquitto.conf<\/em> <\/span>file uncomment <span style=\"color: #339966;\"><em>acl_file<\/em><\/span> and put the name of your acl file after that. It will look something like <span style=\"color: #339966;\"><em>acl_file aclFile.txt<\/em><\/span><\/li>\n<li>Example content of <span style=\"color: #ff6600;\">aclFile.txt<\/span> as below\n<pre class='wp-code-highlight prettyprint'> # user jane given full permission to channel1\/data1 and only read permission to channel1\/data2\r\nuser jane\r\ntopic channel1\/data1\r\ntopic read channel1\/data2\r\n\r\n# user jane given full permission to both data1 and data2 channel\r\nuser john\r\ntopic channel1\/#<\/pre>\n<\/li>\n<\/ol>\n<p>Please put in your suggestions in comment.<\/p>\n<p><em><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2017\/07\/MQTT-on-Windows.docx\">MQTT on Windows<\/a>\u00a0 &#8212; <span style=\"color: #808080;\">Download link of Word File containing the above steps. WordPress had made some filenames missing. So uploaded the original word doc.\u00a0<\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Download the Win32 installer from the below link (I couldn\u2019t successfully installed the CygWin version) https:\/\/mosquitto.org\/download\/ Once downloaded, install the package During the start of the installation process it will show links from where some dependencies will have to be downloaded Copy\/Open the links Once the installation finishes go to the websites opened in the&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/miscellaneous\/how-to-setup-mqtt-server-on-a-windows-10-desktop\/\">Continue reading <span class=\"screen-reader-text\">How to Setup MQTT Server on a Windows 10 Desktop<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,1,3],"tags":[],"class_list":["post-546","post","type-post","status-publish","format-standard","hentry","category-arduino","category-miscellaneous","category-php","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=546"}],"version-history":[{"count":4,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/546\/revisions"}],"predecessor-version":[{"id":559,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/546\/revisions\/559"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}