Tinkster Logo
advancedSmart Home & IoT

Redmond SkyPort 103S socket control via Raspberry Pi

Author
Savva
Tashkent, UZ
1 day
--
2
Cover
Friends, the automation of my home continues and today I would like to share with you about how to control the SkyPort 103S Bluetooth socket from Redmond via Raspberry Pi. The whole point is that in order to control this socket by voice through Alice at home, you need to have a constantly present smartphone or tablet with the application Ready for Sky and Bluetooth enabled. Then, in the Yandex application on your gadget, you link the account with your Ready For Sky account and the 103S socket starts being controlled by voice. I had no desire to allocate a separate smartphone or tablet with constantly enabled internet and Bluetooth for one socket, especially since I control all smart home devices through Raspberry Pi with a web server and "web hooks" of the "Domovenok Kuzya" service.

Steps

1

Installing Arduino IDE and necessary libraries

Installing Arduino IDE and necessary libraries
Installing Arduino IDE and necessary libraries
Installing Arduino IDE and necessary libraries
Download Arduino IDE from here.
Open Arduino IDE and go to the section File–Preferences and in the field Additional Boards Manager URLs paste the link
https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
This is necessary in order to install the support library for the Nordic Semiconductor nRF51822 chip at the next stage. Next, go to Tools – Board – Boards Manager and find the Nordic Semiconductor nRF5 Boards library written by Sandeep Mistry. Install the latest version of this library.
Then you need to create the following folder:
~/Arduino/tools/nRF5FlashSoftDevice/tool/
and copy the file there nRF5FlashSoftDevice.jar. The file can be downloaded from here.
This is necessary to flash the SoftDevice, which is a wireless protocol stack that complements the system on a chip of the nRF5 series (SoC). Nordic Semiconductor provides them as pre-compiled binary files.
SoftDevice contains the stack BLE and service programs, and they must be loaded once before a sketch using BLE can be loaded.
Also, it is necessary that the folder of your future sketch is also located in the folder ~/Arduino/
Install the necessary libraries in Ubuntu:
1
sudo dpkg --add-architecture i386
2
sudo apt update
3
sudo apt install libc6:i386 libstdc++6:i386 libncurses5:i386 libudev1:i386
Restart Arduino IDE and create the following sketch:
1
#include <SPI.h>
2
#include <BLEPeripheral.h>
3
4
#define LED_PIN 3
5
6
BLEPeripheral blePeripheral = BLEPeripheral();
7
8
BLEService ledService = BLEService("0000180a00001000800000805f9b34fb");
9
BLECharCharacteristic switchCharacteristic = BLECharCharacteristic("00002a2900001000800000805f9b34fb", BLERead | BLEWrite);
10
11
void setup() {
12
pinMode(LED_PIN, OUTPUT);
13
14
blePeripheral.setLocalName("LED");
15
blePeripheral.setAdvertisedServiceUuid(ledService.uuid());
16
17
blePeripheral.addAttribute(ledService);
18
blePeripheral.addAttribute(switchCharacteristic);
19
20
blePeripheral.begin();
21
}
22
23
void loop() {
24
BLECentral central = blePeripheral.central();
25
26
if (central) {
27
while (central.connected()) {
28
if (switchCharacteristic.written()) {
29
if (switchCharacteristic.value()) {
30
digitalWrite(LED_PIN, HIGH);
31
}
32
else {
33
digitalWrite(LED_PIN, LOW);
34
}
35
}
36
}
37
38
}
39
}
Save the sketch.
After this, at this stage, go to Tools – Board – Nordic Semiconductor nRF5 Boards and select Generic nRF51.
In Tools – Chip select 16 kB RAM, 256 kB flash
In Tools – Softdevice select S110
In Tools – Low Frequency Clock select RC Oscillator
In Tools – Port no need to select, because we will be flashing via the SWD interface, and it does not provide for the creation of a virtual port.
In Tools — Programmer select ST-Link V2
2

Connecting the programmer to the socket

Connecting the programmer to the socket
Connecting the programmer to the socket
The programmer will come with a four-wire cable with "Female to Female" connectors for connection. I connected one end to the programmer according to the colors: Orange – 3.3V, Yellow – SWCLK, Green – GND, Blue – SWDIO.
Disassemble the socket. It's quite simple to disassemble — unscrew the two screws with a countersunk hex head. On the socket's board there will be four similar inputs. From left to right:
3.3V — Orange wire
SWDIO — Blue
SWCLK — Yellow
GND — Green
On the opposite end of the cable, I used additional wires with "Male to Male" connectors, connected one end to the cable, and the other I simply temporarily soldered to the socket's board on the outputs corresponding to the colors.
Now we need to flash the SoftDevice. This is done only once. Insert the programmer into the USB port and open the Arduino IDE.
Go to Tools and click on nRF5 Flash SoftDevice. A window will appear where you need to press the button Accept. That's it, the SoftDevice is flashed.
Now you can upload the sketch. Press Upload and the Arduino IDE will flash the nRF51822 chip. After that, you can remove the programmer from the USB port, desolder the four wires, and reassemble the socket. After assembling the Bluetooth socket, plug a desk lamp into it for testing. Connect the Bluetooth socket itself to a regular power outlet.
3

Turning on the socket via the terminal

Log into Raspberry Pi via SSH. Enter the command:
1
bluetoothctl
Next enter the command:
1
scan on
Find the MAC address of the device named LED and copy it to the clipboard.
Try to connect to the socket
1
connect XX:XX:XX:XX:XX:XX
where XX:XX:XX:XX:XX:XX is your socket's MAC address.
If the connection is successful, you will see the message
1
Device XX:XX:XX:XX:XX:XX Connected: yes
2
Connection successful
Next enter scan off and then exit to exit from bluetoothctl.
Find the Handler of our characteristic 00002a2900001000800000805f9b34fb.
Enter the command:
1
gatttool -t random --device= XX:XX:XX:XX:XX:XX --characteristics
And see something like
1
char value handle = 0x000b, uuid = 00002a29-0000-1000-8000-00805f9b34fb
0x000b – this is the Handler of this characteristic.
And now try to turn on our socket with the following command:
1
sudo gatttool -t random -i hci0 -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x000b -n 01
Where hci0 – the name of the Raspberry Pi Bluetooth adapter XX:XX:XX:XX:XX:XX – the socket's MAC address 0x000b – the characteristic Handler (you will have your own) 01 – the byte value to write to this characteristic
Accordingly, the command to turn off will be:
1
sudo gatttool -t random -i hci0 -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x000b -n 00

Conclusion

Friends, that's all for now, this socket can now be controlled via Raspberry Pi, but the drawback of this method is that until Sandeep Mistry finds a way to connect via Bluetooth using passkey (i.e., a password), therefore, anyone within 10 meters of the socket will be able to turn it on using the appropriate equipment. I think you won't have any trouble 'attaching' terminal commands for controlling the socket via a web server and 'web hooks' to Alice. If you have suggestions on how to create a connection to the socket with a password, write in the comments.
Happy upcoming New Year to all of you! Wishing you all the best and only good luck in the new year!

Discussion (0)

No comments yet. Be the first!

Maker

Avatar
Savva
Tashkent, UZ

Anton is the Managing Partner of Tinkster. He studied oil and gas engineering in the United States and also holds two honors degrees from Tomsk Polytechnic University.