{"id":1114,"date":"2017-05-04T20:19:33","date_gmt":"2017-05-05T01:19:33","guid":{"rendered":"http:\/\/lisa.rushworth.us\/?p=1114"},"modified":"2017-05-04T20:48:06","modified_gmt":"2017-05-05T01:48:06","slug":"owntracks-stuck-in-connecting-to-mqtt-when-using-websockets","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=1114","title":{"rendered":"Owntracks Stuck In &#8220;Connecting&#8221; To MQTT When Using WebSockets"},"content":{"rendered":"<p>Our home automation presence is maintained through an Android app, <a href=\"http:\/\/owntracks.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">OwnTracks<\/a>, which updates a <a href=\"https:\/\/mosquitto.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Mosquitto <\/a>server via\u00a0<a href=\"http:\/\/lisa.rushworth.us\/?p=358\" target=\"_blank\" rel=\"noopener noreferrer\">a WebSockets reverse proxy<\/a>. Mosquitto runs on a Fedora 25 server and was installed from the default RPM repository.<\/p>\n<p>Recently, we stopped receiving location updates &#8211; both of our Android clients were stuck &#8220;Connecting&#8221; to the MQTT server. Nothing appeared in the Apache access or error logs, and capturing network traffic only got a small number of packets (TCP session overhead &#8216;stuff&#8217;). Even bypassing the reverse proxy and\u00a0using the internal network to communicate directly to the Mosquitto server only created a couple of packets. Using a test client (<a href=\"http:\/\/www.hivemq.com\/demos\/websocket-client\/\">http:\/\/www.hivemq.com\/demos\/websocket-client\/<\/a>), I saw strange connection failures &#8212;\u00a0so I knew the problem was not specific to the OwnTracks client.<\/p>\n<p>It seems there was a bug in libwebsockets v2.1.1\u00a0(and possibly others) &#8212; when we updated our Fedora installation, the new libwebsockets broke our MQTT over WebSockets. Currently, the Fedora repository still contains an impacted version of libwebsockets. To resolve the issue, I built the\u00a0latest stable libwebsockets and built mosquitto against this updated library.<\/p>\n<p>Process: The first step is to remove the dnf managed packages (rpm -e libwebsockets libwebsockets-devel mosquitto). Then build libwebsockets and mosquitto.<\/p>\n<p><strong>To Build LibWebSockets:<\/strong><\/p>\n<p>wget https:\/\/github.com\/warmcat\/libwebsockets\/archive\/master.zip<br \/>\nunzip master.zip<br \/>\ncd libwebsockets-master\/<br \/>\nmkdir build<br \/>\ncd build<br \/>\ncmake ..<br \/>\nmake<br \/>\nmake install<br \/>\ncp libwebsockets.pc \/usr\/lib\/<br \/>\ncp lws_config.h \/usr\/include\/<br \/>\ncp ..\/lib\/libwebsockets.h \/usr\/include\/<br \/>\ncp .\/lib\/libwebsockets.so \/usr\/lib\/<\/p>\n<p><strong>To Build Mosquitto:<\/strong><\/p>\n<p>wget https:\/\/github.com\/eclipse\/mosquitto\/archive\/master.zip<br \/>\nunzip master.zip<br \/>\ncd mosquitto-1.4.11<br \/>\nvi config.mk # Line 68, change to &#8220;WITH_WEBSOCKETS:=yes&#8221;<br \/>\nmake<br \/>\nmake install<\/p>\n<p>Start the Mosquitto server and try again. Voila, presence works again!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our home automation presence is maintained through an Android app, OwnTracks, which updates a Mosquitto server via\u00a0a WebSockets reverse proxy. Mosquitto runs on a Fedora 25 server and was installed from the default RPM repository. Recently, we stopped receiving location updates &#8211; both of our Android clients were stuck &#8220;Connecting&#8221; to the MQTT server. Nothing &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[189,187,188],"class_list":["post-1114","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-libwebsockets","tag-mqtt","tag-owntracks"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/1114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1114"}],"version-history":[{"count":7,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/1114\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/1114\/revisions\/1121"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}