Data Transfer Using Wi-Fi Direct with ESP32 and Establishing Wi-Fi Direct Connection between ESP32 and Android Phone

sema11
Posts: 2
Joined: Mon Mar 18, 2024 7:08 am

Data Transfer Using Wi-Fi Direct with ESP32 and Establishing Wi-Fi Direct Connection between ESP32 and Android Phone

Postby sema11 » Mon Mar 18, 2024 7:37 am

Hello! I want to transfer data between two ESP32 devices using Wi-Fi Direct. I couldn't find definitive information about whether ESP32 supports Wi-Fi Direct feature. Below, I am doing data transfer using one slave and one master, but I can't understand if this is Wi-Fi Direct or not. Because according to this, I want to use Wi-Fi Direct between an ESP32 and an Android phone later. Is it possible for me to do this? I would be very happy if you could help. Thank you in advance.

Code: Select all

//SLAVE KODLARI
#include <ArduinoWebsockets.h>
#include <WiFi.h>
#include <SD.h> // SD kütüphanesini dahil edin
#include "SD.h"
#include "SPI.h"
#include "FS.h"

const char* ssid = "wifidirect_test";
const char* password = "12345678";

const char* websockets_server_host = "192.168.4.1";
const uint16_t websockets_server_port = 8888;

using namespace websockets;
WebsocketsClient client;

const int chipSelect = 5; // SD kartın kullanacağı pin
File dataFile;

void setup() {  

  Serial.begin(115200);
  pinMode(5,INPUT);
  digitalWrite(5,HIGH);
  Serial.setDebugOutput(true);
  Serial.println();
  // Connect to wifi
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.println("Socket Connecting");

  while(!client.connect(websockets_server_host, websockets_server_port, "/")){
    delay(500);
    Serial.print(".");
  }

  Serial.println("Socket Connected!");

  // SD kartı başlat
  if(!SD.begin(5)){        //SD kart baslatilir
  }
  if (!SD.begin(true)) {
  //Serial.println("An Error has occurred while mounting SD");
  }

  
  
}

void loop() {
  dataFile = SD.open("/data.txt"); // Okunacak dosyayı açın
  if (dataFile) {
    
    String data = dataFile.readStringUntil('\n');  // Dosyadan bir satır okuyun
    client.sendBinary(data); // Veriyi master'a gönderin
  }

  if (!dataFile.available()) {
    // Dosya sonuna gelindiğinde tekrar başa alın
    dataFile.close();
    dataFile = SD.open("/data.txt");
  }

  delay(1000); // Gönderimler arasında bekleme süresi
}


Code: Select all

//MASTER
#include <ArduinoWebsockets.h>
#include <WiFi.h>
#include <SD.h> // SD kütüphanesini dahil edin
#include "SD.h"
#include "SPI.h"
#include "FS.h"
const char* ssid = "wifidirect_test";
const char* password = "12345678";

using namespace websockets;
WebsocketsServer server;
WebsocketsClient client;


const int chipSelect = 5; // SD kartın kullanacağı pin

void setup() {
  Serial.begin(115200);
  //Connect to wifi
  WiFi.softAP(ssid, password);
  server.listen(8888);
}

void loop() {
  if(server.poll()){
    client = server.accept();
    Serial.println("Bağlantı");
  }

  if(client.available()){
    client.poll();

   uint32_t messageReceivedTime = millis();
    WebsocketsMessage msg = client.readBlocking();
    Serial.println("Mesaj uzunluğu: ");
    Serial.println(msg.length());
   
    Serial.println("Mesaj: ");
    Serial.println(msg.c_str());

      uint32_t elapsedTime = millis() - messageReceivedTime; 
  Serial.print("Mesaj alındığı süre: ");
  Serial.println(elapsedTime); 
  }
}

Who is online

Users browsing this forum: No registered users and 127 guests