• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Samsung Smartwatch as Proximity Switch : Part IV

By Abhishek Ghosh February 23, 2020 6:28 pm Updated on May 3, 2020

Samsung Smartwatch as Proximity Switch : Part IV

Advertisement

In the previous part of this topic (here is part III), we provided a sample code to create a basic BLE scanner. The code makes the ESP32’s on-board LED to turn on whenever the watch comes in proximity.

In our earlier parts of this series, we talked about filtering the MAC address and practical matters around Samsung Galaxy Watch. I found that the website circuitdigest.com worked with a similar project with a Fitness Band.

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// original version written by
// https://circuitdigest.com/microcontroller-projects/esp32-ble-client-connecting-to-fitness-band-to-trigger-light
 
#include <BLEDevice.h> //Header file for BLE
static BLEUUID serviceUUID("0000d15a-0000-1000-8000-aabbccddeeff"); //Service UUID of fitnessband obtained through nRF connect application
static BLEUUID    charUUID("0000d15a-0000-1000-8000-aabbccddeeff"); //Characteristic  UUID of fitnessband obtained through nRF connect application
String My_BLE_Address = "e0:a1:07:b7:0b:95"; //Hardware Bluetooth MAC of my fitnessband, will vary for every band obtained through nRF connect application
static BLERemoteCharacteristic* pRemoteCharacteristic;
BLEScan* pBLEScan; //Name the scanning device as pBLEScan
BLEScanResults foundDevices;
static BLEAddress *Server_BLE_Address;
String Scaned_BLE_Address;
boolean paired = false; //boolean variable to togge light
bool connectToserver (BLEAddress pAddress){
    
    BLEClient*  pClient  = BLEDevice::createClient();
    Serial.println(" - Created client");
    // Connect to the BLE Server.
    pClient->connect(pAddress);
    Serial.println(" - Connected to fitnessband");
    // Obtain a reference to the service we are after in the remote BLE server.
    BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
    if (pRemoteService != nullptr)
    {
      Serial.println(" - Found our service");
      return true;
    }
    else
    return false;
    // Obtain a reference to the characteristic in the service of the remote BLE server.
    pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
    if (pRemoteCharacteristic != nullptr)
      Serial.println(" - Found our characteristic");
      return true;
}
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks
{
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      Serial.printf("Scan Result: %s \n", advertisedDevice.toString().c_str());
      Server_BLE_Address = new BLEAddress(advertisedDevice.getAddress());
      
      Scaned_BLE_Address = Server_BLE_Address->toString().c_str();
      
    }
};
void setup() {
    Serial.begin(115200); //Start serial monitor
    Serial.println("ESP32 BLE Server program"); //Intro message
    BLEDevice::init("");
    pBLEScan = BLEDevice::getScan(); //create new scan
    pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); //Call the class that is defined above
    pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
    pinMode (2,OUTPUT); //Declare the in-built LED pin as output
}
void loop() {
  foundDevices = pBLEScan->start(3); //Scan for 3 seconds to find the Fitness band
  while (foundDevices.getCount() >= 1)
  {
    if (Scaned_BLE_Address == My_BLE_Address && paired == false)
    {
      Serial.println("Found Device :-)... connecting to Server as client");
       if (connectToserver(*Server_BLE_Address))
      {
      paired = true;
      Serial.println("********************LED turned ON************************");
      digitalWrite (2,HIGH);
      break;
      }
      else
      {
      Serial.println("Pairing failed");
      break;
      }
    }
    
    if (Scaned_BLE_Address == My_BLE_Address && paired == true)
    {
      Serial.println("Our device went out of range");
      paired = false;
      Serial.println("********************LED OOOFFFFF************************");
      digitalWrite (2,LOW);
      ESP.restart();
      break;
    }
    else
    {
    Serial.println("We have some other BLe device in range");
    break;
    }
  }
}

You have to change these three lines :

Advertisement

---

Vim
1
2
static BLEUUID    charUUID("0000d15a-0000-1000-8000-aabbccddeeff"); //Characteristic  UUID of Samsung Galaxy Smartwatch obtained through nRF connect application
String My_BLE_Address = "E0:A1:07:B7:0B:95"; //Hardware Bluetooth MAC of my Samsung Galaxy Smartwatch, will vary for every watch obtained through nRF connect application

Samsung Smartwatch as Proximity Switch

Press the RESET button of ESP32 and open the serial monitor of Arduino IDE. You’ll get some output like below :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ets Jun  8 2016 00:22:57
 
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10208
load:0x40080400,len:6460
entry 0x400806a4
ESP32 BLE Server program
Scan Result: Name: Galaxy Watch (E5CA) LE, Address: e0:a1:07:b7:0b:95, appearance: 192, manufacturer data: 750001000200010302
Found Device :-)... connecting to Server as client
- Created client

We have optimized the code in the next article.

This Article Has Been Shared 685 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Samsung Smartwatch as Proximity Switch : Part IV

  • How to Invert Signal for Arduino (HIGH to LOW or the Reverse)

    Such need is common when then need interfacing for IoT with household gadgets. Here is How to Invert Signal for Arduino (HIGH to LOW or the Reverse).

  • CircuitPython vs C/C++ vs Lua for the Microcontrollers

    Which Programming Language Better for the Microcontrollers to Invest Time? Here is CircuitPython vs C/C++ vs Lua Comparison for the Microcontrollers.

  • Control Multiple AC Appliances With One ESP32 Arduino

    Here is how to use ESP32 and IBM Watson IoT to control multiple relays (i.e. multiple AC appliances) by pushbutton and over the internet.

  • Samsung Smartwatch as Proximity Switch : Part I

    We Can Use BLE of Samsung Smartwatch to Work as Proximity Switch Created With ESP32 Arduino for Automation of Lights in a Room.

  • ESP32 BLE Server with Android App

    BLE only works when one communication is active and stays ON. Else it remains in sleep mode. Beacons are great usage of BLE. In our series of articles on Samsung Smartwatch as Proximity Switch, we have used the ESP32 as client. In this article, we are talking about using ESP32 BLE as a server. In […]

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (20K Followers)
  • Twitter (4.9k Followers)
  • Facebook (5.8k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.2k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Domain-Driven Design (DDD)? January 23, 2021
  • Top 10 Anti Hacking Software for Microsoft Windows January 22, 2021
  • What is Software Modernization? January 21, 2021
  • Cloud Computing : Cybersecurity Tips for Small Business Owners January 20, 2021
  • Arduino : Independently Blink Multiple LED January 18, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Samsung Smartwatch as Proximity Switch : Part IV," in The Customize Windows, February 23, 2020, January 24, 2021, https://thecustomizewindows.com/2020/02/samsung-smartwatch-as-proximity-switch-part-iv/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy