String +DatagramPacket+ Android + Arduino
what I want to do is, if I use send.setOnClickListener(new OnClickListener) to send stringdata1 + stringdata1 over the DatagramSocket to an Arduino Board, but I donīt know how to convert the two Strings and send them
please help me
thanks in Advance
////////////////////////////////////////////////////////////
Code 1
////////////////////////////////////////////////////////////
Code :
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SendSlcValue.setintData();
SendSlcValue.updateArduinoValues();
;
////////////////////////////////////////////////////////////
Code 2
////////////////////////////////////////////////////////////
Code :
public class SendSlcValue {
static DatagramSocket socket;
static byte data[];
static {
data = new byte[700];
try {
socket = new DatagramSocket();
} catch (SocketException e1) {
e1.printStackTrace();
}
}
public static void updateArduinoValues() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
InetAddress serverIP = InetAddress
.getByName("255.255.255.255");
DatagramPacket out = new DatagramPacket(data, data.length,
serverIP, 50025);
socket.send(out);
} catch (IOException e) {
e.printStackTrace();
}
}
});
t.start();
}
public static void setintData(byte val_onoff) {
String stringdata1 = "0020 0020";
byte[] byteData1 = stringdata1.getBytes();
String stringdata2 = "0000 0071 0000 000c 0020 0020 0020 0020 0020 0020 0020 0020 0020 0020 0040 0040 0020 0020 0020 0020 0020 0020 0040 0020 0020 0040 0020 0ca0";
byte[] byteData2 = stringdata2.getBytes();
Re: String +DatagramPacket+ Android + Arduino
Quote:
how to convert the two Strings
Can you explain what the problem is? The byte arrays can go in a DatagramPacket for sending.
Re: String +DatagramPacket+ Android + Arduino
if I send the byteData1 instead of data I don`t see anything on the arduino Serial Monitor
but if I use this code
////////////////////
Code 1
////////////////////
Code :
public class MainActivity extends Activity {
public Button send;
public TextView tv;
public TextView etcode;
String test = new String("test");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send = (Button) findViewById(R.id.Senden);
////////////////////////////
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SendSlcValue.setintData((byte)1);
SendSlcValue.updateArduinoValues();
;
}
});
}
}
///////////////////////
code 2
///////////////////////
Code :
public class SendSlcValue {
static DatagramSocket socket;
static byte data[];
static {
data = new byte[700];
try {
socket = new DatagramSocket();
} catch (SocketException e1) {
e1.printStackTrace();
}
}
public static void updateArduinoValues() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
InetAddress serverIP = InetAddress
.getByName("255.255.255.255");
byte[] byteData = null;
DatagramPacket out = new DatagramPacket(byteData, data.length,
serverIP, 50025);
socket.send(out);
} catch (IOException e) {
e.printStackTrace();
}
}
});
t.start();
}
public static void setintData(byte intensity) {
data[5] = intensity;
}
//////////////////////
///////////////////
I see the 6 on the arduino Serial Monitor
My Problem is I don`t know how I have to connect the stringdata1 and stringdata2 with data to see anything on the Serial Monitor
Re: String +DatagramPacket+ Android + Arduino
Please edit your post and wrap your code with code tags:
[code]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.
Sorry, I don't understand the little bits of code that was posted. Too many things are not defined.