Sample code to control a BB-8 Droid from anywhere in the world
Suppose your Star Wars BB-8 droid is in Melbourne and you are in San Francisco. You are controlling the BB-8 from an internet browser from San Francisco!! Wouldn't it be nice?
This is a sample project to control a BB-8 Droid using MQTT, the IBM internet of Things Foundation, and the sphero.js, . This project also uses the MQTT wrapper from the parrot-sample.
You can control the color of the droid using a Node-RED flow. Sample flow has been included below. The summary of functionalities is:
- BB-8 will change color to Green when connected to IoTF via BLE compatible laptop.
- You can issue color change command
- You can issue run command and droid will run for 1.5 seconds and then randomly change color every second.
Running The Sample
Hardware
You will require the following devices for this demo.- A BB-8 Droid
- A laptop which supports BLE. The BB-8 will be connected to the laptop via BLE. BB-8 controller code will run on the laptop. I used a MacBook Pro (Retina, 15-inch, Mid 2014).
iot-2/cmd/run/fmt/json
topic.Getting The Code
$ git clone https://github.com/shamimshossain/bb8-bluemix.git
Pre-requisite tasks
Create an instance of Internet of Things Foundation from Bluemix catalog.From IoTF Dashboard, perform the following tasks.
- Click the Devices tab and click Add Device.
- Create a new Device Type called "sphero".
- In the Device ID field enter a unique ID for your drone.
- Click Continue
The IoTF service can not retrieve these authentication details for you later. So make sure to store these in a secure place
Next get API keys for your application.
- Click on the API Keys tab
- Click the New API Key link
- You will see a Key and Auth Token displayed.
The IoTF service can not retrieve these authentication details for you later. So make sure to store these in a secure place
In the root of the repository you cloned you will find a file named
sphero-config.properties
. Following is the content of the properties file.#Device ID you use when you register with the IoT foundation
deviceid=yourdroneid
#For controller (device)
authtoken=yourauthtoken
#For the app (publisher)
apikey=yourapikey
apitoken=yourapitoken
Replace the values of the deviceid, authtoken, apikey, and apitoken
with the values you got when creating the device and app in the IoT
Dashboard.Following is a screenshot of IoTF dashboard.
Set up the application to run from your laptop
- Open a terminal window,
cd
to the root of the repository, and runnpm install
to install all the dependencies. - Place your BB-8 near your BLE compatible laptop.
- Now start up the controller code by running
node spheroDemo.js
- Your BB-8 droid will be connected to IoTF via BLE compatible laptop and change color to green. You will see an output similar to following from the terminal.
**** Start debug info *****
Connected to BB-8
BB-8 is changing color to green to indicate that it is connected
**** End debug info *****
r6co3p.messaging.internetofthings.ibmcloud.com
Output of ping command
{ sop1: 255,
sop2: 255,
mrsp: 0,
seq: 0,
dlen: 1,
data: <Buffer >,
checksum: 254 }
End of ping data
MQTT client connected to IBM IoT Cloud.
Connected Sphero ID: spheroownedbyshamim
subscribed to iot-2/cmd/run/fmt/json
- You are now ready to create an Node-RED Starter app from Bluemix catalog.
Node-RED
- Bind the IoTF service created before to this app. The resultant application dashboard looks like the diagram above.
- Now copy the following Node-RED flow and import into Node-RED.
[{"id":"180c60f4.e7f39f","type":"ibmiot out","z":"5fa8453c.a057bc","authentication":"boundService","apiKey":"","outputType":"cmd","deviceId":"spheroownedbyshamim","deviceType":"sphero","eventCommandType":"run","format":"json","data":"___","name":"IBM IoT App Out","service":"registered","x":756,"y":361,"wires":[]},{"id":"b7792b22.4886d8","type":"inject","z":"5fa8453c.a057bc","name":"Run command","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":206,"y":444,"wires":[["f29b07a3.0d64f8"]]},{"id":"f29b07a3.0d64f8","type":"function","z":"5fa8453c.a057bc","name":"Construct RUN command","func":"msg.payload = JSON.stringify({\n d: {\n action : \"#spherorun\"\n }\n});\nreturn msg;","outputs":1,"noerr":0,"x":468,"y":449,"wires":[["180c60f4.e7f39f","d1c575b9.2e3a88"]]},{"id":"d313ea30.2cec18","type":"inject","z":"5fa8453c.a057bc","name":"Change color to RED","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":205,"y":297,"wires":[["26e811fe.d917ee"]]},{"id":"26e811fe.d917ee","type":"function","z":"5fa8453c.a057bc","name":"Construct RED command","func":"msg.payload = JSON.stringify({\n d: {\n action : \"#red\"\n }\n});\nreturn msg;","outputs":1,"noerr":0,"x":473,"y":287,"wires":[["180c60f4.e7f39f","d1c575b9.2e3a88"]]},{"id":"61c2c549.9e3d3c","type":"inject","z":"5fa8453c.a057bc","name":"Change color to BLUE","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":193,"y":369,"wires":[["18100517.e7effb"]]},{"id":"18100517.e7effb","type":"function","z":"5fa8453c.a057bc","name":"Construct BLUE command","func":"msg.payload = JSON.stringify({\n d: {\n action : \"#blue\"\n }\n});\nreturn msg;","outputs":1,"noerr":0,"x":485,"y":363,"wires":[["180c60f4.e7f39f","d1c575b9.2e3a88"]]},{"id":"d1c575b9.2e3a88","type":"debug","z":"5fa8453c.a057bc","name":"","active":true,"console":"false","complete":"false","x":777,"y":286,"wires":[]}]
Once you have imported the flow you will need to double click on the
IBM IoT output node to open the configuration properties and replace the
device ID with the device ID you registered your drone with in Bluemix.
For example, replace spheroownedbyshamim
with your deviceid.This is how the flow looks like.
This comment has been removed by the author.
ReplyDeleteThanks for taking the time to read the tutorial. Could you please share the error messages you received?
DeleteHi,
DeleteI went through the tutorial once again. I've imported the Node-Red flow one more time. This time everything works fine. I suppose there was a problem with the communication between the IoT out node and IoT Foundation service. There were no errors, to find the bug. Logs of app were fine. Once more thank you for the tutorial and I'm looking forward to seeing some new ideas.
Loaded with superb and virtuosic words.Powerful is all that is in this blog.
ReplyDeleteaugmented reality
The compositions of this blog are sensational.
ReplyDeletejiotv
All the blog writings are demonstration of what we call, Brilliant.
ReplyDeleteclick here for thin bezel monitor guides
This blog gives a strong affirmation of outstanding composed work.
ReplyDeleteelectric wine opener
What is so great about this blog is its uniqueness.
ReplyDeleteexecutive chair
Might want to compliment the author for composing this perfect article
ReplyDeleteConsumerism Inc
Indeed, even the words like engaging and dazzling can't do full value concerning depicting this blog.
ReplyDeletelie detector test united kingdom
In this time of false love, the creator has formed each word with everything that is in him filled it.
ReplyDeletebest cell phone look up reviews
I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
ReplyDeletecharter speed test
Thanks for sharing the info, keep up the good work going.... I really enjoyed exploring your site. good resource...
ReplyDeleteMason Soiza
This comment has been removed by the author.
ReplyDeleteAmazing work. I bookmarked your webpage for future post. keep Sharing more post like this. Thank you so much. 192.168.l.l is pre-specified by the router companies as the default gateway address and can be used to make different changes to the router’s settings.
ReplyDeleteRecently, I have commenced a blog the info you give on this site has encouraged and benefited me hugely. Thanks for all of your time & work. laptops
ReplyDeleteVery interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one.
ReplyDeleteSpeed Test Charter net
Great survey, I'm sure you're getting a great response. https://itprospt.com/what-to-do-if-xinput1_3-dll-is-missing-windows-10/
ReplyDeleteLucky Lady Casino App | Download the latest Android
ReplyDeleteThis is a fun and safe place 양산 출장안마 to play 정읍 출장안마 and play casino games on your Android or iOS device. Lucky Lady 수원 출장샵 Casino is available for both 춘천 출장샵 iOS and Android 포천 출장샵
smm panel
ReplyDeletesmm panel
İs İlanlari
İnstagram Takipçi Satın Al
hirdavatci
beyazesyateknikservisi.com.tr
Servis
tiktok jeton hilesi indir