Android Question WifiAP + MQTT - How?

Mark Read

Well-Known Member
Licensed User
Longtime User
I have spent the last two days trying to understand MQTT as I have never used it. There are some good tutorials to be found but I am still unsure.

I need to connect an android (6.0) tablet to multiple other devices probably running B4R. I have no network to connect to and no 3G.

I think I need a Wifi Access Point + MQTT Broker for the tablet and then MQTT clients for the other devices. I have collected enough information to get the MQTT working (hopefully!) but the WifiAP has me a little stumped.

Am I right in thinking that Wifi AP = SocketServer + Socket + AsyncStreams?
 

rboeck

Well-Known Member
Licensed User
Longtime User
I dont fully understand your question, especially what 'no netwotwork to connect' means. You dont need internet connection, but a local network, where all devices can communicate to all others.
You have to use a MQTT broker, which can run on your local network. But this does not mean, that you dont need an mqtt client for all devices, which shall communicate to the others because the broker is not useable for local interaction (but here i am not sure, because i am using an internet based brokerservice).
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hey, what, "I have no network to connect to and no 3G", you need at least one of your quoted connected, or you will need wires all over the place.

As I wrote in an B4R tutorial.
"So what is MQTT?
Well the quick and dirty answer to that question is that MQTT (Message Queuing Telemetry Transport) is an ISO standard, lightweight, low-bandwidth, machine to machine, TCP/IP publish or subscribe messaging protocol which is great for controlling IoT (Internet of Things) devices from over the internet."

TCP/IP is the key here, I presume that you want to use Bluetooth if you have no network or 3g/4g etc. Well I have some bad news for you, sadly it's not going to happen without it.

Enjoy...
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Thank you for the above answers. I will try and rephrase the question.

I have no local internet, 3G/4G, LAN or wifi in the near which I can connect to. I need to create my own local internet. Bluetooth is not an option.

If my understanding is correct, theoretically I could use an ESP8266. Create a WifiAP with it and use it as a MQTT Broker. All other MQTT Clients (Arduino and android tablet) could connect to it and exchange data. This would give me a local network between Broker and clients. So far so good.

Back to my question, I don't have an ESP8266 to act as a wifi server and broker, I need to do this with the android tablet. Is this possible or have I got it all wrong?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
To tell you the truth I'm not sure why I gave you the previous answer. When I'm outside of my home I can control IoT devices via the internet, but before I started to use an external broker I had an internal broker using a really old 1st or 2nd generation HTC Desire, which didn't use the internet at all, just internal IP addresses running through my NetGear router running DD-WRT firmware. But you will need any old cheap router to do all your routing of TCP/IP packets...
  1. On this forum you will find a library called MQTTBroker, it come under B4J but it will also work on B4A, you can use this library to create either a desktop MQTT Broker app or in my case I used it to create an MQTT Broker app for Android.
  2. make sure to give your android device an static IP address.
  3. Get yourself a cheap router and set up and internal network the exact same way as if you had the internet coming into the building, but obviously without an incoming internet cable.
  4. Setup your other devices to to use the desktop or android devices as the MQTT broker.
Enjoy...
 
Last edited:
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Thank you Peter.

Point 1 is clear. I have already downloaded the MQTT files. I was basically stuck on the internal network part.

Get yourself a cheap router and set up and internal network the exact same way as if you had the internet coming into the building, but obviously without an incoming internet cable.

I didn't think of doing that, is also an idea. In post 5, I mentioned using an ESP8266 as Wifi Server (hotspot) but I'm not sure if setting a static IP is possible.

This would be easier for me as my application is a little strange. Imagine a 3D printer which is 6 meters wide and 30 meters long. The motors are controlled via Arduinos. My tablet is the controller for everything. Every part used is on the X and Y axis and has to move with the system ie. the router as well. The Z axis is fixed. Due to the harsh environment, I have to try and not use cables. That means using powerpacks everywhere.

After thought:
One advantage of your method with the Router would be that it would only need to be near my system. I have at least 50 meters line of sight without obstructions.

Regards
 
Upvote 0
Top