Hi all,
I’m using an Arduino with a USB hostshield (sparkfun) that is connected to a Android Phone. When i send data from the smartphone to the arduino then there is no problem. But when i send data from the arduino to the Android smartphone then the data is recieved ( i get a message that the handler is triggerd) but the app crashes after a few cycles. I use de Adb library form Microbridge.
The data that is send from the arduino is as uint16_t with the number 800, this happens in the following loop:
void setup()
{
Serial.begin(57600);
// Record time for sensor polling timer
lastTime = millis();
// Init the ADB subsystem.
ADB::init();
// Open an ADB stream to the phone's shell. Auto-reconnect. Use port number 4568
connection = ADB::addConnection("tcp:4568", true, adbEventHandler);
Serial.println("Ready!");
}
void loop()
{
//Check if sensor should be sampled.
if ((millis() - lastTime) > 1000)
{
int number = 800;
uint16_t data = number;
Serial.println("Before send");
connection->write(sizeof(data), (uint8_t*)&data);
Serial.println("After send");
// Update timer for sensor check
lastTime = millis();
}
// Poll the ADB subsystem.
ADB::poll();
}
The data is recieved on the Android in the handler as followd (it uses the lightwight server from Microbridge):
server.addListener(new AbstractServerListener() {
@Override
public void onReceive(com.example.communicationmodulebase.Client client, byte[] data){
Log.e(TAG, "In handler!");
if (data.length < 1){
return;
}
TextView textRecvStatus = (TextView) findViewById(R.id.RecvStatusText);
textRecvStatus.setText("In handler!");
}
});
The message: “In handler!” is shown but after a few recieves the app chrases.
Does anyone have a idea why the app crashes? I can’t read the catlog since the Android smartphone is connected to the arduino shield. As far as i know there is no way to show the catlog data( i could be wrong?).
Any suggestions and tips are welcome!