3. About FinancialForce.com
• San Francisco Headquarters
• Harrogate, UK
• Granada, Spain
• Toronto, Canada
• Manchester, US
• Opening Sydney, AUS in Sept, 2014
• 350+ Employees
• 400+ by 12/31/2014
• Customers in 31 countries
• 80% Y-o-Y revenue growth
• Advent commitment of $50 million
4. Session Resources
• Follow the Session in the Dreamforce
App, I will share this slide deck and
other related links on the Feed
• Be social and feel free to ask follow up
questions!
5. Introduction
• What are the device requirements?
• How intelligent does the device need to be?
• What is a Machine Cloud?
• Building a Machine Cloud with Salesforce1 Platform
• Demos
• How to make your own Machine Cloud with
with Lego Mindstorms EV3
6. What does a Device need to call the Salesforce API’s?
• Ability to connect to a local internet gateway
– e.g. phone or other computer connected to Internet
• Ability to connect direct to Internet
– SSL support ideally, though non-SSL end points
proxies can be used
• Ability to parse XML or JSON
– String manipulation or ideally JSON or XML parsers
• Ability to consume Java libraries
– Ideally Salesforce Web Service Connector
Basic Capabilities, limited RAM/CPU
Advanced Capabilities e.g. running OS’s
7. What does a Device need to call the Salesforce API’s?
• Common runtime language
– Such as Java!
• Oracle port to ARMv5 process running on Lego Mindstorms EV3
• Community Java runtime known as Lejos for Lego Mindstorms NXT
8. How intelligent should the device be?
• Processing power and storage can vary
– Depends on sensor input and output demands
– Cloud based logic can be used via HTTPS communications
– HTTPS communications
• Streaming communications vs Polling
• Ability to connect locally to the device is useful
– Lego Mindstorms EV3 runs a Lego variation of Linux
– Can TELNET to it and execute Unix commands
– Java Remote Debug is also possible
9. LEGO Mindstorms EV3 Programmable Brick
Feature Spec
Display Monochrome LCD
178 x 128 pixels
Operating System Linux based
Main Processor 300 MH Texas Instruments Sitara
AM11808 (ARM9 core)
Main Memory 64 MB RAM, 16 MB Flash
USB Host Port Yes
WiFi Yes via USB Dongle
Bluetooth Yes
10. What is a Machine Cloud?
• A single place for machines to
communicate and share information
• Machines can communicate to us and
other machines across the world
• Can be used to store data
• Can perform calculations on behalf of
devices, with access to more
information, also easier maintenance
and updates to software
11. Introducing a Machine Cloud built with Salesforce1 Platform
Salesforce1
Mobile
Custom
Objects
REST and
Streaming
API’s
Connected
Applications
15. Ok so what just happened under the hood?
Salesforce
Streaming and
REST APIEV3 #1
ev3force.jar
Heroku
Connected App
EV3 Pairing REST API
EV3 #2
ev3force.jar
Custom
Objects
Commands
Commands
Pairing Pairing
16. You want to go further under the hood?
Salesforce
Streaming and
REST API
Heroku
Connected App
EV3 Pairing REST API
EV3
2. Get Pin
3. Wait for PIN Entry and
receive oAuth Token
4. User Enters PIN, oAuth Token is passed
/ev3force.properties
5. EV3 stores oAuth Token
ev3force.jar
Custom
Objects
1. oAuth Token
stored?
First time ev3force.jar runs
Each time ev3force.jar runs
6. Read Robot Details
7. Start Listening
8. Create
Command records
23. Code: Listening for Commands via Streaming API
// Subscribe to the 'commands' topic to listen for new Command__c records
client.getChannel("/topic/commands").subscribe(new ClientSessionChannel.MessageListener()
{
public void onMessage(ClientSessionChannel channel, Message message)
{
HashMap<String, Object> data = (HashMap<String, Object>)
JSON.parse(message.toString());
HashMap<String, Object> record =
(HashMap<String, Object>) data.get("data");
HashMap<String, Object> sobject =
(HashMap<String, Object>) record.get("sobject");
String commandName = (String) sobject.get("Name");
String command = (String) sobject.get("Command__c");
String commandParameter = (String) sobject.get("CommandParameter__c");
String programToRunId = (String) sobject.get("ProgramToRun__c");
executeCommand(
commandName, command, commandParameter, programToRunId, partnerConnection);
}
});
24. Code: Moving the Robot around with Lejos
import lejos.hardware.motor.Motor;
public static void moveForward(int rotations)
{
Motor.B.rotate((180 * rotations)*1, true);
Motor.C.rotate((180 * rotations)*1, true);
while (Motor.B.isMoving() || Motor.C.isMoving());
Motor.B.flt(true);
Motor.C.flt(true);
}
public static void moveBackwards(int rotations)
{
Motor.B.rotate((180 * rotations)*-1, true);
Motor.C.rotate((180 * rotations)*-1, true);
while (Motor.B.isMoving() || Motor.C.isMoving());
Motor.B.flt(true);
Motor.C.flt(true);
}
25. Building your Lego Robot
• What do I need?
– Edimax EW-7811UN 150Mbps Wireless Nano USB Adapter
– Micro SD Card (SDHC Only), 1GB, no greater than 32GB
– Lego Mindstorms EV3 Set, Gripper Robot!
26. Creating your own Lego Robot Machine Cloud!
• Installation in Salesforce
– Install the Machine Cloud managed package (see Readme)
• https://github.com/afawcett/legoev3-machinecloud
• Installation on Lego Mindstorms EV3
1. Install Lejos on your SDCard and install in the EV3
• http://sourceforge.net/p/lejos/wiki/Home/
2. Use the Lejos menu on the EV3 to connect to your Wifi
3. Copy the ev3force.jar to your EV3 Robot (from /dist folder in GitHub Repo)
• Run the /bin/ev3console UI and deploy using the Programs tab
27. Creating your own Lego Robot Machine Cloud!
• Connecting your Robots
1. Run the ev3force.jar application on the EV3
2. Note the PIN number shown on the EV3 Robot
3. Login to your Salesforce org and create a Robot record
4. Enter PIN number, wait for the device to connect to Salesforce
5. Send it commands and programs to run!
28. Further Ideas…
• Expose the Machine Cloud via Salesforce Communities
• Machine Cloud API?
– Perhaps we already have this?
• Using the Salesforce API to insert records to the Command__c object?
• Add support for other Devices?
– Watches, Phones etc
• Add support for Generic Streaming API events
– Events not driven by Database events but by processes
29. Session Resources
• Follow the Session in the Dreamforce
App, I will share this slide deck and
other related links on the Feed
• Be social and feel free to ask follow up
questions!