{"id":7967,"date":"2015-02-16T01:11:20","date_gmt":"2015-02-15T23:11:20","guid":{"rendered":"http:\/\/lukse.lt\/uzrasai\/?p=7967"},"modified":"2015-02-16T01:14:46","modified_gmt":"2015-02-15T23:14:46","slug":"internet-of-things-messaging-mqtt-2-install-python-clients-on-pc-carambola-rpi","status":"publish","type":"post","link":"https:\/\/lukse.lt\/uzrasai\/2015-02-internet-of-things-messaging-mqtt-2-install-python-clients-on-pc-carambola-rpi\/","title":{"rendered":"Internet of Things messaging MQTT 2: Install Python Clients on PC, Carambola, RPI,&#8230;"},"content":{"rendered":"<div style=\"text-align: justify;\" align=\"center\"><a href=\"http:\/\/lukse.lt\/uzrasai\/2015-02-internet-of-things-messaging-mqtt-2-install-python-clients-on-pc-carambola-rpi\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-7994 size-full\" src=\"http:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2015\/02\/mqttorg.png\" alt=\"mqttorg\" width=\"230\" height=\"56\" \/><\/a>MQTT can be used on various platforms. When we have server up and running, I will provide guides how to install clients on various platforms.<\/div>\n<div align=\"center\"><!--more--><\/div>\n<h2>Installing MQTT clients<\/h2>\n<h3>Linux<\/h3>\n<pre class=\"theme:undefined toolbar:2 nums:false plain:false popup:false lang:vim decode:true\">apt-get update\r\napt-get install openssl libssl-dev python<\/pre>\n<pre class=\"theme:undefined toolbar:2 nums:false plain:false popup:false lang:vim decode:true\">cd \/tmp\/\r\nwget http:\/\/git.eclipse.org\/c\/paho\/org.eclipse.paho.mqtt.python.git\/snapshot\/org.eclipse.paho.mqtt.python-1.1.tar.gz\r\ntar xzf org.eclipse.paho.mqtt.python-1.1.tar.gz\r\ncd org.eclipse.paho.mqtt.python-1.1\r\npython setup.py install<\/pre>\n<h3>Windows<\/h3>\n<ul>\n<li><a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/www.python.org\/downloads\/release\/python-279\/');\"  href=\"https:\/\/www.python.org\/downloads\/release\/python-279\/\">Install Python<\/a><\/li>\n<li>Download http:\/\/git.eclipse.org\/c\/paho\/org.eclipse.paho.mqtt.python.git\/snapshot\/org.eclipse.paho.mqtt.python-1.1.tar.gz (please not, that there might be newer version available)<\/li>\n<li>Unzip, go to folder where setup.py is located and type<\/li>\n<\/ul>\n<pre class=\"theme:undefined toolbar:2 nums:false plain:false popup:false lang:vim decode:true\">python setup.py install<\/pre>\n<h3>Carambola2<\/h3>\n<div id=\"attachment_8024\" style=\"width: 291px\" class=\"wp-caption aligncenter\"><a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/www.8devices.com\/carambola-2');\"  href=\"http:\/\/www.8devices.com\/carambola-2\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8024\" class=\"wp-image-8024 size-full\" src=\"http:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2015\/02\/carambola2.jpg\" alt=\"carambola2\" width=\"281\" height=\"210\" \/><\/a><p id=\"caption-attachment-8024\" class=\"wp-caption-text\">Carambola 2<\/p><\/div>\n<p style=\"text-align: justify;\"><a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/www.8devices.com\/carambola-2');\"  href=\"http:\/\/www.8devices.com\/carambola-2\">Carambola<\/a> from <a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/www.8devices.com\/');\"  href=\"http:\/\/www.8devices.com\/\">8devices<\/a> has huge advantage when used as smart sensor or local sensor concentrator &#8211; it has low power consumption, integrated high power WiFi and LAN connections. Also features some GPIO pins and lot of digital sensors can be used directly.<\/p>\n<pre class=\"theme:undefined toolbar:2 nums:false plain:false popup:false lang:vim decode:true\">opkg install python python-openssl pyserial<\/pre>\n<pre class=\"theme:undefined toolbar:2 nums:false plain:false popup:false lang:vim decode:true\">cd \/tmp\/\r\nwget http:\/\/git.eclipse.org\/c\/paho\/org.eclipse.paho.mqtt.python.git\/snapshot\/org.eclipse.paho.mqtt.python-1.1.tar.gz\r\ntar xzf org.eclipse.paho.mqtt.python-1.1.tar.gz\r\ncd org.eclipse.paho.mqtt.python-1.1\r\npython setup.py install<\/pre>\n<p style=\"text-align: justify;\">Carambola can be used not only as paho client but also whole mosquitto broker can be installed. It should be enough for house or small office. For OpenWrt mosquitto sources see on <a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/github.com\/remakeelectric\/owrt_pub_feeds\/tree\/master\/mosquitto');\"  href=\"https:\/\/github.com\/remakeelectric\/owrt_pub_feeds\/tree\/master\/mosquitto\">mosquitto web page<\/a>.<\/p>\n<h3 style=\"text-align: justify;\">Raspberry Pi<\/h3>\n<div id=\"attachment_7574\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a onclick=\"javascript:pageTracker._trackPageview('\/downloads\/uzrasai\/wp-content\/uploads\/2014\/08\/rsz_b-.jpg');\"  href=\"http:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2014\/08\/rsz_b-.jpg\" rel=\"lightbox[7967]\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-7574\" class=\"wp-image-7574 size-medium\" src=\"http:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2014\/08\/rsz_b--400x269.jpg\" alt=\"rsz_b-\" width=\"400\" height=\"269\" srcset=\"https:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2014\/08\/rsz_b--400x269.jpg 400w, https:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2014\/08\/rsz_b--1024x690.jpg 1024w, https:\/\/lukse.lt\/uzrasai\/wp-content\/uploads\/2014\/08\/rsz_b-.jpg 1527w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><p id=\"caption-attachment-7574\" class=\"wp-caption-text\">Raspberry Pi<\/p><\/div>\n<p style=\"text-align: justify;\">I have tested only Ubuntu RPi package, so installation process is the same like Linux. It has some advantage over Carambola, when bigger processing power and storage is needed. It should be better used as MQTT broker. Local broker running on <a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/www.raspberrypi.org\/');\"  href=\"http:\/\/www.raspberrypi.org\/\">Raspberry Pi<\/a> can be very handy and compact IoT gateway machine, especially when fitted <a href=\"http:\/\/lukse.lt\/uzrasai\/2014-10-raspberry-pi-b-case-is-now-available\/\">aluminium case<\/a> I designed some time ago.<\/p>\n<h2>Some usage examples<\/h2>\n<p>Copy ca.crt certificate from <a href=\"http:\/\/lukse.lt\/uzrasai\/2015-02-internet-of-things-messaging-mqtt-1-installing-mosquitto-server\/\">mosquitto server installation<\/a> to fresh directory or add a path to ca.crt file.<\/p>\n<p>1. Elementary subscribe code snippet. \u00a0This code snippet will subscribe topic test and will messages to screen. Easy!<\/p>\n<pre class=\"lang:python decode:true\">import paho.mqtt.client as paho\r\n\r\ndef on_message(clnt, userdata, msg):\r\n\tprint(msg.topic+\" \"+str(msg.payload))\r\n\r\nmqttc = paho.Client()\r\nmqttc.on_message = on_message\r\nmqttc.tls_set(\"ca.crt\")\r\nmqttc.connect(\"127.0.0.1\", 8883)\r\nmqttc.subscribe(\"test\/#\")\r\nmqttc.loop_forever()<\/pre>\n<p>\u00a02. Complementary example for publishing message on topic<\/p>\n<pre class=\"lang:python decode:true \">import paho.mqtt.client as paho\r\n\r\nmqttc = paho.Client()\r\nmqttc.tls_set(\"ca.crt\")\r\nmqttc.connect(\"127.0.0.1\", 8883)\r\nmqttc.publish(\"test\/temperature\", '22.5', 0)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MQTT can be used on various platforms. When we have server up and running, I will provide guides how to install clients on various platforms.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-7967","post","type-post","status-publish","format-standard","hentry","category-uzrasai"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2rU5c-24v","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/posts\/7967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/comments?post=7967"}],"version-history":[{"count":24,"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/posts\/7967\/revisions"}],"predecessor-version":[{"id":8037,"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/posts\/7967\/revisions\/8037"}],"wp:attachment":[{"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/media?parent=7967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/categories?post=7967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lukse.lt\/uzrasai\/wp-json\/wp\/v2\/tags?post=7967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}