Hey guys I have an Arduino Uno with an ESP8266-01 connected to it. Now I have an Android app connected to it. There I have two variables which are passed to the ESP. The following code is my Android Studio code that sends the packet:
fun sendUDP(messageStr: String) {
// Hack Prevent crash (sending should be done using an async task)
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
try {
//Open a port to send the package
val socket = DatagramSocket()
socket.broadcast = true
val sendData = messageStr.toByteArray()
val sendPacket = DatagramPacket(sendData, sendData.size, InetAddress.getByName(mySettings.RemoteHost), mySettings.RemotePort)
socket.send(sendPacket)
} catch (e: IOException) {
// Log.e(FragmentActivity.TAG, "IOException: " + e.message)
}
}
So this app acts as the UDP client. The ESP8266-01 was set as the server. I've done this using the following commands:
AT+CWMODE=3
OK
AT+CWJAP="AP_SSID","AP_PASSWORD"
OK
AT+CIPMUX=1
OK
AT+CIPSTART=0,"UDP","192.168.0.140",4445,4445,2
0,CONNECT
OK
+IPD,0,13:test from nc
OK
AT+CIPCLOSE=0
0,CLOSED
OK
Now I don't know how I code the Arduino sketch so that I can receive and use this data. Do I need to program the ESP or just the Arduino? I tried to upload an example code to the ESP but it gave me the error that it couldn't connect. Or maybe I just need to use AT commands? I would be really happy if somebody could help me :)
Thanks