User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

[SOLVED] Can Pi zero W run MQTT?

Wed Mar 08, 2017 1:00 pm

Is it possible to run MQTT on a Pi Zero W? New to Pi, looking for solutions for my project. MQTT is a protocol? And Mosquitto is the program to operate MQTT?

I'm trying to turn on several LEDs based on button presses attached to Wemos D1 minis ESP8266 in various locations.
I want to keep the footprint minimalist which is why I chose the Pi zero W. Coming over from Arduino and still fairly new to that.

Thank you!

Edited 04/23/17 Yes, the Pi0W not only runs MQTT but does it very well! Read on...
Last edited by marine_hm on Sun Apr 23, 2017 11:15 am, edited 1 time in total.

User avatar
DougieLawson
Posts: 29359
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Can Pi zero W run MQTT?

Thu Mar 09, 2017 11:35 am

Yes.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Thu Mar 09, 2017 1:07 pm

PiZeroW works great with MQTT and the paho python library is very easy to use

The WeMosD1 is great for simple stuff but with the PiZeroW you've obviously got a whole Linux computer at your fingertips with a lot more GPIO pins

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Thu Mar 09, 2017 2:04 pm

Thank you all so much for your comments. I just purchased a Pi Zero W from Adafruit. Should be here within a week.
I'm going to try reading as much as I can to tget it up and running. Someone willing to walk me through setting up MQTT?
Here's my project. I have 5 Wemos D1 minis. Lets just call the main one "ONE" acting as a Access point, the others A, B, C and D acting as Stations. When the Button On the main (AP) ONE, tells the red LEDS on all the remote Stations to turn on or off.
Works great! Now what I want to do is add 4 leds on ONE labeled A B C D when the buttons on each remote wemos is pressed ,turns on a corresponding LED at the AP.

If I understand this right. the MQTT will act as a Broker. Each Wemos can publish and subscribe. The Main ONE will publish \led1, the remote wemos will subscribe to \led1, Then ONE will subscribe to \ledA, \ledB, \ledC, \ledD

All that said... The Pi Zero will now be the Access Point and ALL the Wemos will log into the PiZero Wifi with SSID, Password?

Thanks

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Thu Mar 09, 2017 3:11 pm

Sounds like a great little project - not had experience with turning a Pi into an access point but there are plenty of tutorials about for that.

yes you can set up a broker on the Pi and get all the others (and itself) to publish and subscribe to it

I don't know if you've done any Python work before but for this sort of task - the coding would be fairly easy to do as the paho MQTT library does all the heavy lifting :)

User avatar
DougieLawson
Posts: 29359
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Can Pi zero W run MQTT?

Thu Mar 09, 2017 4:40 pm

There's a script of commands you have to run in an LXTerminal here: http://mosquitto.org/2013/01/mosquitto- ... epository/
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Sat Mar 11, 2017 1:45 pm

More Questions.... I'm still new to this so bear with me.

1. What's the difference and which should I be using for the Pi Zero W?
Eclipse Paho - Eclipse Mosquitto

2. MQTT is an app/program run on pi or or programming/unix type protocol?

3. I don't want to have this on the internet, so no webserver.io address. Just my own little intranet if you will. So I need to establish an Access Point and Webserver on the Pi. Then running mqtt, create Clients, Publishers, URI/URLs? Am I getting it or even close?

BTW; My name is Nick

Sorry, but I am a bit excited! This is exactly what I have been needing for my project. Both the Pi Zero W and MQTT. I just hope the Wifi part can support being an Access Point. That means like acting as my router and providing an SSID, password security?

As always, Thanks!

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Sat Mar 11, 2017 2:49 pm

1. What's the difference and which should I be using for the Pi Zero W?
Eclipse Paho - Eclipse Mosquitto

2. MQTT is an app/program run on pi or or programming/unix type protocol?
MQTT is the name of the protocol - mosquitto is the name of a program that will run an MQTT broker (what would could be termed the server part of the deal)

paho is name used my some of the client libraries - the code you use to send and receive msgs from a broker - I use the Paho Python libs in all my programs but there are other libraries for other languages)

I don't want to have this on the internet, so no webserver.io address. Just my own little intranet if you will. So I need to establish an Access Point and Webserver on the Pi. Then running mqtt, create Clients, Publishers, URI/URLs? Am I getting it or even close?
I run mosquitto on my main windows PC (as its on all of the time) and all my little Pi around (and outside) the house send and receive msgs to/from it

I could just as easily run the mosquitto broker on any of my Pi but I just decided to stick with using my main computer - any computer would do the job for you

There is no need to run a webserver unless you need to.

If you do decide that you need a webserver to use to send/recieve msgs - then things get quite a bit more complicated and I'd recommend just starting off simply using a bit of Python code - let us know when you are ready to start and we can post some basic examples for you :)

So I haven't got the need to use a Pi as an access point as I already have a WiFi router in the house - but it should be possible to set up a Pi to do everything - be a WiFi access point and run a mosquitti broker at same time - I just have no experience of doing that

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Sun Mar 12, 2017 1:32 am

I found an arduino mqtt library for esp8266. This project is looking very promising. I just checked my order for the Pi zero. Apparently they are on back order but guaranteed when they arrive, 1 will be sent my way. Whoot Whoot! :D

asandford
Posts: 1601
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Can Pi zero W run MQTT?

Sun Mar 12, 2017 1:53 am

Node-Red (built in) works perfectly with GPIO and MQTT (as well as a whole raft of other things), no need to dirty your hands with python (I re-wrote my greenhouse environmental control system from a python to NR several years ago, and it's run happily ever since. NR is asynchronous and non-blocking, so you don't have multiple python programs / processes running).

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Mon Mar 13, 2017 4:08 pm

I want my project to run autonomous from our work wifi, no access to the outside world other than the Wemos D1 minis that will connect to the access point created on the Pi Zero, subscribe/publish to the MQTT to turn on/off LEDs on the remote Wemos. A silent notification process that; attention is needed and where.

Thanks. Nick

asandford
Posts: 1601
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Can Pi zero W run MQTT?

Mon Mar 13, 2017 6:14 pm

marine_hm wrote:I want my project to run autonomous from our work wifi, no access to the outside world other than the Wemos D1 minis that will connect to the access point created on the Pi Zero, subscribe/publish to the MQTT to turn on/off LEDs on the remote Wemos. A silent notification process that; attention is needed and where.

Thanks. Nick
Assuming that the Wemos can run a client, the Pi with NR and MQTT server would be trivial to set up, no code required.

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Mon Mar 13, 2017 8:42 pm

the Pi with NR and MQTT server would be trivial to set up, no code required.
Yep

For simple LED/Switch on/off type work - no need to do Python - NodeRed will handle that easily

Once you go off-piste :) then you might want to switch to Python (or write custom nodes - depends whether your happier with Python or Javascript)

At the moment I use mainly Python for my MQTT but I do utilise NodeRed with the BigTimer add-on node that works out when sunrise/sunset is so I only turn on outside lights during darkness.

That is one of the beauties about MQTT - there are very easy-peasy ways of using it and then there are easy ways of using it :)

asandford
Posts: 1601
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Can Pi zero W run MQTT?

Mon Mar 13, 2017 9:47 pm

mattmiller wrote: At the moment I use mainly Python for my MQTT but I do utilise NodeRed with the BigTimer add-on node that works out when sunrise/sunset is so I only turn on outside lights during darkness.
I use the sunrise node to control pond lights.

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Wed Mar 15, 2017 2:29 pm

Well, my Pi Zero W is listed as "Out for delivery". I'm excited. I ran into a bit of a snag. Maybe not necessary, but I tried downloading MQTT on my windows 7 laptop. NO DEAL. Missing two dll files. ssleay32.dll, some other. Should I just skip the windows version and just stick with the Pi? It should still work on my windows 7 laptop? Even tried downloading node red to play with and this is as far as I got: https://nodejs.org/en/

Downloaded the lts version. it installs but wont run due to the missing files. But I cant seem to install the dll files correctly. I think that's what the issue is.

Thank you for any assistance. Nick

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Wed Mar 15, 2017 3:03 pm

but I tried downloading MQTT on my windows 7 laptop.
Just to re-clarify - MQTT is a protocol - mosquitto is the base software that is used.

IIRC I installed mosquitto on my win10 pc using the native installer on this page
https://mosquitto.org/download/


I found getting node red to install on windows involved a lot of steps and I did end up going around the houses a few times ( i don't think the node red people use windows much!)

But just keep on trying (I can't remember what I did and I'm pretty certain 50% of was unnecessary)

asandford
Posts: 1601
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Can Pi zero W run MQTT?

Thu Mar 16, 2017 1:58 am

To install on win 10:
-install latest node 6.x binary from here
-Right click on "Node.js command promt" from start menu, and run as administator
-in the console that pops up type npm install -g --unsafe-perm node-red
-type node-red to start

Code: Select all

Your environment has been set up for using Node.js 6.10.0 (x64) and npm.

C:\Windows\System32>cd C:\Users\<your-userid>

C:\Users\<your-userid>>npm install -g --unsafe-perm node-red
npm WARN deprecated i18next-client@1.10.3: you can use npm install i18next from version 2.0.0
npm WARN deprecated node-uuid@1.4.7: use uuid module instead
C:\Users\<your-userid>\AppData\Roaming\npm\node-red -> C:\Users\<your-userid>\AppData\Roaming\npm\node_modules\node-red\red.js
C:\Users\<your-userid>\AppData\Roaming\npm\node-red-pi -> C:\Users\<your-userid>\AppData\Roaming\npm\node_modules\node-red\bin\node-red-pi
C:\Users\<your-userid>\AppData\Roaming\npm
`-- node-red@0.16.2


C:\Users\<your-userid>>node-red
16 Mar 01:40:18 - [info]

Welcome to Node-RED
===================

16 Mar 01:40:18 - [info] Node-RED version: v0.16.2
16 Mar 01:40:18 - [info] Node.js  version: v6.10.0
16 Mar 01:40:18 - [info] Windows_NT 10.0.14393 x64 LE
16 Mar 01:40:20 - [info] Loading palette nodes
16 Mar 01:40:21 - [warn] ------------------------------------------------------
16 Mar 01:40:21 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
16 Mar 01:40:21 - [warn] [tail] Not currently supported on Windows.
16 Mar 01:40:21 - [warn] ------------------------------------------------------
16 Mar 01:40:21 - [info] Settings file  : \Users\<your-userid>\.node-red\settings.js
16 Mar 01:40:21 - [info] User directory : \Users\<your-userid>\.node-red
16 Mar 01:40:21 - [info] Flows file     : \Users\<your-userid>\.node-red\flows_<your-machine-name>.json
16 Mar 01:40:21 - [info] Creating new flow file
16 Mar 01:40:21 - [info] Server now running at http://127.0.0.1:1880/
16 Mar 01:40:21 - [info] Starting flows
16 Mar 01:40:21 - [info] Started flows
`

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Thu Mar 16, 2017 4:49 pm

asandford wrote:To install on win 10:
-install latest node 6.x binary from here
-Right click on "Node.js command promt" from start menu, and run as administator
-in the console that pops up type npm install -g --unsafe-perm node-red
-type node-red to start
Thanks! That seems to be working. I think I had to paste and run it twice. I was too impatient and closed out the window before anything happened. The second time I did it and had to set the aptop down to do something and noticed it downloading and decompressing the files.

No. It seems to hang after showing an IP address, says starting flows, next line says started flow. Then nothing.

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Tue Mar 21, 2017 3:22 am

mattmiller wrote:Sounds like a great little project - not had experience with turning a Pi into an access point but there are plenty of tutorials about for that.
Matt; with MQTT, do I even need to set up an access point? Mosquitto would act as a server and the "clients" would log on via the IP address of the Raspberry Pi? Maybe I have to forget the idea that you need an SSID that says "hey I'm here", you click on it and log on with the proper credentials.

Then my Wemos would subscribe and publish through MQTT on the Pi? 192.168.0.xx:1880 or whatever

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Tue Mar 21, 2017 6:35 am

do I even need to set up an access point?
Yes if you still want this
I want my project to run autonomous from our work wifi,
mosquitto/MQTT needs a network (and since your using Wemos - a WiFi one)

I, personally, would get something working on your work WiFi 1st and then see about switching the Pi to be an own access point

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Fri Mar 24, 2017 1:03 pm

I was successfully able to get the Pi up and running. WiFi turned on, able to ssh with it. I ran into a bit of a snag. At the end of installation of mosquitto, I get this:

N: Ignoring file 'mosquitto-jessie.list.1' in directory '/etc/apt/sources.list.d /' as it has an invalid filename extension
Suggestions, help please. Is this needed to run Mosquitto?

Thanks

User avatar
DougieLawson
Posts: 29359
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Can Pi zero W run MQTT?

Fri Mar 24, 2017 2:29 pm

Files in /etc/apt/sources.list.d must end with .list as anything else won't be used by apt-get. That's useful because you can rename an *.list file to *.list~ and know that it won't be used.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

User avatar
marine_hm
Posts: 58
Joined: Tue Mar 07, 2017 4:27 pm

Re: Can Pi zero W run MQTT?

Fri Mar 24, 2017 4:58 pm

Thanks for the quick response. Can you tell me a quick command or way to just check, see if it installed correctly?
I typed "mosquitto_sub --help" and a menu came up, so, can I assume it did install and now I have to figure out how to use it.
Off to mosquitto.org for some more reading.

I found that "mosquitto -h" works too.

I saw a tutorial on node red and just tried "node-red-start". It gave me an IP address for the web browser. Low and behold, it came up. Not sure what I think of node red. It's probably very easy for someone who's used to it, but doesn't seem very intuitive for a beginner. I would probably be happier with a script page to see/control what's happening. I think that's how mosquitto works.

Dogs just got in a fight, have to run to the vet for stitches. Will check in later. Thanks all.

User avatar
DougieLawson
Posts: 29359
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Can Pi zero W run MQTT?

Fri Mar 24, 2017 9:35 pm

sudo mosquitto -v works
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

mattmiller
Posts: 1426
Joined: Thu Feb 05, 2015 11:25 pm

Re: Can Pi zero W run MQTT?

Fri Mar 24, 2017 10:35 pm

Not sure what I think of node red. It's probably very easy for someone who's used to it, but doesn't seem very intuitive for a beginner.
Its one of those things that looks incomprehensible to start with but once you start playing with it and understand the concept of a flow - the VFM in terms of power/effort is fantastic

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 21 guests