Reputation: 75
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
Upvotes: 0
Views: 597
Reputation: 1701
Just want to point out that you dont need the Arduino Uno to get the information from the ESP8266, the ESP8266 can be programmed to handle directly the variables.
Now, you will need to connect the Arduino Uno as described below in order to upload the sketch you want to use in the ESP8266:
ESP8266:--------------> Arduino:
GND -------------------------- GND
GPIO-2 -------------------------- Not connected (open)
GPIO-0 -------------------------- GND
RXD -------------------------- RX
TXD -------------------------- TX
CHPD ------------------------ 3.3V
RST -------------------------- Not connected (open) *(Read Below Instruction)
VCC -------------------------- 3.3V
Remove RST after half a second (the blue LED flashes for some millisecond).
Hit upload, the blue flashes once and then blinks till it gets uploaded.
Now you are all done.
You can follow this document for a complete guide
Upvotes: 0