We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, in my project, arduino sends two byte data by osc protocol. In android side, mobile phone get them via bluetooth (ketai-osc) and send to other PC by osc meessage as gateway. Arduino sends very fast but android side lost data and set zero "0" value of float value1 and value2.
Where is my fault? why variables (value1,value2) get 0?
Android Code: `import android.content.Intent; import android.os.Bundle;
import ketai.net.bluetooth.*; import ketai.ui.*; import ketai.net.*; import oscP5.*; import netP5.*;
OscP5 oscP5; NetAddressList myNetAddressList = new NetAddressList(); int myListeningPort = 32000; int myBroadcastPort = 12000; String myConnectPattern = "/server/connect"; String myDisconnectPattern = "/server/disconnect";
KetaiBluetooth bt; String info = ""; KetaiList klist; boolean isConfiguring = true; String UIText; float value1, value2; ArrayList names; String aktar = "Gelen: ";
int xPos = 1;
float height_old = 0;
float height_new = 0;
int say = 0;
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); bt = new KetaiBluetooth(this); }
void onActivityResult(int requestCode, int resultCode, Intent data) { bt.onActivityResult(requestCode, resultCode, data); }
void setup() {
background(0);
oscP5 = new OscP5(this, myListeningPort);
bt.start();
stroke(255); fill(0xff); textSize(32);
if (bt.getDiscoveredDeviceNames().size() > 0) klist = new KetaiList(this, bt.getDiscoveredDeviceNames()); else if (bt.getPairedDeviceNames().size() > 0) klist = new KetaiList(this, bt.getPairedDeviceNames());
bt.discoverDevices();
xPos = (width/4)+1;
height_old = (height/2)-5;
stroke(0,0xff,0xff);
strokeWeight(5);
line(((width/4)-3),0,((width/4)-3),height);
line(0,(height/2),width,(height/2));
stroke(0xff, 0, 0); strokeWeight(2);
}
void draw() {
background(0);
value1 = map(value1, 0, 1023, 0, (height/2)-5); height_new = (height/2)-5 - value1; stroke(0); line(xPos,0,xPos,(height/2)-5); stroke(0xff, 0, 0); line(xPos - 1, height_old, xPos, height_new); height_old = height_new;
if (xPos >= width) { xPos = width/4; } else { xPos=xPos + 2; } }
void onBluetoothDataEvent(String who, byte[] data) { KetaiOSCMessage m = new KetaiOSCMessage(data); OscMessage myOscMessage = new OscMessage("");
if (m.isValid()) {
if (m.checkAddrPattern("/sti"))
{
if (m.checkTypetag("ii"))
{
value1= m.get(0).intValue();
value2 = m.get(1).intValue();
println("Gelen: "+value1+","+value2);
myOscMessage.add(value1);
myOscMessage.add(value2);
oscP5.send(myOscMessage, myNetAddressList);
}
}
} }
void onKetaiListSelection(KetaiList klist) { String selection = klist.getSelection(); bt.connectToDeviceByName(selection);
klist = null; }
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.addrPattern().equals(myConnectPattern)) { connect(theOscMessage.netAddress().address()); } else if (theOscMessage.addrPattern().equals(myDisconnectPattern)) { disconnect(theOscMessage.netAddress().address()); } else { oscP5.send(theOscMessage, myNetAddressList); } }
private void connect(String theIPaddress) { if (!myNetAddressList.contains(theIPaddress, myBroadcastPort)) { myNetAddressList.add(new NetAddress(theIPaddress, myBroadcastPort)); } }
private void disconnect(String theIPaddress) { if (myNetAddressList.contains(theIPaddress, myBroadcastPort)) { myNetAddressList.remove(theIPaddress, myBroadcastPort); } }`
Arduino code: `uint8_t buf[20]; char gelenveri = 0; int val1=512 , val2;
void setup() {
Serial.begin(9600);
Serial1.begin(115200);
pinMode(13,OUTPUT);
buf[0] = 47; // /
buf[1] = 115; // s
buf[2] = 116; // t
buf[3] = 105; // i
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
buf[8] = 44; // ,
buf[9] = 105; // i
buf[10] = 105;
buf[11] = 0;
buf[12] = 0; // ilk veri byte3
buf[13] = 0; // ilk veri byte2
buf[14] = 0; // ilk veri byte1
buf[15] = 0; // ilk veri byte0
buf[16] = 0; // ikinci veri byte3
buf[17] = 0; // ikinci veri byte2
buf[18] = 0; // ikinci veri byte1
buf[19] = 0; // ikinci veri byte0
}
void loop() {
val1 = analogRead(A0);
val2 = analogRead(A1);
buf[14] = val1>>8;
buf[15] = val1%256;
buf[18] = val2>>8;
buf[19] = val2%256;
Serial1.write(buf, sizeof(buf));
delay(50);
}`