-
Notifications
You must be signed in to change notification settings - Fork 492
Add serial protocol #59
Changes from 35 commits
5c75177
eff6087
7bddea6
81788aa
04bdf6e
8557658
67f51e6
e323a1c
8a3a56c
6150e54
3d96c9c
d554f5d
246f2e8
d3da4e9
07c43db
ebb181b
51921e3
1b318b3
6297660
ecea516
6f30401
8dac3f3
b0d90d2
724fde5
1c422b9
fc6a0f4
9f146de
76c746c
c39e371
6ca12be
c485ef7
6be74cd
e8c9623
d9bdee6
6530949
f004ae5
bba8045
8ced4fb
e5570d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#Protocol: | ||
During the first use, or when the chiplet changes environments a “NETWORK” call is expected to initialize the wifi parameters. | ||
|
||
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. | ||
|
||
In the following examples we use $ to represent variables. For example $Host represents your firebase host. | ||
|
||
##Response Format Byte | ||
All responses will be prefixed with one of the following bytes signifying the response type. | ||
``` | ||
+ If response is ok and a raw string value. | ||
$ If response is ok, raw string value will be json formatted and prefixed by the byte count and a new line. | ||
: If response is ok and a number, this could be float or int. | ||
? If response is ok and a boolean value. | ||
- If response is an error | ||
``` | ||
##NETWORK | ||
Only needs to be called when the chiplet is in a new environment and needs to connect to a new network. This setting will be stored by the chiplet and persisted through power cycles. | ||
###Usage | ||
NETWORK $SSID | ||
NETWORK $SSID $PASSWORD | ||
###Response | ||
CONNECTED - When connected to new network | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be +CONNECTED :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on nvm, this is then correct in the example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
UNABLE_TO_CONNECT - When unable to connect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -UNABLE_TO_CONNECT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
###Examples | ||
>> NETWORK home-guest | ||
<< +CONNECTED | ||
>> NETWORK home-private MySecretPassword | ||
<< +CONNECTED | ||
>> NETWORK home-guest | ||
<< -UNABLE_TO_CONNECT | ||
|
||
##BEGIN | ||
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. | ||
###Usage | ||
BEGIN $Host | ||
BEGIN $Host $Secret | ||
###Response | ||
OK - Accepted initialization parameters | ||
###Examples | ||
>> BEGIN https://samplechat.firebaseio-demo.com | ||
<< +OK | ||
>> BEGIN https://samplechat.firebaseio-demo.com nnz...sdf | ||
<< +OK | ||
##GET | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Path/PATH` to match the "Usage"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
###Usage | ||
GET $PATH | ||
###Response | ||
$DATA_AT_PATH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the confusing part of using "$" for bulk strings. I am using it in all of the documentation to represent a variable (ala bash). So this should stay variable "DATA_AT_PATH" because we cannot say what type it will be. |
||
$JSON_DATA_BYTE_COUNT \n\r $JSON_DATA | ||
###Examples | ||
>>GET /user/aturing/first | ||
<<+Alan | ||
>>GET /user/aturing | ||
<<$39 | ||
<<{ "first" : "Alan", "last" : "Turing" } | ||
|
||
##GET{+,*,#,.,?,$} | ||
Same as GET but will either return the value in the format specified (by the format byte) or return an error. | ||
###Usage | ||
GET+ $PATH | ||
GET: $PATH | ||
GET? $PATH | ||
GET$ $PATH | ||
###Response | ||
$FORMATED_RESPONSE | ||
###Examples | ||
>>GET? /user/aturing/was_human | ||
<<?true | ||
>>GET? /user/aturing/first | ||
<<-ERROR_INCORRECT_FORMAT | ||
##SET | ||
Store the data provided at the path provided. This method should be used for simple strings and will assume the first newline is the end of the data. | ||
###Usage | ||
SET $PATH $DATA | ||
###Response | ||
+OK | ||
-FAIL | ||
###Examples | ||
>>SET /user/aturning/first Alan | ||
<<+OK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @proppy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might matter for server side value like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, interesting wasn't aware of .sv. I am still in favor of just a simple response but don't feel strongly either way. |
||
##SET$ | ||
Similar to SET above but used to write multiline strings or raw binary data. Data format is similar to the batch string ($) return type, we specify the $DATA_BYTE_COUNT on the same line as SET$ then a newline and all data. | ||
|
||
Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. | ||
###Usage | ||
SET$ $PATH $DATA_BYTE_COUNT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do you distinguish between:
Maybe we should put the size on a separate line to distinguish between the two.
and
Do we support typing the payload, so that you can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can distinguish because "SET" always ends at the first line break. "SET$" contains the length on the first line then follows with a variable length of bytes. You are right that we should probably support forcing a type on the value with SET{+,:,...}. We can probably guess pretty well but you should be able to override our guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should put $DATA_BYTE_COUNT on a separate line, that would make it match
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ok with that, it does make parsing and writing easier. |
||
$DATA | ||
###Response | ||
+OK | ||
-FAIL | ||
-FAIL_TIMEOUT | ||
###Examples | ||
>>SET /user/aturning/address 24 | ||
>>78 High Street, | ||
>>Hampton | ||
<<+OK | ||
|
||
##REMOVE | ||
Deletes the value located at the path provided. | ||
###Usage | ||
REMOVE $PATH | ||
###Response | ||
+OK | ||
-FAIL | ||
###Examples | ||
>>REMOVE /user/aturning | ||
<<+OK | ||
|
||
##PUSH | ||
Adds a value to the list located at the path provided and returns the key at which the new object is located. | ||
###Usage | ||
PUSH $PATH $DATA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PUSH$ is the version with a size prefix. |
||
###Response | ||
$KEY | ||
###Examples | ||
>>PUSH /user/aturning/login_timestamps 1455052043 | ||
<<+-K94eLnB0rAAvfkh_WC2 | ||
|
||
##PUSH$ | ||
Similar to PUSH but used to write multiline strings or raw binary data. Data format is similar to the batch string ($) return type, we specify the $DATA_BYTE_COUNT on the same line as SET$ then a newline and all data. However you are not required to json escape all of your data, that will be handled for you. | ||
|
||
Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. | ||
###Usage | ||
PUSH_BULK $PATH $DATA_BYTE_COUNT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we do the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is PUSH$ already, just he usage comment needs to be updated. |
||
$DATA | ||
###Response | ||
$KEY | ||
###Examples | ||
>>PUSH /user/aturning/quotes 91 | ||
>>We can only see a short distance ahead, | ||
>>but we can see plenty there that needs to be done. | ||
<<+-K94eLnB0rAAvfkh_WC3 | ||
|
||
##STREAM | ||
Used to register to receive a stream of events that occur to the object at the provided path. | ||
|
||
After registering you will start receiving events on the response line. They will be formatted as one line with the event type {PUT,PATCH,etc..} followed by the sub_path that changed and the other line with the data associated with that event type. This data will be formatted similar to GET results and can have multi-line batch strings (*) or json strings (&). | ||
|
||
The event stream will continue until you send CANCEL_STREAM. | ||
###Usage | ||
STREAM $PATH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. |
||
CANCEL_STREAM | ||
###Response | ||
$EVENT_NAME $SUB_PATH | ||
$DATA | ||
+OK | ||
###Examples | ||
>>STREAM /user/aturning | ||
<<+PUT /last_login | ||
<<:1455052043 | ||
<<+PUT /address | ||
<<$24 | ||
<<"78 High Street,\r\nHampton" | ||
>>CANCEL_STREAM | ||
<<+OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since
$
is already used in the protocol, maybe we should using a different delimeter for placeholder like%VALUE%
,[VALUE]
or<VALUE>