SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Downloaden Sie, um offline zu lesen
Swift Hardware Hacking
Sally Shepard

@mostgood
First Local Cat Savings Bank!
Congratulations on joining
@mostgood
Video of coin bank
Savings account v1.0
@mostgood
Savings account v2.0
@mostgood
Ready for deposit
£4.85
How to: Build the smart savings account
@mostgood
Step 0: Setup development environment
@mostgood
"
@mostgood
@mostgood
@mostgood
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
Setting up Geany for build/run
Reference: https://www.geany.org/manual/current/index.html
@mostgood
Step 1: Controlling power to the bank
@mostgood
v1
#$
v2
% &
@mostgood
Circuits
@mostgood
Circuits
@mostgood
@mostgood
+ — + —
GPIOHeader
@mostgood
Dependencies ->
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/uraimo/SwiftyGPIO.git", from: "1.0.0")]
.target( name: "GeePeeEyeOh",
dependencies: ["SwiftyGPIO"])
Reference: https://github.com/uraimo/SwiftyGPIO
@mostgood
@mostgood
@mostgood
Relay.swift
import SwiftyGPIO
struct Relay {
var state: State {
get {
if let pin = self.gpio {
switch pin.value {
case 1:
return .On
default:
return .Off
}
}
return .Off
}
}
private var gpio: RaspberryGPIO?
init() {
setup()
}
init(connectTo pin: RaspberryGPIO) {
self.gpio = pin
setup()
}
private mutating func setup() {
if self.gpio == nil {
let gpios = SwiftyGPIO.GPIOs(for: .RaspberryPiPlusZero)
self.gpio = gpios[.P4] as? RaspberryGPIO
}
if let gpio = self.gpio {
gpio.direction = .OUT
}
}
public func switchTo(_ state: State) {
if let gpio = self.gpio {
gpio.value = state.rawValue
}
}
}
@mostgood
Digital Signal
0
1
1 = 3.3v 1 = 3.3v
0 = 0v 0 = 0v
@mostgood
Step 2: tell when the lid is open
@mostgood
@mostgood
@mostgood
Analogue Signal
0
128
256
384
512
640
768
896
1024
768
140
@mostgood
@mostgood
@mostgood
Dependencies -> MCP3008.swift
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/uraimo/SwiftyGPIO.git", from: “1.0.0”),
.package(url: "https://github.com/uraimo/MCP3008.swift.git", from: “2.0.0")]
.target( name: "GeePeeEyeOh",
dependencies: [“SwiftyGPIO”, “MCP3008”])
Reference: https://github.com/uraimo/MCP3008
@mostgood
import SwiftyGPIO
struct Photoresistor {
private var maxLightThreshold: UInt32 = 0
private var minLightThreshhold: UInt32 = 1024
private var tolerance: UInt32 = 10
var lightReading: UInt32 = 1024
var light: Bool {
get {
let lightRange = 0...(lightReading + tolerance)
return lightRange.contains(lightReading)
}
}
init(light minLightThreshhold: UInt32,
dark maxLightThreshold: UInt32,
tolerance tolerance: UInt32) {
self.minLightThreshhold = minLightThreshhold
self.maxLightThreshold = maxLightThreshold
self.tolerance = tolerance
self.init()
}
}
Photoresistor.
swift
@mostgood
Step 3: figuring out what coin was deposited
@mostgood
coin weight = currentDeposit - previousDeposit
@mostgood
@mostgood
@mostgood
Red E+
Black E-
White A-
Green A+
Ground
DF
SCK
Vcc
Datasheets!
@mostgood
@mostgood
@mostgood
@mostgood
Digital Signal
0
1
1 = 3.3v 1 = 3.3v
0 = 0v 0 = 0v
@mostgood
Analogue Signal
0
128
256
384
512
640
768
896
1024
768
140
@mostgood
Analogue to Digital?
140
768
@mostgood
Analogue to Digital?
140
768
0000 1000 1100
0011 0000 0000
@mostgood
Analogue to Digital?
0000 1000 1100
0011 0000 0000
@mostgood
Analogue to Digital?
0 0 0 0 0 0 1 0 1 0 0 1
word length = 12 bits
@mostgood
@mostgood
@mostgood
@mostgood
@mostgood
two’s complement
import SwiftGPIO
struct HX711 {
var dt: RaspberryGPIO?
var sck: RaspberryGPIO?
init() {
let gpios = SwiftyGPIO.GPIOs(for:.RaspberryPiPlusZero)
dt = gpios[.P5] as? RaspberryGPIO
sck = gpios[.P6] as? RaspberryGPIO
self.setup()
}
init(data dt: RaspberryGPIO, clock ck: RaspberryGPIO) {
self.dt = dt
self.sck = ck
self.setup()
}
private func setup() {
if let dt = self.dt, let sck = self.sck {
dt.direction = .IN
sck.direction = .OUT
}
}
// read from the Data pin
public func readData() -> Int {
if let dt = self.dt {
if dt.value == 0 {
for _ in 0..<24 {
self. sck.value = 1
if let dt = self.dt {
//MAKE BITS DO THINGS HERE
}
self. sck.value = 0
}
} else {
print("Not Ready")
}
}
}
}
HX711.swift
@mostgood
@mostgood
@UIKitten
Step 5: Bluetooth connection to iOS
@mostgood
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
Bluetooth Low Energy
Core
Bluetooth
API
PureSwift/Bluetooth
PureSwift/BluetoothLinux
PureSwift/GATT
@mostgood
Bluetooth Low Energy
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/uraimo/SwiftyGPIO.git", from: “1.0.0”),
.package(url: "https://github.com/uraimo/MCP3008.swift.git", from: “2.0.0”),
.package(url: "https://github.com/PureSwift/BluetoothLinux.git", from: “3.0.0"),
.package(url: "https://github.com/PureSwift/GATT.git", from : "1.0.0")]
.target( name: "GeePeeEyeOh",
dependencies: [“SwiftyGPIO”, “MCP3008”, “BluetoothLinux”, “GATT”])
Reference: https://github.com/PureSwift/BluetoothLinux https://github.com/PureSwift/GATT
@mostgood
Core Bluetooth
// Core Bluetooth Manager
var centralManager = CBCentralManager(delegate: self, queue: DispatchQueue.main)
centralManager?.scanForPeripherals(withServices: nil, options: nil)
// Delegate Methods for Bluetooth Central Manager
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData:
[String : Any], rssi RSSI: NSNumber)
// Delegate methods for connected peripherals
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
// Peripheral methods
peripheral.writeValue(data, for: descriptor)
peripheral.readValue(for: descriptor)
peripheral.setNotifyValue(true, for: characteristic)
@mostgood
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
Final product
@mostgood
@mostgood
Thank you for listening!
Sally Shepard

@mostgood

Weitere ähnliche Inhalte

Was ist angesagt?

Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationFIWARE
 
A friend in need - A JS indeed
A friend in need - A JS indeedA friend in need - A JS indeed
A friend in need - A JS indeedYonatan Levin
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/smoret1979
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioCaesar Chi
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBemptysquare
 
Tornado web
Tornado webTornado web
Tornado webkurtiss
 
Vert.x clustering on Docker, CoreOS and ETCD
Vert.x clustering on Docker, CoreOS and ETCDVert.x clustering on Docker, CoreOS and ETCD
Vert.x clustering on Docker, CoreOS and ETCDTim Nolet
 
The 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWAREThe 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWAREFIWARE
 
WebRTC 101 - How to get started building your first WebRTC application
WebRTC 101 - How to get started building your first WebRTC applicationWebRTC 101 - How to get started building your first WebRTC application
WebRTC 101 - How to get started building your first WebRTC applicationDan Jenkins
 
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIPhpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIMarcelo Gornstein
 
How to Install & Configure Your Own Identity Manager GE
How to Install & Configure Your Own Identity Manager GEHow to Install & Configure Your Own Identity Manager GE
How to Install & Configure Your Own Identity Manager GEFIWARE
 
Serverless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopServerless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopLuciano Mammino
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019Matt Raible
 
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...Luciano Mammino
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Luciano Mammino
 

Was ist angesagt? (20)

Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE Implementation
 
A friend in need - A JS indeed
A friend in need - A JS indeedA friend in need - A JS indeed
A friend in need - A JS indeed
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/s
 
Node worshop Realtime - Socket.io
Node worshop Realtime - Socket.ioNode worshop Realtime - Socket.io
Node worshop Realtime - Socket.io
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDB
 
Tornado web
Tornado webTornado web
Tornado web
 
Vert.x clustering on Docker, CoreOS and ETCD
Vert.x clustering on Docker, CoreOS and ETCDVert.x clustering on Docker, CoreOS and ETCD
Vert.x clustering on Docker, CoreOS and ETCD
 
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
 
The 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWAREThe 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWARE
 
WebRTC 101 - How to get started building your first WebRTC application
WebRTC 101 - How to get started building your first WebRTC applicationWebRTC 101 - How to get started building your first WebRTC application
WebRTC 101 - How to get started building your first WebRTC application
 
Guice gin
Guice ginGuice gin
Guice gin
 
Tornado in Depth
Tornado in DepthTornado in Depth
Tornado in Depth
 
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIPhpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
 
hacking with node.JS
hacking with node.JShacking with node.JS
hacking with node.JS
 
How to Install & Configure Your Own Identity Manager GE
How to Install & Configure Your Own Identity Manager GEHow to Install & Configure Your Own Identity Manager GE
How to Install & Configure Your Own Identity Manager GE
 
Serverless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopServerless, The Middy Way - Workshop
Serverless, The Middy Way - Workshop
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
 
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​
 

Ähnlich wie Swift hardware hacking @ try! Swift

Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)남균 김
 
Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2FIWARE
 
From the internet of things to the web of things course
From the internet of things to the web of things courseFrom the internet of things to the web of things course
From the internet of things to the web of things courseDominique Guinard
 
FIWARE IoT Proposal & Community
FIWARE IoT Proposal & CommunityFIWARE IoT Proposal & Community
FIWARE IoT Proposal & CommunityFIWARE
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionHiveMQ
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Yuriy Senko
 
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud PlatformBackend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud PlatformDevMT
 
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud PlatformBackend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud PlatformAlvaro Viebrantz
 
Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8FIWARE
 
FIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT DevicesFIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT DevicesFIWARE
 
Raspberry pi and Azure
Raspberry pi and AzureRaspberry pi and Azure
Raspberry pi and AzureFaisal Mehmood
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community TIDChile
 
IoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3BIoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3BJingfeng Liu
 
IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2John Staveley
 
Fire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS FirewallsFire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS FirewallsPriyanka Aash
 
OpenStack API's and WSGI
OpenStack API's and WSGIOpenStack API's and WSGI
OpenStack API's and WSGIMike Pittaro
 

Ähnlich wie Swift hardware hacking @ try! Swift (20)

IoT on Raspberry Pi
IoT on Raspberry PiIoT on Raspberry Pi
IoT on Raspberry Pi
 
Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)
 
IoT Workshop in Macao
IoT Workshop in MacaoIoT Workshop in Macao
IoT Workshop in Macao
 
IoT Workshop in Macao
IoT Workshop in MacaoIoT Workshop in Macao
IoT Workshop in Macao
 
Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2Fiware IoT_IDAS_intro_ul20_v2
Fiware IoT_IDAS_intro_ul20_v2
 
From the internet of things to the web of things course
From the internet of things to the web of things courseFrom the internet of things to the web of things course
From the internet of things to the web of things course
 
FIWARE IoT Proposal & Community
FIWARE IoT Proposal & CommunityFIWARE IoT Proposal & Community
FIWARE IoT Proposal & Community
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ Extension
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud PlatformBackend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
 
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud PlatformBackend, app e internet das coisas com NodeJS no Google Cloud Platform
Backend, app e internet das coisas com NodeJS no Google Cloud Platform
 
Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8
 
FIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT DevicesFIWARE Wednesday Webinars - How to Secure IoT Devices
FIWARE Wednesday Webinars - How to Secure IoT Devices
 
Raspberry pi and Azure
Raspberry pi and AzureRaspberry pi and Azure
Raspberry pi and Azure
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community
 
IoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3BIoT with openHAB on pcDuino3B
IoT with openHAB on pcDuino3B
 
IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2
 
Fire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS FirewallsFire & Ice: Making and Breaking macOS Firewalls
Fire & Ice: Making and Breaking macOS Firewalls
 
OpenStack API's and WSGI
OpenStack API's and WSGIOpenStack API's and WSGI
OpenStack API's and WSGI
 

Mehr von Sally Shepard

Porting iOS apps to tvOS
Porting iOS apps to tvOSPorting iOS apps to tvOS
Porting iOS apps to tvOSSally Shepard
 
Porting iOS apps to tvOS
Porting iOS apps to tvOSPorting iOS apps to tvOS
Porting iOS apps to tvOSSally Shepard
 
Helping Users Create Good Habits @ AltConf 2017
Helping Users Create Good Habits @ AltConf 2017Helping Users Create Good Habits @ AltConf 2017
Helping Users Create Good Habits @ AltConf 2017Sally Shepard
 
iOS Accessibility Testing Workshop
iOS Accessibility Testing WorkshopiOS Accessibility Testing Workshop
iOS Accessibility Testing WorkshopSally Shepard
 
Helping Users Create Good Habits @ MCE 2017
Helping Users Create Good Habits @ MCE 2017Helping Users Create Good Habits @ MCE 2017
Helping Users Create Good Habits @ MCE 2017Sally Shepard
 
Debugging Accessibility @ Craft Conf
Debugging Accessibility @ Craft ConfDebugging Accessibility @ Craft Conf
Debugging Accessibility @ Craft ConfSally Shepard
 
Debugging Accessibility
Debugging AccessibilityDebugging Accessibility
Debugging AccessibilitySally Shepard
 
Crafting Great Accessible Experiences
Crafting Great Accessible ExperiencesCrafting Great Accessible Experiences
Crafting Great Accessible ExperiencesSally Shepard
 
Developing for Apple TV
Developing for Apple TVDeveloping for Apple TV
Developing for Apple TVSally Shepard
 
Implementing Inclusive Interfaces
Implementing Inclusive InterfacesImplementing Inclusive Interfaces
Implementing Inclusive InterfacesSally Shepard
 
Building habits: keeping users engaged
Building habits: keeping users engagedBuilding habits: keeping users engaged
Building habits: keeping users engagedSally Shepard
 
Implementing inclusive interfaces in iOS
Implementing inclusive interfaces in iOSImplementing inclusive interfaces in iOS
Implementing inclusive interfaces in iOSSally Shepard
 
Extracurricular Swift
Extracurricular SwiftExtracurricular Swift
Extracurricular SwiftSally Shepard
 
Making an app like 'Clear' Accessible
Making an app like 'Clear' AccessibleMaking an app like 'Clear' Accessible
Making an app like 'Clear' AccessibleSally Shepard
 
Making apps for the Apple TV
Making apps for the Apple TVMaking apps for the Apple TV
Making apps for the Apple TVSally Shepard
 
Beyond VoiceOver: making iOS apps accessible
Beyond VoiceOver: making iOS apps accessibleBeyond VoiceOver: making iOS apps accessible
Beyond VoiceOver: making iOS apps accessibleSally Shepard
 

Mehr von Sally Shepard (18)

Porting iOS apps to tvOS
Porting iOS apps to tvOSPorting iOS apps to tvOS
Porting iOS apps to tvOS
 
Porting iOS apps to tvOS
Porting iOS apps to tvOSPorting iOS apps to tvOS
Porting iOS apps to tvOS
 
Helping Users Create Good Habits @ AltConf 2017
Helping Users Create Good Habits @ AltConf 2017Helping Users Create Good Habits @ AltConf 2017
Helping Users Create Good Habits @ AltConf 2017
 
iOS Accessibility Testing Workshop
iOS Accessibility Testing WorkshopiOS Accessibility Testing Workshop
iOS Accessibility Testing Workshop
 
Helping Users Create Good Habits @ MCE 2017
Helping Users Create Good Habits @ MCE 2017Helping Users Create Good Habits @ MCE 2017
Helping Users Create Good Habits @ MCE 2017
 
Debugging Accessibility @ Craft Conf
Debugging Accessibility @ Craft ConfDebugging Accessibility @ Craft Conf
Debugging Accessibility @ Craft Conf
 
Accessibility
AccessibilityAccessibility
Accessibility
 
Debugging Accessibility
Debugging AccessibilityDebugging Accessibility
Debugging Accessibility
 
Crafting Great Accessible Experiences
Crafting Great Accessible ExperiencesCrafting Great Accessible Experiences
Crafting Great Accessible Experiences
 
Developing for Apple TV
Developing for Apple TVDeveloping for Apple TV
Developing for Apple TV
 
Implementing Inclusive Interfaces
Implementing Inclusive InterfacesImplementing Inclusive Interfaces
Implementing Inclusive Interfaces
 
Building habits: keeping users engaged
Building habits: keeping users engagedBuilding habits: keeping users engaged
Building habits: keeping users engaged
 
Implementing inclusive interfaces in iOS
Implementing inclusive interfaces in iOSImplementing inclusive interfaces in iOS
Implementing inclusive interfaces in iOS
 
Extracurricular Swift
Extracurricular SwiftExtracurricular Swift
Extracurricular Swift
 
Inheriting iOS code
Inheriting iOS codeInheriting iOS code
Inheriting iOS code
 
Making an app like 'Clear' Accessible
Making an app like 'Clear' AccessibleMaking an app like 'Clear' Accessible
Making an app like 'Clear' Accessible
 
Making apps for the Apple TV
Making apps for the Apple TVMaking apps for the Apple TV
Making apps for the Apple TV
 
Beyond VoiceOver: making iOS apps accessible
Beyond VoiceOver: making iOS apps accessibleBeyond VoiceOver: making iOS apps accessible
Beyond VoiceOver: making iOS apps accessible
 

Kürzlich hochgeladen

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Swift hardware hacking @ try! Swift

  • 1. Swift Hardware Hacking Sally Shepard @mostgood
  • 2. First Local Cat Savings Bank! Congratulations on joining @mostgood
  • 3. Video of coin bank Savings account v1.0 @mostgood
  • 5. How to: Build the smart savings account @mostgood
  • 6. Step 0: Setup development environment @mostgood
  • 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
  • 12. Step 1: Controlling power to the bank @mostgood
  • 18. Dependencies -> dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/uraimo/SwiftyGPIO.git", from: "1.0.0")] .target( name: "GeePeeEyeOh", dependencies: ["SwiftyGPIO"]) Reference: https://github.com/uraimo/SwiftyGPIO @mostgood
  • 21. Relay.swift import SwiftyGPIO struct Relay { var state: State { get { if let pin = self.gpio { switch pin.value { case 1: return .On default: return .Off } } return .Off } } private var gpio: RaspberryGPIO? init() { setup() } init(connectTo pin: RaspberryGPIO) { self.gpio = pin setup() } private mutating func setup() { if self.gpio == nil { let gpios = SwiftyGPIO.GPIOs(for: .RaspberryPiPlusZero) self.gpio = gpios[.P4] as? RaspberryGPIO } if let gpio = self.gpio { gpio.direction = .OUT } } public func switchTo(_ state: State) { if let gpio = self.gpio { gpio.value = state.rawValue } } } @mostgood
  • 22. Digital Signal 0 1 1 = 3.3v 1 = 3.3v 0 = 0v 0 = 0v @mostgood
  • 23. Step 2: tell when the lid is open @mostgood
  • 29. Dependencies -> MCP3008.swift dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/uraimo/SwiftyGPIO.git", from: “1.0.0”), .package(url: "https://github.com/uraimo/MCP3008.swift.git", from: “2.0.0")] .target( name: "GeePeeEyeOh", dependencies: [“SwiftyGPIO”, “MCP3008”]) Reference: https://github.com/uraimo/MCP3008 @mostgood
  • 30. import SwiftyGPIO struct Photoresistor { private var maxLightThreshold: UInt32 = 0 private var minLightThreshhold: UInt32 = 1024 private var tolerance: UInt32 = 10 var lightReading: UInt32 = 1024 var light: Bool { get { let lightRange = 0...(lightReading + tolerance) return lightRange.contains(lightReading) } } init(light minLightThreshhold: UInt32, dark maxLightThreshold: UInt32, tolerance tolerance: UInt32) { self.minLightThreshhold = minLightThreshhold self.maxLightThreshold = maxLightThreshold self.tolerance = tolerance self.init() } } Photoresistor. swift @mostgood
  • 31. Step 3: figuring out what coin was deposited @mostgood
  • 32. coin weight = currentDeposit - previousDeposit @mostgood
  • 34. @mostgood Red E+ Black E- White A- Green A+ Ground DF SCK Vcc
  • 39. Digital Signal 0 1 1 = 3.3v 1 = 3.3v 0 = 0v 0 = 0v @mostgood
  • 42. Analogue to Digital? 140 768 0000 1000 1100 0011 0000 0000 @mostgood
  • 43. Analogue to Digital? 0000 1000 1100 0011 0000 0000 @mostgood
  • 44. Analogue to Digital? 0 0 0 0 0 0 1 0 1 0 0 1 word length = 12 bits @mostgood
  • 49. import SwiftGPIO struct HX711 { var dt: RaspberryGPIO? var sck: RaspberryGPIO? init() { let gpios = SwiftyGPIO.GPIOs(for:.RaspberryPiPlusZero) dt = gpios[.P5] as? RaspberryGPIO sck = gpios[.P6] as? RaspberryGPIO self.setup() } init(data dt: RaspberryGPIO, clock ck: RaspberryGPIO) { self.dt = dt self.sck = ck self.setup() } private func setup() { if let dt = self.dt, let sck = self.sck { dt.direction = .IN sck.direction = .OUT } } // read from the Data pin public func readData() -> Int { if let dt = self.dt { if dt.value == 0 { for _ in 0..<24 { self. sck.value = 1 if let dt = self.dt { //MAKE BITS DO THINGS HERE } self. sck.value = 0 } } else { print("Not Ready") } } } } HX711.swift @mostgood
  • 51. Step 5: Bluetooth connection to iOS @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
  • 54. Bluetooth Low Energy dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/uraimo/SwiftyGPIO.git", from: “1.0.0”), .package(url: "https://github.com/uraimo/MCP3008.swift.git", from: “2.0.0”), .package(url: "https://github.com/PureSwift/BluetoothLinux.git", from: “3.0.0"), .package(url: "https://github.com/PureSwift/GATT.git", from : "1.0.0")] .target( name: "GeePeeEyeOh", dependencies: [“SwiftyGPIO”, “MCP3008”, “BluetoothLinux”, “GATT”]) Reference: https://github.com/PureSwift/BluetoothLinux https://github.com/PureSwift/GATT @mostgood
  • 55. Core Bluetooth // Core Bluetooth Manager var centralManager = CBCentralManager(delegate: self, queue: DispatchQueue.main) centralManager?.scanForPeripherals(withServices: nil, options: nil) // Delegate Methods for Bluetooth Central Manager func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) // Delegate methods for connected peripherals func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) // Peripheral methods peripheral.writeValue(data, for: descriptor) peripheral.readValue(for: descriptor) peripheral.setNotifyValue(true, for: characteristic) @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
  • 59. Thank you for listening! Sally Shepard @mostgood