Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **BLE Server**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-03-28 03:13:13
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a Bluetooth Low Energy (BLE) */
- /* communication system using NimBLEDevice to connect */
- /* and control connected components remotely. Ensure */
- /* seamless data transfer and device management for */
- /* enhanced user experience. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Write a Code for esp32-C3 in arduino IDE that */
- /* always is on deep sleep. Increment a value every 3 */
- /* seconds and transmit the value by bluetooth using */
- /* Nimble library and the same data will transmitted */
- /* by espnow every 9 seconds. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <NimBLEDevice.h> // https://github.com/h2zero/NimBLE-Arduino
- #include <DHT.h> // https://github.com/adafruit/DHT-sensor-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t myDHT22_DHT22_DOUT_PIN_D4 = 4;
- const uint8_t myDHT11_DHT11_DOUT_PIN_D13 = 13;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // BLE variables
- NimBLEServer* pServer = nullptr;
- NimBLECharacteristic* pCharacteristic = nullptr;
- uint32_t valueToSend = 0; // Value to be incremented and sent
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // Initialize Serial for debugging
- Serial.begin(115200);
- // Initialize BLE
- NimBLEDevice::init("ESP32-C3");
- // Create BLE Server
- pServer = NimBLEDevice::createServer();
- pCharacteristic = pServer->createCharacteristic(
- "12345678-1234-5678-1234-56789abcdef0", // UUID
- NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::READ
- );
- // Set pin modes
- pinMode(myDHT22_DHT22_DOUT_PIN_D4, INPUT_PULLUP);
- pinMode(myDHT11_DHT11_DOUT_PIN_D13, INPUT_PULLUP);
- // Start advertising
- pServer->getAdvertising()->start();
- Serial.println("BLE Server is advertising");
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Increment the value every 3 seconds
- delay(3000);
- valueToSend++;
- Serial.print("Value to send: ");
- Serial.println(valueToSend);
- // Update the characteristic with the new value
- pCharacteristic->setValue(valueToSend);
- pCharacteristic->notify();
- // Deep sleep for 9 seconds
- Serial.println("Going to deep sleep for 9 seconds");
- esp_sleep_enable_timer_wakeup(9000000); // 9 seconds in microseconds
- esp_deep_sleep_start();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement