Recommendations for MQTT with Arduino and Android Clients - push-notification

I am fairly new to Arduino, and for a project I want to use an UNO to push/publish notifications to an MQTT broker, then have the broker push a notification to a subscribing Android app I am developing.
I have an ESP8266 for my Arduino incoming. I've done a fair bit of research but am having some trouble piecing things together. I've read articles with the Arduino as the subscriber, or as the server, or the Android as the publisher, but none for this specific implementation. What I (think) I know so far is:
1: Since this is just a fun DIY, test.mosquitto.org would suffice as a decent free broker. So for a #define mqtt_server field, it'd be test.mosquitto.org.
2: Programmatically, I can push notifications from my Arduino to this broker via an mqtt library such as PubSubClient.
3. In Android Studio, I can use an mqtt client (Paho?) to subscribe to the topics being pushed to the broker.
My questions at this point are:
Is there anything else I would need to install on the Arduino besides PubSubClient and the library for my ESP?
I saw that on some code examples, there were 'mqtt_password' and 'mqtt_user' fields. Do all brokers generate these fields, and if so, where can I access them from test.mosquitto.org.
Are there better brokers for a job like this (that are also free) or would mosquitto be enough? I'll only be sending short messages of < 100 characters, but do some brokers limit the amount of data they receive/send?
I just need a jump start in understanding the overall architecture. As usual, any help is appreciated.

Is there anything else I would need to install on the Arduino besides
PubSubClient and the library for my ESP?
You are on the right way... if your Arduino libs are working then you can pub topics and see if the broker can deal with it (I suggest to use mqttFx as a client and subs to those topics too)
I saw that on some code examples, there were 'mqtt_password' and
'mqtt_user' fields. Do all brokers generate these fields, and if so,
where can I access them from test.mosquitto.org.
every broker can deal with anonymous clients, M2m.eclipse.org is one of those...
Are there better brokers for a job like this (that are also free) or
would mosquitto be enough? I'll only be sending short messages of <
100 characters, but do some brokers limit the amount of data they
receive/send?
yes, you can search in the web for those, I have been playing with:
HiveQM: broker.mqttdashboard.com
and
Eclipse: iot.eclipse.org
and they allow you more or lesss the same features you need for the test...
For the andoir part, Paho is a pretty good way to go...
but fisrt step fisrt, pub things with arduino and check that the broker is understanding you + that another client(mqttfx) can get the info and send you something too :)

Related

Why use mqtt server for BLE gateway?

I have a BLE temperature sensor, which should send measurements to an ESP32 via a BLE connection and my plan was that the ESP32 could send the measurements via WiFi to my database (Firebase Realtime Database). However, I have seen from a few tutorials that a mqtt server would be neccesary (see the screenshot below - link to the video: https://www.youtube.com/watch?v=PBYCG-ypvRY). Could someone please explain to me why the mqtt component is neccesary? Currently I am measuring temperatures using my ESP32 (without the BLE temperautre sensors) and sending them directly to the database, so I am confused as to why with BLE I would need a mqtt server.
Thanks for your help in advance!
You don't need MQTT. It's just one of the IoT-friendly protocol alternatives (like HTTPS, AMQP, CoAP, homebrew, etc) available to you for device-to-server communication. There are pros and cons to each one. It's up to you to choose whatever solution is relevant to your system.
If you've already implemented the Firebase HTTPS interface and it does the job, you're done.
If you are having problems, note that the Google IoT Core also prescribes MQTT (or, alternatively HTTPS) as an underlying messaging protocol - used together with the Device SDK for Embedded C. But this is for people who want to have a large-scale authentication and management solution for their devices. By all means, stick to your existing solution if it works.

Can an MQTT Client in principle publish two different topics?

Background: I'm currently drawing up a project using a simple Arduino and a GPRS module that connects with UDP protocol to a RPi configured as an MQTT client, with an online MQTT Broker.
Arduino--GPRSMod--RPIMQTTClientPubl--Broker--WebclientSubscrib
I have not done anything yet, except gathering information about the plausibility of this project and figuring out the time and effort (The GPRS Module with UDP protocol to RPi is based on somebody else's project, and I'm not sure yet how it works, I thought in theory I could just send it directly to the Broker, but not sure which protocol I'm suppsed to use) and familiarized myself with Windows Mosquitto, just to try out MQTT.
Question: Is it possible to have two (or more) different sensors connected to the Arduino (Say, US, Temp and a normal Switch) and have them all sent as three different topics to the MQTT broker through one MQTT client?
US -------|
Temp ----|--Arduino--GPRSMod--RPIMQTTClientPubl--Broker--WebclientSubscrib
Switch ---|
I have a feeling that although in theory the three different inputs at the Arduino side, can be recognized and sent as three different signals (sent at different times) to the GPRSModule, however the GPRS Module||MQTT Client, can only publish to one topic, isn't it? Then do I really have to have three different GPRSModule||MQTTClients so I can send three different topics?
Thanks in advance!
Any given MQTT client can publish to as many topics as they like. You should only need 1 GSM/GPRS module

Communication b/w two WiFi modules using Arduino Ide

Firstly, I'll just give you a brief introduction about our project... its "Speech controlled Home Automation System" where we are controlling the Home appliances by the voice or speech commands. We're successfully done with the voice recognition module. But our problem is with achieving the communication between the transmitter {where the user gives the voice command} and receiver {where the home appliances are present} through WiFi i.e. we have got 2 ESP8266 12E modules interfaced with Arduino both at the transmitter and receiver side and these two WiFi modules need to be communicated(To interchange some data sent by Arduinos).So please let us know which Arduino code need to be used at transmitter side wifi module and at Receiver side wifi module and also about the header files or additional softwares(if any)to be used.
you can achieve this by starting one of wifi modules in Access Point Mode and the other one has to be set to Station Mode in order to connect to the first one.
In case you want to add a router, just set both ESP8266 modules to Station Mode and connect them to the router.
And then transfer any data you want through AT commands of ESP8266.
Here is the refrence to them.
https://room-15.github.io/blog/2015/03/26/esp8266-at-command-reference/
If you are newbie to Esp8266 and Arduino , this will help you.
http://www.teomaragakis.com/hardware/electronics/how-to-connect-an-esp8266-to-an-arduino-uno/
Good Luck !
I worked on a similar system a year ago. I was developing a remote controlled toy. My main difference was I used the ESP8266 without an Arduino attached.
One ESP worked as a a WiFi hotspot and the other connected to it, sending messages through UDP.
For some reason, I could not get the two ESP modules to connect (I think it was a problem with the board I had), but I sent messages from my computer, and it worked out fine. I will not burden you with all of the code, but here is the GitHub link.
All that needs to happen is they will be on the same WiFi network, and then you can use the ESP8266 WiFi library to send messages between the two. Like I said above, I used UDP, which is good for high speed, with no error checking. But there is also TCP (higher up, has error checking code), or you can use the server/client part of the library to set up a full web server and read/write data to it. Without knowing what type of data, I cannot comment on what would be the best method.
As for headers, you will need WiFi.h, and if you are using UDP you will need WiFiUdp.h
You should not need any external software besides the Arduino IDE.
I taught myself from scratch for this product, using two main resources: the Arduino library reference, and the docs on the ESP8266 Arduino GitHub page

Using MQTT between Raspberry Pi, Arduino and JavaScript

A mate and I are doing a project at the moment that hosts a webpage on a raspberry pi which I would like to send a message via MQTT to the arduino which reads sensors and then sends the values back to the pi to be displayed on the web page.
I am hoping to use Mosquito on the pi as a broker and treat the arduino and the webpage as clients.
I am just having a lot of trouble working out how it all fits together.
A lot of examples I have seen use web sockets and node.js and MQTT.io and I'm just so confused..
Could someone please help me piece it all together and explain how everything fits and what it does?
Thanks in advance!
Websockets allows a web browser to open a bi-directional communication pipe to a server.
For websockets to work you need a websocket enabled mqtt broker. At the moment you have to install this seperately, some examples of what is out there are here. Mosquitto will have websockets enabled in the next version, 1.4, you can compile it if you wish.
An example of what can be done, and what I am doing atm with mqtt and websockets is;
publish temperature data to mqtt broker from an arduino.
subscribe to the topic that the arduino is publishing to and populate the data into a mysql database using python scripts.
have a live website subscribe to the topic and show the current temperature as a line graph.
We did tutorials on building applications with MQTT and websockets in the past. Slides (+ Code) can be found on Slideshare.
If you're interested in how MQTT over websockets works in detail, this blog post may help you. Also, a full example websockets/MQTT application tutorial can be found in this blog post.

Develop client library for MQTT in C

I want to develop a c client library for MQTT, to make my PIC 8 bit micro-controller to talk to an MQTT broker( say Active MQ). I am relatively new to this field. Can anyone suggest where can i start . I need to implement just CONNECT, SUBSCRIBE,UNSUBSCRIBE, PUBLISH nad DISCONNECT API's to start with.
Thanks in advance
You need to get ethernet working first, then just implement the protocol... :)
A good place to look would be the arduino client (http://knolleary.net/arduino-client-for-mqtt/) that should have solved a lot of what you need to do.
Good luck!
I'm really not sure a AMQP client would be able to run on a limited system like the AVR (but a great system tough).
You will need at least the following:
- The TCP/IP stack;
- Enough memory to hold some frames (4096 bytes or maybe smaller but not often);
If you think the arduino will handle all this, I would start from the rabbitmq-c library and strip it down.
Other option, and if the rabbitmq-c isn't small enough, and your goals are just to publish messages, take a look at STOMP and how to combine it with RabbitMQ or other AMQP. Stomp has a very small footprint and will, probably, be the best shot to give.
Cheers,
You can use XSockets.NET since you can connect any device with TCP/IP to XSockets and then talk to other devices.
It will basically work like this.
Setup a XSockets server somewhere (localhost to start with)
Connect from the Arduino to XSockets
Use XSockets publish/subscribe pattern do send/receive data between arduino and any other device connected to XSockets
Simple vide demo here: Arduino pub/sub with XSockets
If you want to mix in any other tech do it from XSockets since that wil be easier than writing stuff on the Arduino.
EDIT: Just saw that you did not say Arduino... 8-bit PIC micro-controller might be another story :) I have just connected Arduino and Netduino

Resources