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.
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"); } } } }
March 8, 2013 at 1:39 pm
Think of the possibilities! How about voice control via Chatter?
March 8, 2013 at 2:35 pm
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.
March 14, 2013 at 7:32 pm
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!
March 14, 2013 at 7:44 pm
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! 😉
Pingback: Meanwhile….On BrickInTheCloud…It’s Alive! | andrewfawcett
March 14, 2013 at 11:45 pm
Nice! I wonder – could you have implemented a public web service on Force.com and skipped Heroku? See http://blogs.developerforce.com/developer-relations/2012/02/quick-tip-public-restful-web-services-on-force-com-sites.html
March 15, 2013 at 7:48 am
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!