• 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.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, 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

  • Samsung Smartwatch as Proximity Switch : Part II

    This second part of the guide (here is the first part) ideally should have the working code matching with the title! But, ESP32 with Arduino IDE is not completely bug-free with BLE. So, instead of directly going to the topic, it will be practical for us to show some basic example codes which the readers […]

  • Detect Smartwatch With ESP32 on IBM Watson IoT Widget

    In our previous guide, we have shown that we can trigger ESP32 (with Arduino IDE) to send message to IBM Watson IoT in Presence of a Particular Samsung Galaxy Smartwatch. That process involves BLE and WiFi. In our one series of articles on Samsung Smartwatch as Proximity Switch, we triggered a local event, such as […]

  • Detect Samsung Smartwatch BLE and Trigger IBM Watson IoT Event

    We can trigger ESP32 to send message to IBM Watson IoT in Presence of a Particular Samsung Galaxy Smartwatch. This involves BLE and WiFi.

  • WROOM ESP32 Example Codes For IBM Watson IoT Platform

    Here Are Few WROOM ESP32 Example Codes For IBM Watson IoT Platform So That Anyone Can Get Started With Both of Them Without Huge Experience.

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

Get new posts by email:

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 (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

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

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