You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-1Lines changed: 83 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# BB8 Commander
2
-
A Node CLI Tool for Sphero BB8 Robot.
2
+
A Node CLI Tool for Sphero BB8 Robot using the [Sphero Javascript SDK](http://sdk.sphero.com/community-apis/javascript-sdk/)
3
3
4
4

5
5
@@ -20,6 +20,88 @@ Not yet on npm so you'll have to do it the good'ol fasioned way with a cheeky gi
20
20
*`node index.js disco` - Command to turn your BB8 Unit into a shining disco ball in the night
21
21
*`node index.js weather --city="manchester" --country="uk" --api-key="ABCD"` - Command to turn your BB8 Unit into your very own weather reporter, uses OpenWeather so be sure to get your own API key
22
22
*`node index.js tweet --hash-tag="bb8" --delay=5000` - Command to search twitter and run the first hashtag it finds as a command. Eg a tweet "#disco #bb8" would run the `disco` command --consumer-key xxx --consumer-secret xxx --access-token-key xxx --access-token-secret xxx
23
+
*`node index.js express --port=4000` - Command to run an express server which has a single POST endpoint which you can send a JSON object to. See below for more details.
24
+
25
+
### Express Server
26
+
27
+
Having the ability to run an Express server to issue commands to the BB8 unit opens up a bunch of possibilities. One of the main benefits of having an Express server is that you can integrate into [IFTTT](https://ifttt.com/) and at that point, you have entered the Internet of things.
28
+
29
+
To get started is really easy, all you need to do is run `node index.js express --port=4000` adn once your BB8 is connected, an Express server will be started.
30
+
31
+
You can then send commands directly to it via a POST request. It supports any SpheroSDK command as well as custom commands we have created. See below for some examples.
32
+
33
+
### Native Commands
34
+
35
+
With native commands, the response body will include information the BB8 exposes once that command has been executed. Read the Sphero documentation on what data it returns. http://sdk.sphero.com/community-apis/javascript-sdk/
36
+
37
+
#### Running the `color` command
38
+
39
+
Post Request - localhost:3000/
40
+
41
+
Request Body
42
+
43
+
```
44
+
{
45
+
"mode":"sphero",
46
+
"command":"color",
47
+
"value": "yellow"
48
+
}
49
+
```
50
+
51
+
#### Running the `roll` command
52
+
53
+
Post Request - localhost:3000/
54
+
55
+
Request Body
56
+
57
+
```
58
+
{
59
+
"mode":"sphero",
60
+
"command":"roll",
61
+
"value": [130, 50]
62
+
}
63
+
```
64
+
65
+
With this request, we are passing an array and that's because the roll command in Sphero SDK requires multiple parameters. This is just a simple way to pass those values to that command.
66
+
67
+
### Custom Commands
68
+
69
+
#### Running the `disco` command
70
+
71
+
Post Request - localhost:3000/
72
+
73
+
Request Body
74
+
75
+
```
76
+
{
77
+
"mode":"custom",
78
+
"command":"disco"
79
+
}
80
+
```
81
+
82
+
#### Running the `tweet` command
83
+
84
+
POST Request - localhost:3000/
85
+
86
+
Request Body
87
+
88
+
```
89
+
{
90
+
"mode":"custom",
91
+
"command":"tweet",
92
+
"value": {
93
+
"delay": 30,
94
+
"consumerKey": "YOUR_CONSUMER_KEY",
95
+
"consumerSecret": "YOUR_CONSUMER_SECRET",
96
+
"accessTokenKey": "YOUR_ACCESS_TOKEN_KEY",
97
+
"accessTokenSecret": "YOUR_ACCESS_TOKEN_SECRET"
98
+
}
99
+
}
100
+
```
101
+
102
+
Obviously you wouldn’t pass your OAuth information like this (BB8 Commander supports environment variables for secure data) but the important thing to note here is, anything that can be passed to the CLI tool can also be passed into the express server endpoint.
103
+
104
+
A suite difference between native commands and custom commands is that native commands that require multiple parameters will be passed as an array whilst custom commands will be objects. The reason for this is custom commands are key value pairs due to them sharing the same code as the CLI tool.
0 commit comments