Android Question Android ESP8266 control in AP mode using UDP packets

albertduino

New Member
Hello community,

I created a network in esp8266 with arduino IDE.
The smarphone created successfully connect to your network.
I open the application and both the serial arduino but the value of packet is always 0.

ESP8266 sketch:
B4X:
/* Create a WiFi access point */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>

WiFiUDP Udp;
char packetBuffer[255];
unsigned int localPort = 8000;

/* Set these to your desired credentials. */
const char *ssid = "SERVER";
const char *password = "0123456789";
void setup()
{

  Serial.begin(115200);
  


}



void loop()
{
int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.println("Tamanyo del paquete recibido :  ");
    Serial.println(packetSize);
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len-1] = 0;
    Serial.print("Recibido(IP/Size/Data): ");
    Serial.print(Udp.remoteIP());Serial.print(" / ");
    Serial.print(packetSize);Serial.print(" / ");
    Serial.println(packetBuffer);


    Udp.beginPacket(Udp.remoteIP(),Udp.remotePort());
    Udp.write("recived: ");
    Udp.write(packetBuffer);
    Udp.write("\r\n");
    Udp.endPacket();

     }
     delay(10);
}

Client B4A :

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Esp.wifi
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

Sub process_globals
    Dim UDPSocket As UDPSocket
End Sub

Sub Globals
Private Miboton As Button
End Sub

    Sub Activity_Create(FirstTime As Boolean)
       If FirstTime Then
            'puerto 8000 por defecto
           UDPSocket1.Initialize("UDP", 0, 8000)
       End If
          Activity.LoadLayout (1)
    End Sub

Sub Miboton_Click
    Dim data() As Byte
    data = "SET1".GetBytes("UTF8")
    Packet.Initialize(data, "192.168.1.1", 7000)
    UDPSocket1.Send(Packet)
End Sub


End Sub
 
Last edited:
Top