2. About Me
• iOS developer
• Runs Azukisoft Pte Ltd
• Author of
http://www.amazon.com/Objecti
ve-C-Memory-Management-
Essentials-Gibson-
ebook/dp/B00V8BMX7I/
3. What is the Aspirus Standing Desk?
• Standing Desk
• But Smarter
• https://www.indiegogo.com/p
rojects/aspirus-world-s-first-
smart-standing-workstation#/
4.
5. Functionality
• 8-in-1 SMART WORKSTATION
with one-touch elevation,
smart app, sit-stand reminder,
tracking and more
10. Protocol
• We settled on Modbus after discussion with
the hardware engineer
• WTF is Modbus?
11. Modbus
• https://en.wikipedia.org/wiki/Modbus
• Modbus is a serial communications protocol
originally published by Modicon (now Schneider
Electric) in 1979 for use with its programmable
logic controllers
• Simple and robust, it has since become a de facto
standard communication protocol, and it is now a
commonly available means of connecting
industrial electronic devices
12. Modbus
• Royalty free too
• Which means someone wrote a objective-c
library
• Which we can use?
16. Modbus
• So we had no choice, but to write our own
implementation
• Look for online documentation
• Start hacking away
• http://www.modbustools.com/modbus.html
18. Modbus
• 30 0300 2500 01 91E0
• 30 – Random Tag
• 0300 – Address of register
• 2500 – Function to use
• 01 – Data to send
• 91E0 – CRC check
19. Bluetooth
• CRC calculated using some arcane formula
involving bit shifting, blood of your first born
and some magical incantations
• http://www.ccontrolsys.com/w/How_to_Com
pute_the_Modbus_RTU_Message_CRC
20. Bluetooth
• After calculation, how do we send it to the
controller on the desk?
• 1st, we scan for a peripherals and then get an
array of peripherals
• retrieveConnectedPeripheralsWithServices
returns a NSArray of peripherals
21. Bluetooth
• Then we do a connection
• - (void)connectPeripheral:(CBPeripheral
*)peripheral options:(NSDictionary<NSString
*, id> *)options
• Great. Now the easy part is done
22. Modbus
• So how we do send the data
over?
• Binary?
• Text?
• ???
23. Modbus
• Only way is using byte array
• So we convert our NSString
• Contain Hex values
• To a byte array
27. Modbus
• Then in the callback function.
We await the response from
the device
• - (void)peripheral:(CBPeripheral *)peripheral
didUpdateValueForCharacteristic:(CBCharacte
ristic *)characteristic error:(NSError *)error
28. Modbus
• But wait, there’s more!!!
• Remember that random tag?
• 30030025000191E0
• 30 – Random Tag
• 0300 – Address of register
• 2500 – Function to use
• 01 – Data to send
• 91E0 – CRC check
30. Modbus
1. Write random tag and value to
characteristic
2. Await for response
3. Get the random tag from response
4. If tag does not match what was sent
in step #1
5. Rinse and repeat step #1 until it does
31. Modbus
1. So once all these are done
2. We reused the code so that we
are able to get various sensor
data from the device
3. Desk up/down position, adjust
desk light, detection of user
presense etc