4 Mayıs 2026 Pazartesi

Esp32 code example

Now you can set the connection password in the setup section using `uint32_t passkey = 123456;`, so that only those who know and match the password can connect.


      doc["ldr1"] = sensorValue1;

      doc["ldr2"] = String(map(analogRead(0), 0, 4095, 100, 0)) + "%";

If you want to send sensor data or information, you can easily establish an ESP32 phone connection by adding a tag like ["ldr1"] and saving it to your phone with that tag. You don't necessarily have to write ldr1; you can write dataA or data1.



        // Scenario 1: Simple On/Off (Standard Switch)

        if (value == "A") {

          digitalWrite(LED_PIN, HIGH);

          Serial.println("LED State: ON");

        }

        else if (value == "B") {

          digitalWrite(LED_PIN, LOW);

          Serial.println("LED State: OFF");

        }


Again, here you look at the tag you registered on your phone, and while it might say "A", you can enter a different tag. For example, I was only able to enter a tag with the size "aaa".


👉Google Play  It works perfectly with the app.Please support us🌟
Also check out other apps 📲.

// ------------------------------Example code -------------------------



#include <BLEDevice.h>

#include <BLEServer.h>

#include <BLEUtils.h>

#include <BLE2902.h>

#include <ArduinoJson.h>

#include <WiFi.h>


// --- BLE UUID Definitions ---

#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"

#define CHARACTERISTIC_UUID "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"


// Global Variables

BLECharacteristic *pCharacteristic;

bool deviceConnected = false;

unsigned long lastMillis = 0;


// WiFi & API Storage

String savedSSID = "";

String savedPassword = "";

String savedApiKey = "";


// Hardware Pin Definitions

int sensorPin = 0;

const int LED_PIN = 8;

const int PWM_PIN = 3;


// PWM Configuration (v3.0+ SDK Compatible)

const int freq = 5000;

const int resolution = 8;


// BLE Server Connection Callbacks

class MyServerCallbacks: public BLEServerCallbacks {

    void onConnect(BLEServer* pServer) {

      deviceConnected = true;

      Serial.println(">>> Device Connected");

    };

    void onDisconnect(BLEServer* pServer) {

      deviceConnected = false;

      Serial.println(">>> Device Disconnected");

      // Restart advertising to remain visible for authorized devices

      pServer->getAdvertising()->start(); 

    }

};


// BLE Characteristic Write Callbacks

class MyCallbacks: public BLECharacteristicCallbacks {

    void onWrite(BLECharacteristic *pCharacteristic) {

      String value = String(pCharacteristic->getValue().c_str());


      if (value.length() > 0) {

        Serial.print("Command Received: ");

        Serial.println(value);


        // Scenario 1: Simple On/Off (Standard Switch)

        if (value == "A") {

          digitalWrite(LED_PIN, HIGH);

          Serial.println("LED State: ON");

        }

        else if (value == "B") {

          digitalWrite(LED_PIN, LOW);

          Serial.println("LED State: OFF");

        }


        // Scenario 2: WiFi + API Key Setup

        // Expected Format: "WIFI:ssid:password:apikey"

        else if (value.startsWith("WIFI:")) {

          String payload = value.substring(5);


          int first = payload.indexOf(':');

          int second = payload.indexOf(':', first + 1);


          if (first == -1) {

            Serial.println("WIFI format error!");

            return;

          }


          savedSSID = payload.substring(0, first);

          savedPassword = payload.substring(first + 1, second != -1 ? second : payload.length());

          savedApiKey = second != -1 ? payload.substring(second + 1) : "";


          Serial.println("SSID: " + savedSSID);

          Serial.println("Password: " + savedPassword);

          Serial.println("API Key: " + savedApiKey);


          WiFi.begin(savedSSID.c_str(), savedPassword.c_str());

          Serial.print("Connecting to WiFi");


          int timeout = 0;

          while (WiFi.status() != WL_CONNECTED && timeout < 20) {

            delay(500);

            Serial.print(".");

            timeout++;

          }


          if (WiFi.status() == WL_CONNECTED) {

            String ip = WiFi.localIP().toString();

            Serial.println("\nWiFi Connected! IP: " + ip);

            pCharacteristic->setValue(("IP:" + ip).c_str());

            pCharacteristic->notify();

          } else {

            Serial.println("\nWiFi connection failed!");

            pCharacteristic->setValue("WIFI_FAIL");

            pCharacteristic->notify();

          }

        }


        // Scenario 3: PWM Control

        // Expected Format: "tag:value" — e.g., "ldr1:5"

        else if (value.indexOf(':') != -1) {

          int colonIndex = value.indexOf(':');

          String tag = value.substring(0, colonIndex);

          int val = value.substring(colonIndex + 1).toInt();


          if (tag == "ldr1") {

            int brightness = map(val, 0, 9, 0, 255);

            ledcWrite(PWM_PIN, brightness);

            Serial.printf("PWM Intensity set to: %d\n", brightness);

          }

        }

      }

    }

};


void setup() {

  Serial.begin(115200);

  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, HIGH);


  ledcAttach(PWM_PIN, freq, resolution);


  // Initialize BLE Device

  BLEDevice::init("ESP32-C3-FIIX");


  // --- BLE SECURITY & STATIC PASSKEY CONFIGURATION ---

  // Enable MITM (Man-in-the-middle) protection and encryption

  BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT_MITM);

  

  BLESecurity *pSecurity = new BLESecurity();

  pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND); // Save pairing bond on smartphone storage

  pSecurity->setCapability(ESP_IO_CAP_OUT);           // Triggers native OS numeric passkey prompt

  pSecurity->setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);

  

  // Set 6-digit static passkey (Change it if needed)

  uint32_t passkey = 123456; 

  esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));

  // ---------------------------------------------------


  BLEServer *pServer = BLEDevice::createServer();

  pServer->setCallbacks(new MyServerCallbacks());


  BLEService *pService = pServer->createService(SERVICE_UUID);


  // --- ENCRYPT CHARACTERISTIC ACCESS PERMISSIONS ---

  // Restrict read/write operations to authenticated/paired devices only

  pCharacteristic = pService->createCharacteristic(

                        CHARACTERISTIC_UUID,

                        BLECharacteristic::PROPERTY_READ |

                        BLECharacteristic::PROPERTY_WRITE |

                        BLECharacteristic::PROPERTY_NOTIFY |

                        BLECharacteristic::PROPERTY_WRITE_NR

                      );

  pCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED);

  // ---------------------------------------------------


  pCharacteristic->setCallbacks(new MyCallbacks());

  pCharacteristic->addDescriptor(new BLE2902());


  pService->start();

  

  // Start advertising permanently under passkey protection

  pServer->getAdvertising()->start();

  Serial.println("BLE Ready with Passkey Security (123456)...");

}


void loop() {

  // Telemetry loop for sending JSON payloads to the app

  if (deviceConnected) {

    if (millis() - lastMillis > 2000) {


      int sensorValue1 = random(100, 1024);

      int sensorValue3 = random(100, 1024);

      String mockDataStr = "123456789123456789";


      StaticJsonDocument<128> doc;

      doc["ldr1"] = sensorValue1;

      doc["ldr2"] = String(map(analogRead(0), 0, 4095, 100, 0)) + "%";

      doc["ldr3"] = sensorValue3;

      doc["ldr4"] = mockDataStr;


      if (digitalRead(LED_PIN) == HIGH) {

        doc["aa"] = "OFF";

      } else {

        doc["aa"] = "ON";

      }


      char buffer[128];

      serializeJson(doc, buffer);


      pCharacteristic->setValue(buffer);

      pCharacteristic->notify();


      Serial.print("JSON Sent to App: ");

      Serial.println(buffer);


      lastMillis = millis();

    }

  }

}





Privacy Policy for ble control

 Last Updated: May 2, 2026

reddapp ("we," "our," or "us") operates the ble control mobile application (the "Service"). This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data.

1. Information Collection and Use

We collect several different types of information for various purposes to provide and improve our Service to you.

Personal Data: While using our Service, we may ask you to provide us with certain personally identifiable information that can be used to contact or identify you ("Personal Data").

Usage Data: The app may collect information such as your device's IP address, device name, operating system version, and the time/date of your use.

Bluetooth & Local Files: This application requires access to your device’s Bluetooth to communicate with BLE devices (e.g., ESP32, BLE modules) and may require local storage access for saving your configurations.

Advertising ID: This "free" version of the app uses your device's advertising identifier to show personalized ads.

2. Third-Party Service Providers

The app uses third-party services that may collect information used to identify you. These include analytics, stability, and advertising services:

Google Play Services

AdMob: Used for displaying advertisements. AdMob may use the Advertising ID from your device to serve relevant ads. Google’s Privacy & Terms

Google Analytics for Firebase

Firebase Crashlytics

3. Advertising

We use third-party service providers to show advertisements to you to help support and maintain our Service.

AdMob by Google: Google, as a third-party vendor, uses cookies and advertising identifiers to serve ads on our Service. You may opt-out of personalized advertising by visiting your device's "Ads" settings.

4. Data Safety & Disclosure

We do not sell or share your personal data with third parties for marketing purposes. Data is only used to:

Facilitate the core functionality of the Bluetooth controller.

Show relevant advertisements via AdMob.

Analyze app performance and fix crashes.

5. Data Retention and Deletion

We retain your personal data only for as long as is necessary for the purposes set out in this Privacy Policy.

User Rights: You have the right to request the deletion of any data collected. Since we do not use a centralized user account system for this app, most data is stored locally on your device. You can clear this data by uninstalling the app or clearing the app cache. For any further data inquiries, contact us at rukosw@gmail.com.

6. Security

The security of your data is important to us, but remember that no method of transmission over the Internet is 100% secure. We strive to use commercially acceptable means to protect your Personal Data.

7. Children's Privacy

Our Service does not address anyone under the age of 13. We do not knowingly collect personally identifiable information from children under 13. If we discover that a child under 13 has provided us with personal information, we immediately delete this from our servers.

8. DIY Disclaimer

This is a "Do-It-Yourself" (DIY) application. The user assumes all responsibility for any hardware issues or accidents that may occur during the use of this software with real electronic components (relays, ESP32, BLE devices, etc.).

9. Changes to This Privacy Policy

We may update our Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on this page.

10. Contact Us

If you have any questions about this Privacy Policy, please contact us:

By email: rukosw@gmail.com

2 Mayıs 2026 Cumartesi

Privacy Policy for esp relay wifi controller free

 Last Updated: May 2, 2026

reddapp ("we," "our," or "us") operates the esp relay wifi controller free mobile application (the "Service"). This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data.

1. Information Collection and Use

We collect several different types of information for various purposes to provide and improve our Service to you.

Personal Data: While using our Service, we may ask you to provide us with certain personally identifiable information that can be used to contact or identify you ("Personal Data").

Usage Data: The app may collect information such as your device's IP address, device name, operating system version, and the time/date of your use.

Local Network & Files: This application requires access to your local network (Wi-Fi) to communicate with ESP8266/ESP32 devices and may require local storage access for saving your configurations.

Advertising ID: This "free" version of the app uses your device's advertising identifier to show personalized ads.

2. Third-Party Service Providers

The app uses third-party services that may collect information used to identify you. These include analytics, stability, and advertising services:

Google Play Services

AdMob: Used for displaying advertisements. AdMob may use the Advertising ID from your device to serve relevant ads. Google’s Privacy & Terms

Google Analytics for Firebase

Firebase Crashlytics

3. Advertising

We use third-party service providers to show advertisements to you to help support and maintain our Service.

AdMob by Google: Google, as a third-party vendor, uses cookies and advertising identifiers to serve ads on our Service. You may opt-out of personalized advertising by visiting your device's "Ads" settings.

4. Data Safety & Disclosure

We do not sell or share your personal data with third parties for marketing purposes. Data is only used to:

Facilitate the core functionality of the Wi-Fi controller.

Show relevant advertisements via AdMob.

Analyze app performance and fix crashes.

5. Data Retention and Deletion

We retain your personal data only for as long as is necessary for the purposes set out in this Privacy Policy.

User Rights: You have the right to request the deletion of any data collected. Since we do not use a centralized user account system for this app, most data is stored locally on your device. You can clear this data by uninstalling the app or clearing the app cache. For any further data inquiries, contact us at rukosw@gmail.com.

6. Security

The security of your data is important to us, but remember that no method of transmission over the Internet is 100% secure. We strive to use commercially acceptable means to protect your Personal Data.

7. Children's Privacy

Our Service does not address anyone under the age of 13. We do not knowingly collect personally identifiable information from children under 13. If we discover that a child under 13 has provided us with personal information, we immediately delete this from our servers.

8. DIY Disclaimer

This is a "Do-It-Yourself" (DIY) application. The user assumes all responsibility for any hardware issues or accidents that may occur during the use of this software with real electronic components (relays, ESP8266, etc.).

9. Changes to This Privacy Policy

We may update our Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on this page.

10. Contact Us

If you have any questions about this Privacy Policy, please contact us:

By email: rukosw@gmail.com