Mosquitto MQTT Server on a Raspberry Pi

To access an MQTT broker direct from the browser, you need websockets support. On a Raspberry Pi, this used to require a custom build from source. That is no longer required. You can now install direct from the mosquitto.org repository and add a simple config change. This article explains the details.

MQTT is a messaging protocol for the “Internet of Things” (IoT). It allows devices to communicate easily with minimal overheads. The Raspberry Pi of course makes an excellent low cost platform for managing IoT. Not only is it cheap to buy, it is also cheap to keep running.

To use MQTT, you need a “broker” which is simply a service running in the background. Mosquitto is one of the more popular brokers, partly because it is pretty small and therefore ideal for running on a Pi.

If you want to use MQTT from the browser however, you also need the broker to support something called “websockets” since browsers cannot directly talk using the MQTT protocol. In the past, Mosquitto didn’t have websockets compiled in by default and compiling your own version on a Pi is painful to say the least.

Thankfully, this is no longer a problem since the authors of Mosquitto now provide a repository containing ARM versions which work fine on the Pi. See mosquitto.org for the details.

Once installed from the repository, you will need to add a suitable configuration since websockets are not part of the default configuration.

To turn it on, you should add a new file to /etc/mosquitto/conf.d/ containing something like:

# See: http://mm011106.github.io/reference/mosquitto_conf.html

# Standard Listener
listener 1883
protocol mqtt
allow_anonymous false
password_file /etc/mosquitto/passwords.txt

# Websockets Listener
listener 9001
http_dir
Set the protocol to accept for this listener. Can be mqtt (the default), or websockets.
protocol websockets

Note that you can create more than one listener of the same type. You might, for example, want to create another listener that is restricted to a subset of topics so that you can allow access to that over the Internet. Perhaps you would restrict it to listing only sensor data but not control messages for your home automation project for example.

Once you have enabled websockets access to Mosquitto, you can do some interesting things directly from web pages. Get hold of MQTT.js for the browser and you can both listen to and send messages from/to the broker. Combined with a framework such as REACT allows you to, with only a few lines of code, display all the messages that arrive at your broker.

 

No Code Business Solutions in Microsoft SharePoint

Resources to show you how to create code-free business solutions in Microsoft SharePoint

It used to be that you had to be an expert Microsoft developer to create business solutions in Microsoft SharePoint but that is no longer true.

There are many ways for users and power users to create incredible solutions with no coding at all.

Here are two resources that show you how:

Cloudflare Now Active

After the recent high-profile vulnerabilities, I decided to turn on the free version of CloudFlare for this domain.

CloudFlare provides a reverse proxy service that sits in front of your domain. It will serve content where it can on your behalf (caching), optimise content where it can (e.g. minimising JavaScript, HTML, CSS, etc.). But even more important from my perspective is their ability to protect against a number of vulnerabilities.

The most obvious protection – because this is where CloudFlare started – is DDOS protection. DDOS is a way of throwing very large numbers of requests at your domain, preventing legitimate access. But CloudFlare also now provide protection against other threats and it is interesting to look at the dashboard and seeing a bunch of threats being filtered out every few days.

A recent add-on, especially to the free service, is the ability for CloudFlare to provide SSL security for free. This means that your whole site can present as HTTPS (encrypted HTTP) & you can even enforce this so that visitors cannot connect without encryption. This is easily done without the hassle normally associated with creating and maintaining SSL security.

Kudos to CloudFlare for providing this excellent service and for providing a useful free version. I’m happy to recommend it to everyone who runs a web site or service.

Outlook 2013 URL Protocol Handler

Outlook has a custom URL protocol that allows interaction with different elements such as folders, mail and calendar items and contacts, Since Outlook 2007, this has been restricted for use only within Outlook itself but there are some tremendous opportunities for use from simple web systems. This post explains how to turn it on, even for Outlook 2013 (Office 365 version). It also gives pointers to other articles on how to use the protocol.

One of the nice features about older versions of Microsoft Outlook was that it had a set of URL Protocol Handlers (like outlook:inbox) defined that could be used system wide to trigger actions in Outlook such as opening a folder, creating or editing an item.

Unfortunately, along the way, these got gradually toned down so that they only worked from within Outlook itself.

This can still be useful. I’m not sure how many people realise that you can create “folders” in your Outlook mailbox. Choose Properties .../Home Page and set a URL – maybe your blog or Intranet. Now when you click on the folder, you will see the web page instead of a set of mail items or whatever.

When using this feature to do some more clever stuff such as creating To Do lists from incoming mail, you might choose to use a dynamic web system to handle the list. CouchDB or Node.JS are lightweight web systems that come to mind.

Then you might find yourself wishing that you could create links in your To Do system back to the original email in Outlook. Well you can! Sort of.

It turns out that, although the external use of the Outlook: protocol hasn’t been available since Outlook 2003, it can still be turned on, even in Outlook 2013. There is a useful article on the TeamScope web site that shows you how to turn on the outlook: protocol system-wide.

One minor wrinkle though if you use Office from an Office 365 subscription – the location for Microsoft Office applications is different! You will find them at: C:\Program Files\Microsoft Office 15\root\office15.

Here then is the registry code that you need to enable the protocol:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\outlook]
"URL Protocol"=""
@="URL:Outlook Folders"

[HKEY_CLASSES_ROOT\outlook\DefaultIcon]
@="\"C:\\Program Files\\Microsoft Office 15\\root\\office15\\OUTLOOK.EXE\""

[HKEY_CLASSES_ROOT\outlook\shell]
@="open"

[HKEY_CLASSES_ROOT\outlook\shell\open]
@=""

[HKEY_CLASSES_ROOT\outlook\shell\open\command]
@="\"C:\\Program Files\\Microsoft Office 15\\root\\office15\\OUTLOOK.EXE\" /select \"%1\""

Simply save this into a .reg file and open it to install the changes.

Now you can use the outlook: protocol anywhere on the system, great for dynamic web systems.

One minor word of warning though – there are dangers! Don’t open links unless you know what they are, where they go and what they do!

To find out how to use the Outlook protocol handler, try one of the following articles:

One final note. I’m now looking to create some tools that link between Outlook and CouchDB. CouchDB provides a very lightweight NOSQL database that uses JSON and JavaScript to great effect. I’m already using it to track statistics on incoming/outgoing emails, linking the web interface back to Outlook via the home page method mentioned at the start. I’m going to have a go at creating a task monitor too if I get the time. I am currently reading only around a quarter of the emails in my work inbox and I really need some tools to improve the situation. Food for some more blog posts hopefully.

Site updated – Faster and better!

The upgrade of this blog from WordPress 3.3 to 3.4 on Dreamhost didn’t go as smoothly as planned. In fact it failed fairly spectacularly – unable to complete the required database upgrade.

However, many clouds have silver linings. In this case it meant that I brought forward my plans to ditch the horribly slow hosting provided by Dreamhost in the USA and switch over to the new VPS provided by BHost in the UK.

If you have had the chance to compare the two sites, you’ll know that it now runs a lot faster. It will improve again when I do some tweaking. I can now use a proper opcode cache for PHP, something that Dreamhost wasn’t able to provide.

I’ll be doing further optimisations now that I have full control, I should be able to do away with a whole load of WordPress plugins.

WordPress tweak to manage posts admin, filter and show custom field

This tweak will change the “All Posts” page in the administration section of a WordPress site.

It adds the ability to filter the post list based on a custom field that has been used in any of the posts at any time. Continue reading “WordPress tweak to manage posts admin, filter and show custom field”

Make the WordPress visual editor content look more like the finished output

Content in the visual post editor (TinyMCE) in WordPress doesn’t look that much like the finished article by default. Thankfully WordPress includes a style sheet that we can use to make things better. Continue reading “Make the WordPress visual editor content look more like the finished output”

Enterprise System Design and Accessibility

Most web designers are well aware of the need to design with accessibility in mind and that this is a legal requirement in many countries.

Not so many IT architects and designers who deal with internal, enterprise systems are aware, though, that these laws and requirements also apply to internal systems.

Recently I’ve yet again seen a number of dreadfully designed user interfaces (UI) for enterprise systems that most certainly don’t meet usability standards let alone accessibility standards! Continue reading “Enterprise System Design and Accessibility”

Diigo Bookmarks 05/12/2011

  • “Jash is a DHTML-based window that gives you command-line JavaScript access to the current browser window. With this console you can quickly debug scripts, manipulate the DOM, view the current page’s objects, functions, and variables, execute arbitrary Javascript, enter new CSS (in IE, Firefox, Opera, and Safari), and much more.” – A useful tool to execute JavaScript, make live (temporary) CSS changes to a page, discover the page structure, etc. for developers. Written totally in JavaScript so can be used on any platform with any browser. Include in your own pages for debugging or load via a bookmarklet to run on any page.

    tags: javascript programming development bookmarklet

    • Jash is a DHTML-based window that gives you command-line JavaScript access to the current browser window. With this console you can quickly debug scripts, manipulate the DOM, view the current page’s objects, functions, and variables, trace the execution stack, execute arbitrary Javascript, enter new CSS (in IE or Firefox!), and much more. – post by yc c

Posted from Diigo. The rest of my favorite links are here.

Bug in WordPress 3.0 Custom Post Types

Well this one threw me!

I was trying out the new custom post types in WordPress 3.0 RC1 and could not work out why mine wasn’t working even when I copied an example from the web and only changed a few things.

It turns out that there is a limitation in the naming of post types – they cannot have a name longer than 20 characters!

If you use more than 20 characters, the “Publish” button becomes “Submit for Review” and if you submit, you get the dreaded:

Are you sure you want to do this?
Please try again.

error.