Answer the question
In order to leave comments, you need to log in
Data transfer via udp from arduino to server in java?
Good day to all!
Tell me how to solve the following problem, I've been fighting for a couple of days.
For the test, I wrote a simple udp server in java (I took an example):
import java.io.*;
import java.net.*;
class UDPClient
{
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("192.168.31.157");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence = new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
char ch = temperatureC;
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ch);
Udp.endPacket();
Answer the question
In order to leave comments, you need to log in
I solved the problem: instead of Udp.write (ch) I use Udp.print (ch)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question