Android Question Android monitoring in real time Arduino port status

demasi

Active Member
Licensed User
Longtime User
Hello,

I think I´m at the right board, as my question involves Android and Arduino. Sorry if is not the right place.

I need some advice from the experts for a project.
I have an arduino connected to my wifi network, running a web server, as the example in the forum. It receive commands from android clientes, as:

http://192.168.1.101/ledON turns the port to HIGH and returns HIGH
http://192.168.1.101/ledOFF turns the port to LOW and returns LOW
http://192.168.1.101/status returns HIGH or LOW depending on port status

I read the return text in B4A by using HTTP jobs.

The problem is, I have more than one android clients connected to the same arduino.
When I turn the LED on, the button on the APP turns to RED, when off turns to GRAY.

To reflect the real status of the port/LED, I have a loop in a timer running every second and checking the status of the port, via HTTP job in B4A, changing the button´s color apropriately.

But this approach is not ok, because it generates a unuseful traffic in my network, every second, and, worst, it sometimes makes arduino freeze or be crazy. I think it´s because of the serial connection that looses data.

The question is, my B4A app, can be more than one, needs to know the status of the port when it changes, even if it was changed via web browser or another app. i.e. if my daughter turns the light on, via her app, my app will show it immediately.

One important requisite is that this wifi network is not connected to the internet, at least now, for security reasons, so, I can´t connect to any external service.

I tried to use a web server in android side, and when the port changes status, arduino call the app server informing the change. It worked, but just for one app. But I used a known app static IP. If I have more than one connected I don't know how to do.

Any idea?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
I don´t know if the Arduino is able to run a b4j server. But if then i would run a Websockets server on the arduino.
Each device itself connects to this server.

If the status changes then the server can update the new status to all connected clients (you see your daugther switched off the light) sending an Event to the connected clients...

I dont know how to do it. Don´t own an Arduino and never tried to setup a WebSockets Server. I just have in mind websockets could be a good way.

Just my 2 Cent.

Edit: Maybe get some inspiration here: https://www.b4x.com/android/forum/threads/websocketclient.66212/
 
Upvote 0

demasi

Active Member
Licensed User
Longtime User
Thank you. I was researching in the forum and I thibk what I need is a push client for arduino. I could not find any yet.
 
Upvote 0

demasi

Active Member
Licensed User
Longtime User
I am researching this now. I tried some examples for android.
As I can understand to use MQTT I need the clients, that should be the devices running my B4A app, and a broker to notificate all devices.
But which is the arduino's wifi switch role? It will run a client too? I found an example code in the forum fom arduino.
I also found a raspberry pi broker in another site, but is there a way to run a broker in an Arduino?
Thank you for your support.
 
Upvote 0
Top