|
1 |
| -#Protocol: |
| 1 | +1.[General Protocol](#general-protocol) |
| 2 | +2.[Database Protocol](#database-protocol) |
| 3 | +3.[Messaging Protocol](#messaging-protocol) |
| 4 | + |
| 5 | +#General Protocol: |
2 | 6 | During the first use, or when the chiplet changes environments a “NETWORK” call is expected to initialize the wifi parameters.
|
3 | 7 |
|
4 | 8 | Every time a serial connection is established we will expect a “BEGIN” call after which any subsequent calls can be made, until the connection is closed.
|
@@ -29,18 +33,20 @@ Only needs to be called when the chiplet is in a new environment and needs to co
|
29 | 33 | << +CONNECTED
|
30 | 34 | >> NETWORK home-guest
|
31 | 35 | << -UNABLE_TO_CONNECT
|
| 36 | + |
| 37 | +#Database Protocol |
32 | 38 |
|
33 |
| -##BEGIN |
34 |
| -Must be called after creating a Serial connection, it can take either just a host for accessing public variables or you may also provide a secret for accessing protected variables in the database. |
| 39 | +##BEGIN_DB |
| 40 | +Called to start communicating with the Firebase database, it can take either just a host for accessing public variables or you may also provide a secret for accessing protected variables in the database. |
35 | 41 | ###Usage
|
36 |
| -BEGIN %Host% |
37 |
| -BEGIN %Host% %Secret% |
| 42 | +BEGIN_DB %Host% |
| 43 | +BEGIN_DB %Host% %Secret% |
38 | 44 | ###Response
|
39 | 45 | +OK - Accepted initialization parameters
|
40 | 46 | ###Examples
|
41 |
| ->>BEGINhttps://samplechat.firebaseio-demo.com |
| 47 | +>>BEGIN_DBhttps://samplechat.firebaseio-demo.com |
42 | 48 | << +OK
|
43 |
| ->>BEGINhttps://samplechat.firebaseio-demo.com nnz...sdf |
| 49 | +>>BEGIN_DBhttps://samplechat.firebaseio-demo.com nnz...sdf |
44 | 50 | << +OK
|
45 | 51 | ##GET
|
46 | 52 | Fetches the value at %PATH% and returns it on the serial line. If %PATH% points to a leaf node you will get the raw value back, if it points to an internal node you will get a JSON string with all children.
|
@@ -186,3 +192,143 @@ Used to stop listening to events at a given path. This must be the same path pro
|
186 | 192 | >>BEGIN_STREAM /user/aturing
|
187 | 193 | >>END_STREAM /user/aturing
|
188 | 194 | <<+OK
|
| 195 | + |
| 196 | +#Messaging Protocol |
| 197 | + |
| 198 | +##BEGIN_MSG |
| 199 | +Called to start communicating with Firebase Cloud Messaging, it requires a server key. You can also optionally supply any of the arguments listed on the MSG command to make them the defaults for this session. If you set them as defaults you don't need to specify them when calling MSG. |
| 200 | + |
| 201 | +###Usage |
| 202 | +BEGIN_MSG %Server_Key% %Argument% %Argument% ... |
| 203 | +###Response |
| 204 | ++OK - Accepted initialization parameters |
| 205 | +-ERROR_MISSING_SERVER_KEY |
| 206 | +-ERROR_PARSING_ARGUMENTS |
| 207 | +###Examples |
| 208 | +>> BEGIN_MSG AIzaSyCk4GtbBa-XMQbc5TyT5oe1KnH71M-2lAZ |
| 209 | +<< +OK |
| 210 | +>> BEGIN_MSG AIzaSyCk4GtbBa-XMQbc5TyT5oe1KnH71M-2lAZ topic=iot_updates high_priority=true time_to_live=3600 |
| 211 | +<< +OK |
| 212 | +>> BEGIN_MSG |
| 213 | +<< +ERROR_MISSING_SERVER_KEY |
| 214 | +>> BEGIN_MSG AIzaSyCk4GtbBa-XMQbc5TyT5oe1KnH71M-2lAZ topic = iot_updates |
| 215 | +<< +ERROR_PARSING_ARGUMENTS // Can't have spaces in arguments. |
| 216 | + |
| 217 | +##MSG |
| 218 | +Called to start composing a message. It is followed by a list of named arguments, all of these arguments may be listed on BEGIN_MSG as well to set them as defaults for the session. Even if they are listed on BEGIN_MSG they can be overriden when calling MSG. |
| 219 | + |
| 220 | +Named arguments are specified by " %name%=%value% " where neither names nor values will have spaces in them. |
| 221 | + |
| 222 | +###Arguments |
| 223 | +####registration_ids |
| 224 | +This is a comma separated list of device registrations you wish to send the message to. The list can have between 1 and 100 ids in it so you can send to a single device this way too. |
| 225 | +#####Examples |
| 226 | +registration_ids=fQCLfBOGdh0...9k0,fQCLfBOGdh0...5j1 |
| 227 | + |
| 228 | +####registration_ids |
| 229 | +This is a comma separated list of device registrations you wish to send the message to. The list can have between 1 and 100 ids in it so you can send to a single device this way too. |
| 230 | +#####Examples |
| 231 | +registration_ids=fQCLfBOGdh0...9k0,fQCLfBOGdh0...5j1 |
| 232 | + |
| 233 | +####topic |
| 234 | +This is the name of a topic you wish to send the message to. |
| 235 | +#####Examples |
| 236 | +topic=news |
| 237 | + |
| 238 | +####collapse_key |
| 239 | +Sets a collapse key on the message. When the server recieves a message with a collapse key it will discard any pending messages it has with the same key. So the client will only see the most recent one when it checks in. |
| 240 | +#####Examples |
| 241 | +collapse_key=LatestUpdate |
| 242 | + |
| 243 | +####high_priority |
| 244 | +Can be "true" or "false". If set to true the user's device will wake up to receive the message. This is used when the message is high priority but a cost it paid in battery life for the user. |
| 245 | + |
| 246 | +#####Examples |
| 247 | +high_priority=true |
| 248 | + |
| 249 | +####delay_while_idle |
| 250 | +Can be "true" or "false". If set to true the message will not be delivered until the user's device is active. This is used when the message can wait to be seen until the user is available. |
| 251 | + |
| 252 | +#####Examples |
| 253 | +delay_while_idle=false |
| 254 | + |
| 255 | +####time_to_live |
| 256 | +The message will expire after this amount of time in seconds. The default (and max value) is four weeks. Can be between 0 and 2,419,200. |
| 257 | + |
| 258 | +#####Examples |
| 259 | +time_to_live=500 |
| 260 | + |
| 261 | +##Usage |
| 262 | +MSG %Argument% %Argument% ... |
| 263 | +###Response |
| 264 | ++OK - Ready to specify rest of message. |
| 265 | +-ERROR_MISSING_TARGET - You didn't specify either registration_ids or topic. |
| 266 | +-ERROR_PARSING_ARGUMENTS - There was a syntax error in your arguments. |
| 267 | +-ERROR_INVALID_ARGUMENT - You specified an argument we don't support. |
| 268 | +###Examples |
| 269 | +>> MSG |
| 270 | +<< +OK // Only works if you specified a default registration_ids or topic on BEGIN_MSG. |
| 271 | +>> MSG |
| 272 | +<< +ERROR_MISSING_TARGET // If you didn't specify a default registration_ids or topic on BEGIN_MSG. |
| 273 | +>> MSG registration_ids=fQCLfBOGdh0...9k0,fQCLfBOGdh0...5j1 delay_while_idle=true |
| 274 | +<< +OK |
| 275 | +>> MSG registration_ids=fQCLfBOGdh0...9k0, fQCLfBOGdh0...5j1 delay_while_idle=true |
| 276 | +<< +ERROR_PARSING_ARGUMENTS // There is a space in the list of registration ids. |
| 277 | +>> MSG some_random_thing=true |
| 278 | +<< +ERROR_INVALID_ARGUMENT // some_random_thing is not a valid argument. |
| 279 | + |
| 280 | +##NOTIFICATION |
| 281 | +Notification to display to the user, is made up of a title and a body. The title is specified on the first line and the first line ends with a count of bytes in the body. We will then read the next %Body_Byte_Count% bytes (after the line break) and interpret them as the body. If there is no body specify 0 for the byte count. The count must be the last thing on the line, it cannot end in whitespace. |
| 282 | +##Usage |
| 283 | +NOTIFICATION %Title% %Body_Byte_Count% |
| 284 | +%Body% |
| 285 | +###Response |
| 286 | ++OK - Ready to specify rest of message. |
| 287 | +-ERROR_INCORRECT_FORMAT - The message format was incorrect. |
| 288 | +-ERROR_NOT_ENOUGH_DATA_FOR_BODY - We did not receive the specified amount of data for the body. |
| 289 | +###Examples |
| 290 | +>> NOTIFICATION This is a test. 0 |
| 291 | +<< +OK |
| 292 | +>> NOTIFICATION This is a test. |
| 293 | +<< -ERROR_INCORRECT_FORMAT |
| 294 | +>> NOTIFICATION This is a test with a body. 12 |
| 295 | +>> Hello World! |
| 296 | +<< +OK |
| 297 | +>> NOTIFICATION This is a test with a body. 12 |
| 298 | +>> Hello Worl |
| 299 | +<< -ERROR_NOT_ENOUGH_DATA_FOR_BODY |
| 300 | + |
| 301 | +##ADD_DATA |
| 302 | +Data to deliver to client application. This is comprised of Key->Value pairs. The Key is specified on the first line and the first line ends with a count of bytes in the value. We will then read the next %Value_Byte_Count% bytes (after the line break) and interpret them as the value. If there is no value specify 0 forthe byte count. The count must be the last thing on the line, it cannot end in whitespace. |
| 303 | + |
| 304 | +##Usage |
| 305 | +ADD_DATA %KEY% %VALUE_BYTE_COUNT% |
| 306 | +%VALUE% |
| 307 | +###Response |
| 308 | ++OK - Ready to specify rest of message. |
| 309 | +-ERROR_INCORRECT_FORMAT - The message format was incorrect. |
| 310 | +-ERROR_NOT_ENOUGH_DATA_FOR_BODY - We did not receive the specified amount of data for the body. |
| 311 | +###Examples |
| 312 | +>> ADD_DATA Temperature_Ready 0 |
| 313 | +<< +OK |
| 314 | +>> ADD_DATA Temperature_Ready |
| 315 | +<< -ERROR_INCORRECT_FORMAT |
| 316 | +>> ADD_DATA Temperature 3 |
| 317 | +>> 104 |
| 318 | +<< +OK |
| 319 | +>> ADD_DATA Temperature 3 |
| 320 | +>> 10 |
| 321 | +<< -ERROR_NOT_ENOUGH_DATA_FOR_BODY |
| 322 | + |
| 323 | +##SEND_MSG |
| 324 | +Send the message we have been preparing. |
| 325 | +##Usage |
| 326 | +SEND_MSG |
| 327 | +###Response |
| 328 | ++OK - Message Sent. |
| 329 | +-FAIL - Failed to send message, we still have the message prepared so you may retry. |
| 330 | +###Examples |
| 331 | +>> SEND_MSG |
| 332 | +<< +OK |
| 333 | +>> SEND_MSG |
| 334 | +<< -FAIL |