Brick in the Cloud

The Lego Machine Cloud Project

Its alive! Lego Robot and Salesforce Chatter Demo

7 Comments

After a few late nights / mornings I finally got my second robot chatting with me via Salesforce Chatter! I chose to switch designs as it was easier to mount the Wifi sensor and move this robot around than the Alpha Rex. You cannot see it in the video but I was controlling it via the Chatter app on my iPhone, I took some screenshots after the video.

photo photo[1]

The NXC code I developed for this communicates to Salesforce via a custom Heroku RESTful Service. Which provides two services /command and /chat that wrap the Chatter API in something easier to code against in NXC. I’ll share the Java code for these  services in a later blog. In the meantime enjoy!

task main()
{
   SetSensorLight(S3, true);
   if (quickConnect(WB_PORT,"ssid",WB_SECURITY_WPA2,"pass"))
   {
    string lastCommand;
    while (true)
    {
     string command = quickGETHostname(WB_PORT,"brickinthecloud.herokuapp.com","/services/command");
     if (command!="") {
       TextOut(0,LCD_LINE1, "Cmd:" + command + "      " );
       if(strcmp(command, lastCommand)!=0)
       {
          string message = "Afirmative!";
          if(strcmp(command, "Status?")==0)
          {
             float volts = BatteryLevel() / 1000.0;
             message = FormatNum("Battery:%5.3f", volts);
          }
          else if(strcmp(command, "Take aim!")==0)
          {
             RotateMotor(OUT_B, 180, 180);
             RotateMotor(OUT_C, 180, 180);
          }
          else if(strcmp(command, "Fire!")==0)
          {
             RotateMotor(OUT_A, 360, 360);
          }
          else if(strcmp(command, "Light on!")==0)
          {
             SetSensorColorRed(S3);
          }
          else if(strcmp(command, "Light off!")==0)
          {
             SetSensorColorNone(S3);
          }
          string response = quickGETHostname(WB_PORT,"brickinthecloud.herokuapp.com","/services/chat?message=" + message + "&comment=true");
          TextOut(0,LCD_LINE1, "Response:" + response + "      " );
          strcpy(lastCommand, command);
       }
     }
     else {
       TextOut(0,LCD_LINE1,"GET ERROR");
     }
    }
   }
}

7 thoughts on “Its alive! Lego Robot and Salesforce Chatter Demo

  1. Think of the possibilities! How about voice control via Chatter?

  2. Now thats a great idea, there are so many sensors for this thing the possibilities are only limited by ones imagination! I do plan plan to make it respond more to its environment as well and make Chatter posts to ask for help or decisions on what to do for example.

    • I’ve had a similar idea for a while – having the sensors report back data to be stored in Salesforce, from which you could then do reporting and analytics. Great job!

      • Yes indeed, what I’ve shown here is just the tip of the iceberg on possibilities, quite looking forward see it get its own voice and interact, rather than just follow commands. Hopefully something more this weekend! 😉

  3. Pingback: Meanwhile….On BrickInTheCloud…It’s Alive! | andrewfawcett

    • Unfortunately the WifiBlock firmware does not appear to support HTTPS, I’ve yet to confirm this though. In the meantime I wanted to get something hooked up. I actually tried to create something via Force.com Site’s but of course I cannot update Chatter Feeds from this context. However I didn’t know about this trick and will give it a go. I agree, would be nice to remove the Heroku aspect and go direct. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s