Android Question Problems receiving data via Wi-Fi on Android 10 devices.

PierPaduan

Active Member
Licensed User
Longtime User
Hi.
I have an app that connects to a Wi-Fi module (RN171XVW-I/RM) set as AP without access to internet.
The module send small data packets to the app every 4s and the app receive and save those data.

The connection between app and module is made manually going in the Wi-Fi Settings of the phone and choosing the SSID of the specific module you want to connect to.
The app exchange data using a Socket.

B4X:
Dim Socket1 As Socket
The Socket is initialized and connected to the IP of the AP.
B4X:
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.1", 2000, 10000)
During the Socket1_Connected event an Async Stream is initialized.
B4X:
AStream.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStream")
The data packets are received periodically in the Sub AStream_NewData.

No problems up to Android 9, but if the app runs on Android 10 devices (tested on: Samsung Tab A and Motorola ONE ZOOM), the AStream_NewData events are periodical only for the first packets. After those the events begin to arrive not periodically. Sometimes they stops for a lot of seconds and after that some events arrives in less than one second. Sometimes they stops arriving at all, but the Wi-Fi module still continue to send the packets periodically.

I'm using:
B4A v.10.7
javac.exe: "jdk-11.0.1\bin\javac.exe"
android.jar: "commandlinetools-win-6609375_latest\platforms\android-30\android.jar"
Manifest: targetSdkVersion="29"

Thanks a Lot to everyone who can help me to fix this problem.
 

JohnC

Expert
Licensed User
Longtime User
Android 10 has more aggressive power savings.

1) Make sure you configure (in the tablets settings) your app (that is running on the A10 tablet) to "Not Be restricted, and allowed to run in background", and also to "Do Not Optimize Battery"
2) Make sure your app is using Wakelock to keep the device from going to sleep.
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User

Hi JohnC,
I've tested your proposal, sorry but I didn't get a better communication between Wi-Fi Module and App on Android 10. The problem remains the same.
Thanks a Lot anyway for your help.
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@PierPaduan
Look at this simple example, test it out on your devices to see if you get the same issues.

 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Hi Peter.
I've tested your Tic Tac Toe example on two devices, one with Android 10 and another with Android 9. Both connected to my domestic Wi-Fi network.
The communication between this two devices seems to be Ok. During the test they didn't loose data. Anyway your example use UDPSocket. In my app I use Websocket and Async Stream to communicate with the RN171. These two situations seems to me very different. I still don't have idea on how to fix my problem with Android 10.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
These two situations seems to me very different. I still don't have idea on how to fix my problem with Android 10.
I was hoping that you could adapt your code, but if not then hmm, have you tried using a partial lock?

In most cases I use AStream_NewData for commutations between multiple devices including network EPoS printers, ESP/Arxuino desktops etc.

I've never had any issues with communications, even with the current Android 11, but I do know that some cheaper Chinese brand devices can cause huge issues.

Anyway
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Sorry, I cannot adapt your code.
My app at the moment use KeepAlive. The communication problem appears with my app in foreground, screen ON and with KeepAlive(True). PartialLock is to prevent the CPU from sleeping when the screen is OFF, isn't it?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…