android


TCP Comunication between a WiFi Module and Android App


I need to implement a TCP comunication between the SPWF01SA Wifi-Module (from ST Microelectronics) and an Android App. For the Wifi-Module firmware i'm using the X-Cube-WIFI Middleware library as a Server Socket, while in Android i have an AsyncTask as a Client Socket. The wifi module is controlled by the stm32f103 micro(using an I2C interface) and they are both connected to an access point. Here is the Android Client Socket code for the initialization/socket-read and socket-write:
#Override
protected Boolean doInBackground(Void... params) { //This runs on a different thread
boolean result = false;
try {
Log.i("AsyncTask", "doInBackground: Creating socket");
//Get a List of IPs that have a the desired port opened
SocketAddress sockaddr = new InetSocketAddress(MY_IP, PORT);
nsocket = new Socket();
nsocket.connect(sockaddr, 5000); //10 second connection timeout
if (nsocket.isConnected()) {
nsocket.setSendBufferSize(250);
nis = nsocket.getInputStream();
nos = nsocket.getOutputStream();
Log.i("AsyncTask", "doInBackground: Socket created, streams assigned");
Log.i("AsyncTask", "doInBackground: Waiting for inital data...");
byte[] buffer = new byte[4096];
int read = nis.read(buffer, 0, 4096); //This is blocking
publishType = PUBLISH_READ;
while(read != -1){
byte[] tempdata = new byte[read];
System.arraycopy(buffer, 0, tempdata, 0, read);
publishProgress(tempdata);
Log.i("AsyncTask", "doInBackground: Got some data");
read = nis.read(buffer, 0, 4096); //This is blocking
}
}
} catch (IOException e) {
e.printStackTrace();
Log.i("AsyncTask", "doInBackground: IOException");
result = true;
} catch (Exception e) {
e.printStackTrace();
Log.i("AsyncTask", "doInBackground: Exception");
result = true;
} finally {
try {
nis.close();
nos.close();
nsocket.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
Log.i("AsyncTask", "doInBackground: Finished");
}
return result;
}
public boolean sendDataToNetwork(final String cmd)
{
if (nsocket.isConnected())
{
Log.i("AsyncTask", "SendDataToNetwork: Writing received message to socket");
new Thread(new Runnable()
{
public void run()
{
try
{
nos.write(cmd.getBytes());
}
catch (Exception e)
{
e.printStackTrace();
Log.i("AsyncTask", "SendDataToNetwork: Message send failed. Caught an exception");
}
}
}).start();
return true;
}
Log.i("AsyncTask", "SendDataToNetwork: Cannot send message. Socket is closed");
return false;
}
For small size socket write(From Android to the module) everything works, the problem rises when i need to send more than 512bytes (witch is the wifi module rx buffer). If i send more than that to the wifi module, its RX buffer goes on overflow. I thought, that the line nsocket.setSendBufferSize(250) would make the trick, but doesn't make any difference. How can i stream to the wifi module large amount of data, if the latter has a small receiver buffer?
I'm new to TCP implementations, thank you for your time.
Other info:
The WiFi Module is controlled through the I2C interface by the STM32F103RB microcontroller, and the Middlware library is provided directly by ST(I have posted the link at the beginging).
After debbuging the software on the micro that comunicates with the wifi module, i saw that there are two malfunctions that occur ramdomply:
either the I2C Rx buffer overflows
or while it reads the rx buffer it can miss some I2C commands from the wifi modules, wich serves to read the current pending packet on the i2c rx buffer;
I2C speed between wifi-module and micro is set at 460800kbps.
Either of two, the problem seems to be that the TCP stream from android is too fast. Here are some specifications for the wifi module communciation(Provided by the STM team):
Wifi Module buffer size is 1Kb(same on the micro);
For TCP, the MSS (maximum segment size) is equal to 730B (fixed in the lwip stack options). So, both for TX and for RX, this is the max segment transmittable or receivable by the module.
ST Microelectronics affirm that by spliting the data in 100B packets, they reached 60kB/s.
How can i slow down the stream from the Android App, and fix an MSS less or equal to 730B?

Related Links

How does iOS compute a scrollbar's thumb's position and extent?
How can I change the touch effect color of the ActionBar in Android 3.0 and higher
How can i reach getResources() and Context except Activity class?
How to perform a similar operation as AffineTransform.transform on Android?
Scrolling view during putting text i EditText
java.lang.StackOverflowError in android 4.0 and not in android 3.0
Draw multiple rectangles on button click on the same canvas in android
I'm struggling to find helpful, clear resources for OpenCV
android app invoking google map with car,public,walking controls
Clues about reason for dropping into Debug mode seem convoluted
Changing the color of over scroll in scrollview in android
Android: TabActivity deprecated using Fragment instead
how to customize audio recording quality in android?
MultiPoint Bluetooth Connection
easier way of doing both portrait and landscape in one xml file? in android
lock canvas fail when using MediaPlayer with Surfaceview

Categories

HOME
facebook-oauth
paraview
string
flex
can
opendj
spring-data-mongodb
entity-framework-core
soa
3d-reconstruction
polling
opengl-3
title
rcloud
pega
cmdb
xcodebuild
php-5.6
libc
renjin
template-engine
google-data-studio
mapstruct
apache2.4
libigl
postscript
inno-download-plugin
mount
froala
windows-server-2003
winexe
exchangewebservices
twiml
sqsh
nsurl
cognos-bi
git-squash
getpixel
servicestack-text
watchman
zoomify
git-rewrite-history
css-position
datacachefactory
x-ray
zenhub
payara-micro
custom-font
static-cast
backbone-collections
edit
excel-dna
check-mk
rmongo
gets
adafruit
jboss-tools
delta
http-status-code-401
findfirst
fiware-monitoring
ocra
linked-tables
alloy-ui
ms-access-2000
node-serialport
qtwebengine
infosphere-spl
execve
packet-sniffers
teaspoon
machine-instruction
ios8-extension
cfcache
multiautocompletetextview
qscrollarea
ie8-compatibility-mode
model-driven-development
ebay-lms
rolify
flex++
scmmanager
cascadingdropdown
mysql-error-2013
apache-abdera
preload
argouml
garbage
usertype
ikimagebrowserview
expression-blend-4
screen-size
mbeans
clrstoredprocedure
unattended-processing
blender-2.49

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App