Blog

First Look at the MyRobots API

John Keogh | July 24, 2013

My last post was about using web services with robots and I recently read a post in the Linkedin group "Robotics Guru" about the new MyRobots.com cloud monitoring service from RobotShop (from whom I sometimes buy motors, wheels and casters). I'm interested in the development of APIs as it can shape the way that people think about how to approach solving a problem, and it's useful to keep up to date, particularly from companies with influence among technical people. The API is basically a simple front end to what looks like a key/value store, with three levels of privacy so that robots can be set up to share information with a larger or smaller set of entities. I've created a small app in Objective C that calls the API and updates and retrieves values from the key named "Field1". The code I have placed in the public domain.

Steps

  1. First go to MyRobots.com and sign up for an account
  2. Once you are in, you will be shown a dashboard, click on "Add Robot"
  3. For Robot Type, choose custom, the other fields use whatever values you prefer
  4. Next click on "Manage Robots", then on the robot you just created
  5. You will need the Robot ID and the API Key for the app, so make a note of them
  6. You may also want to click on the Channel Feed in JSON, which will show you your updates after you make them with the app
  7. Get the Objective-C code and fire up XCode

Code

You will need to replace the

const static NSString *kAPIKey = @"[Your API Key]";

const static NSString *kRobotId = @"[Your Robot ID]";

In MyRobotsTestViewController.h with the API key and Robot ID you got in the steps outlined above.

The code required is minimal. You can update and retrieve with just this code (several required supporting functions aren't included, see the project for the complete code):

-(IBAction)sendValue:(id)sender { NSString *valueToSend = [self encodeString:[self.valueToSendTextField text]]; NSString *updateURL = [NSString stringWithFormat:kRobotUpdateURLFormat, kAPIKey, valueToSend]; NSString *agentString = @"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1"; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:updateURL]]; [request setValue:agentString forHTTPHeaderField: @"User-Agent"]; NSError *error; [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: &error]; } -(IBAction)retrieveValue:(id)sender { NSString *retrievalURL = [NSString stringWithFormat:kRobotRetrieveURLFormat, kRobotId, kAPIKey]; NSDictionary *retrievedData = [self parseJSONFileAtURL:retrievalURL]; if(retrievedData!=nil){ //dump all keys and values to see what was returned for (id key in retrievedData) { NSLog(@"key: %@, value: %@", key, [retrievedData objectForKey:key]); } if([retrievedData valueForKey:@"feeds"]!=nil){ //just get the last item in the feeds, //it is the latest if([((NSArray *)[retrievedData valueForKey :@"feeds"]) count]>0) { NSDictionary *latestFeedItem = [((NSArray *)[retrievedData valueForKey:@"feeds"]) lastObject]; if(latestFeedItem!=nil){ if([latestFeedItem valueForKey:@"field1"] !=nil){ [self.retrievedValueLabel setText: [latestFeedItem valueForKey:@"field1"]]; } } } } } }

Screenshot of the app UI of the test app

Summary

Limited but very easy to use and appropriate for the problem they are trying to solve. I'll be looking at the business case for including this in my robots. The really interesting thing is the possibilities for robot to robot communications that this enables.

Eyesbot Company

Computer vision

Artificial intelligence

Effecting the physical world