A talk looking at building a smart savings account - some hardware hacking, Raspberry Pi development, Bluetooth LE, electronics, bit banging - all using Swift.
10. Install Swift on Raspberry Pi
curl -s https://packagecloud.io/install/
repositories/swift-arm/release/script.deb.sh |
sudo bash
sudo apt install swift4 //if on 3B+
sudo apt install swift4rpi01 //if using a Zero
@mostgood
Create a project
mkdir ~/Documents/<project-name>
cd ~/Documents/<project-name>
swift package init --type executable
11. Setting up Geany for build/run
Reference: https://www.geany.org/manual/current/index.html
@mostgood
52. Bluetooth Low Energy
“Central”
client
“Peripheral”
server
GATT Profile
0x180A
“Device Information”
• Manufacturer Name
• Model Number
• Serial Number
• Hardware/Firmware/Software
Revision
• System ID
• Certification List
• Device ID
GATT Profile
0x180F
“Battery Service”
• Battery Level
• Level Changed
Notify
“Battery Level
Changed”
• Battery Percentage
(optional)
Write
“User Data - First Name”
Read
“Device Information -
Serial Number”
@mostgood
56. Bluetooth Linux
// Instantiate controller & peripheral
let controller = HostController.default
let peripheral = PeripheralManager(controller: controller)
// configure service(s)
let service = BluetoothUUID(rawValue: “180A”), // Hex value of GATT Service
let controllerType = serviceControllers.first(where: { $0.service == service })
let serviceController = try controllerType.init(peripheral: peripheral)
// start the peripheral
try peripheral.start()
Reference: https://github.com/MillerTechnologyPeru/gattserver
@mostgood