From 5c75177cbd7695d13c59e1e7c6b1f95c4decf50c Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 2 Feb 2016 15:24:32 -0800 Subject: [PATCH 01/34] Create serial_protocol.md Initial copy from google doc --- serial_protocol.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 serial_protocol.md diff --git a/serial_protocol.md b/serial_protocol.md new file mode 100644 index 00000000..2f42e2f3 --- /dev/null +++ b/serial_protocol.md @@ -0,0 +1,42 @@ +#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 “INIT” 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. +##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 + OK - When connected to new network + FAIL - When unable to connect +###Examples + >> NETWORK home-guest + << OK + >> NETWORK home-private MySecretPassword + << OK + +##Init +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 + INIT $Host + INIT $Host $Secret +###Response + OK - Accepted initialization parameters +###Examples + >> INIT https://samplechat.firebaseio-demo.com + << OK + >> INIT https://samplechat.firebaseio-demo.com nnz...sdf + << OK +##Get +Fetches the value at $Path and returns it on the serial line. +###Usage + GET $Path +###Response + OK +##Set +##Push +##Remove +##Stream From eff608796c3f6702304d5ad49d6a5b312a437c94 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 2 Feb 2016 16:36:07 -0800 Subject: [PATCH 02/34] Update serial_protocol.md --- serial_protocol.md | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 2f42e2f3..2a47be1b 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -4,7 +4,7 @@ During the first use, or when the chiplet changes environments a “NETWORK” c Every time a serial connection is established we will expect a “INIT” 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. -##Network +##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 @@ -18,7 +18,7 @@ Only needs to be called when the chiplet is in a new environment and needs to co >> NETWORK home-private MySecretPassword << OK -##Init +##INIT 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 INIT $Host @@ -30,12 +30,31 @@ Must be called after creating a Serial connection, it can take either just a hos << OK >> INIT https://samplechat.firebaseio-demo.com nnz...sdf << OK -##Get -Fetches the value at $Path and returns it on the serial line. +##GET +Fetches the value, in json, at $Path and returns it on the serial line. ###Usage - GET $Path + GET $PATH ###Response - OK + $SIZE_OF_DATA $DATA +###Examples + >>GET /user/aturing + <<39 { "first" : "Alan", "last" : "Turing" } + +##GET_VALUE +Fetches the value stored $Path and returns it on the serial line. $PATH must point to a leaf node in the tree as this call returns one value but does so without json wrapper. +###Usage + GET_VALUE $PATH +###Response + $SIZE_OF_DATA_IN_BYTES $DATA + ERROR_NOT_LEAF_NODE +###Examples + >>GET_VALUE /user/aturing/first + <<4 Alan + >>GET_VALUE /user/aturing/last + <<7 Turing + >>GET_VALUE /user/aturing + < Date: Tue, 2 Feb 2016 16:41:46 -0800 Subject: [PATCH 03/34] Update serial_protocol.md --- serial_protocol.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 2a47be1b..015c10d6 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -35,7 +35,7 @@ Fetches the value, in json, at $Path and returns it on the serial line. ###Usage GET $PATH ###Response - $SIZE_OF_DATA $DATA + $DATA_BYTE_COUNT $DATA ###Examples >>GET /user/aturing <<39 { "first" : "Alan", "last" : "Turing" } @@ -45,7 +45,7 @@ Fetches the value stored $Path and returns it on the serial line. $PATH must poi ###Usage GET_VALUE $PATH ###Response - $SIZE_OF_DATA_IN_BYTES $DATA + $DATA_BYTE_COUNT $DATA ERROR_NOT_LEAF_NODE ###Examples >>GET_VALUE /user/aturing/first From 81788aa7a81e76259dab83409ee2ba3f9e3ecd8a Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Wed, 3 Feb 2016 15:03:39 -0800 Subject: [PATCH 04/34] Update serial_protocol.md remove GET_VALUE --- serial_protocol.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 015c10d6..2d9099b6 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -31,29 +31,18 @@ Must be called after creating a Serial connection, it can take either just a hos >> INIT https://samplechat.firebaseio-demo.com nnz...sdf << OK ##GET -Fetches the value, in json, at $Path and returns it on the serial line. +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. ###Usage GET $PATH ###Response $DATA_BYTE_COUNT $DATA -###Examples - >>GET /user/aturing - <<39 { "first" : "Alan", "last" : "Turing" } - -##GET_VALUE -Fetches the value stored $Path and returns it on the serial line. $PATH must point to a leaf node in the tree as this call returns one value but does so without json wrapper. -###Usage - GET_VALUE $PATH -###Response - $DATA_BYTE_COUNT $DATA - ERROR_NOT_LEAF_NODE ###Examples >>GET_VALUE /user/aturing/first <<4 Alan >>GET_VALUE /user/aturing/last <<7 Turing >>GET_VALUE /user/aturing - < Date: Wed, 3 Feb 2016 15:57:58 -0800 Subject: [PATCH 05/34] Update serial_protocol.md --- serial_protocol.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 2d9099b6..3a6eda62 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -37,11 +37,11 @@ Fetches the value at $Path and returns it on the serial line. If $PATH points to ###Response $DATA_BYTE_COUNT $DATA ###Examples - >>GET_VALUE /user/aturing/first + >>GET /user/aturing/first <<4 Alan - >>GET_VALUE /user/aturing/last + >>GET /user/aturing/last <<7 Turing - >>GET_VALUE /user/aturing + >>GET /user/aturing <<39 { "first" : "Alan", "last" : "Turing" } ##Set From 85576587cfea65c08adc168552145c03edfc4410 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Wed, 3 Feb 2016 16:32:03 -0800 Subject: [PATCH 06/34] Update serial_protocol.md --- serial_protocol.md | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 3a6eda62..88f7a082 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -4,19 +4,30 @@ During the first use, or when the chiplet changes environments a “NETWORK” c Every time a serial connection is established we will expect a “INIT” 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 value + $ If response is ok and a raw value prefixed by count of bytes in response. + & If response is ok and json formatted + ! 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 - OK - When connected to new network - FAIL - When unable to connect + CONNECTED - When connected to new network + UNABLE_TO_CONNECT - When unable to connect ###Examples >> NETWORK home-guest - << OK + << +CONNECTED >> NETWORK home-private MySecretPassword - << OK + << +CONNECTED + >> NETWORK home-guest + << !UNABLE_TO_CONNECT ##INIT 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. @@ -27,23 +38,35 @@ Must be called after creating a Serial connection, it can take either just a hos OK - Accepted initialization parameters ###Examples >> INIT https://samplechat.firebaseio-demo.com - << OK + << +OK >> INIT https://samplechat.firebaseio-demo.com nnz...sdf - << OK + << +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. ###Usage GET $PATH ###Response - $DATA_BYTE_COUNT $DATA + $DATA_AT_PATH ###Examples >>GET /user/aturing/first - <<4 Alan + <<+Alan >>GET /user/aturing/last - <<7 Turing + <<+Turing >>GET /user/aturing - <<39 { "first" : "Alan", "last" : "Turing" } + <<&{ "first" : "Alan", "last" : "Turing" } +##GET_BULK +Same as GET but returns value with size prefix. useful when value is expected to be large so you can know the size before accepting value. +Also only returns values at leaf nodes, if called on internal node returns error. +###Usage + GET_BULK $PATH +###Response + $DATA_BYTE_COUNT $DATA_AT_PATH +###Examples + >>GET_BULK /user/aturing/first + <<$4 Alan + >>GET /user/aturing + < Date: Wed, 3 Feb 2016 16:44:09 -0800 Subject: [PATCH 07/34] Update serial_protocol.md --- serial_protocol.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 88f7a082..f873c0d9 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -9,8 +9,9 @@ In the following examples we use $ to represent variables. For example $Host rep All responses will be prefixed with one of the following bytes signifying the response type. ``` + If response is ok and a raw value - $ If response is ok and a raw value prefixed by count of bytes in response. + * If response is ok and a raw value prefixed by count of bytes in response. & If response is ok and json formatted + $ If response is ok and json formatted and prefixed by count of bytes in response. ! If response is an error ``` ##NETWORK @@ -64,9 +65,9 @@ Also only returns values at leaf nodes, if called on internal node returns error $DATA_BYTE_COUNT $DATA_AT_PATH ###Examples >>GET_BULK /user/aturing/first - <<$4 Alan + <<*4 Alan >>GET /user/aturing - < Date: Wed, 3 Feb 2016 16:50:16 -0800 Subject: [PATCH 08/34] Update serial_protocol.md --- serial_protocol.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index f873c0d9..a547e231 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -51,8 +51,6 @@ Fetches the value at $Path and returns it on the serial line. If $PATH points to ###Examples >>GET /user/aturing/first <<+Alan - >>GET /user/aturing/last - <<+Turing >>GET /user/aturing <<&{ "first" : "Alan", "last" : "Turing" } @@ -67,7 +65,7 @@ Also only returns values at leaf nodes, if called on internal node returns error >>GET_BULK /user/aturing/first <<*4 Alan >>GET /user/aturing - <<$38 { "first" : "Alan", "last" : "Turing" } + <<$39 { "first" : "Alan", "last" : "Turing" } ##Set ##Push ##Remove From 8a3a56c08ce2996eff3654d7b0fa0cc322376d76 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Thu, 4 Feb 2016 13:44:43 -0800 Subject: [PATCH 09/34] Update serial_protocol.md --- serial_protocol.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index a547e231..5b615ceb 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -8,11 +8,13 @@ In the following examples we use $ to represent variables. For example $Host rep ##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 value - * If response is ok and a raw value prefixed by count of bytes in response. - & If response is ok and json formatted - $ If response is ok and json formatted and prefixed by count of bytes in response. - ! If response is an error + + If response is ok and a raw string value. + * If response is ok and a raw string value prefixed by count of bytes in response then new line. + # If response is ok and a integer value. + . If response is ok and a float value. + $ If response is ok and a boolean value. + & If response is ok and json formatted and prefixed by count of bytes in response then new line. + - 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. @@ -28,7 +30,7 @@ Only needs to be called when the chiplet is in a new environment and needs to co >> NETWORK home-private MySecretPassword << +CONNECTED >> NETWORK home-guest - << !UNABLE_TO_CONNECT + << -UNABLE_TO_CONNECT ##INIT 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. @@ -48,11 +50,13 @@ Fetches the value at $Path and returns it on the serial line. If $PATH points to GET $PATH ###Response $DATA_AT_PATH + $JSON_DATA_BYTE_COUNT \n\r $JSON_DATA ###Examples >>GET /user/aturing/first <<+Alan >>GET /user/aturing - <<&{ "first" : "Alan", "last" : "Turing" } + <<&39 + <<{ "first" : "Alan", "last" : "Turing" } ##GET_BULK Same as GET but returns value with size prefix. useful when value is expected to be large so you can know the size before accepting value. @@ -63,9 +67,11 @@ Also only returns values at leaf nodes, if called on internal node returns error $DATA_BYTE_COUNT $DATA_AT_PATH ###Examples >>GET_BULK /user/aturing/first - <<*4 Alan + <<*4 + <>GET /user/aturing - <<$39 { "first" : "Alan", "last" : "Turing" } + <<$39 + <<{ "first" : "Alan", "last" : "Turing" } ##Set ##Push ##Remove From 6150e54c33193defd82662613f0ef25fa3eaa86b Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 10:49:48 -0800 Subject: [PATCH 10/34] Update serial_protocol.md --- serial_protocol.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 5b615ceb..c777257a 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -12,8 +12,8 @@ All responses will be prefixed with one of the following bytes signifying the re * If response is ok and a raw string value prefixed by count of bytes in response then new line. # If response is ok and a integer value. . If response is ok and a float value. - $ If response is ok and a boolean value. - & If response is ok and json formatted and prefixed by count of bytes in response then new line. + ? If response is ok and a boolean value. + $ If response is ok and json formatted and prefixed by count of bytes in response then new line. - If response is an error ``` ##NETWORK From 3d96c9c5c42e8343af54e42902479610ceeb039d Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 10:53:40 -0800 Subject: [PATCH 11/34] Update serial_protocol.md --- serial_protocol.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index c777257a..bfc06776 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -12,8 +12,8 @@ All responses will be prefixed with one of the following bytes signifying the re * If response is ok and a raw string value prefixed by count of bytes in response then new line. # If response is ok and a integer value. . If response is ok and a float value. - ? If response is ok and a boolean value. - $ If response is ok and json formatted and prefixed by count of bytes in response then new line. + $ If response is ok and a boolean value. + & If response is ok and json formatted and prefixed by count of bytes in response then new line. - If response is an error ``` ##NETWORK @@ -58,20 +58,22 @@ Fetches the value at $Path and returns it on the serial line. If $PATH points to <<&39 <<{ "first" : "Alan", "last" : "Turing" } -##GET_BULK -Same as GET but returns value with size prefix. useful when value is expected to be large so you can know the size before accepting value. -Also only returns values at leaf nodes, if called on internal node returns error. +##GET{+,*,#,.,?,$} +Same as GET but will either return the value in the format specified (by the format byte) or return an error. ###Usage - GET_BULK $PATH + GET+ $PATH + GET* $PATH + GET# $PATH + GET. $PATH + GET? $PATH + GET$ $PATH ###Response - $DATA_BYTE_COUNT $DATA_AT_PATH + $FORMATED_RESPONSE ###Examples - >>GET_BULK /user/aturing/first - <<*4 - <>GET /user/aturing - <<$39 - <<{ "first" : "Alan", "last" : "Turing" } + >>GET? /user/aturing/was_human + <>GET? /user/aturing/first + <<-ERROR_INCORRECT_FORMAT ##Set ##Push ##Remove From d554f5d90468cf44cc218b4b744d3e680488300f Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 11:21:06 -0800 Subject: [PATCH 12/34] Update serial_protocol.md --- serial_protocol.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/serial_protocol.md b/serial_protocol.md index bfc06776..26fffc40 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -75,6 +75,29 @@ Same as GET but will either return the value in the format specified (by the for >>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 +##SET_BULK +Similar to SET above but used to write multiline strings or raw data. + +Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. +###Usage + SET_BULK $PATH $DATA_BYTE_COUNT $DATA +###RESPONSE + +OK + -FAIL + -FAIL_TIMEOUT +###Examples + >>SET /user/aturning/address 23 78 High Street, + >>Hampton + <<+OK ##Push ##Remove ##Stream From 246f2e8f896c8adfd3de13cf55cbf9f5a308cd56 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 11:29:14 -0800 Subject: [PATCH 13/34] Update serial_protocol.md --- serial_protocol.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 26fffc40..17fbcbda 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -78,7 +78,7 @@ Same as GET but will either return the value in the format specified (by the for 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 +###Response +OK -FAIL ###Examples @@ -90,7 +90,7 @@ Similar to SET above but used to write multiline strings or raw data. Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. ###Usage SET_BULK $PATH $DATA_BYTE_COUNT $DATA -###RESPONSE +###Response +OK -FAIL -FAIL_TIMEOUT @@ -98,6 +98,17 @@ Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of >>SET /user/aturning/address 23 78 High Street, >>Hampton <<+OK -##Push + ##Remove +Deletes the value located at the path provided. +###Usage + REMOVE $PATH +###Response + +OK + -FAIL +###Examples + >>REMOVE /user/aturning + <<+OK + +##Push ##Stream From d3da4e9ecf84711ebe00b599161df3e62aea3ad2 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:16:14 -0800 Subject: [PATCH 14/34] Update serial_protocol.md --- serial_protocol.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 17fbcbda..e535758f 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -85,7 +85,7 @@ Store the data provided at the path provided. This method should be used for sim >>SET /user/aturning/first Alan <<+OK ##SET_BULK -Similar to SET above but used to write multiline strings or raw data. +Similar to SET above but used to write multiline strings or raw binary data. Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. ###Usage @@ -99,7 +99,7 @@ Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of >>Hampton <<+OK -##Remove +##REMOVE Deletes the value located at the path provided. ###Usage REMOVE $PATH @@ -110,5 +110,25 @@ Deletes the value located at the path provided. >>REMOVE /user/aturning <<+OK -##Push +##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 +###Response + $KEY +###Examples + >>PUSH /user/aturning/login_timestamps 1455052043 + <<+-K94eLnB0rAAvfkh_WC2 +##Push_BULK +Similar to PUSH but used to write multiline strings or raw binary data. + +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 $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 From 07c43db8b241399082cf3ca5c04d661887289866 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:42:01 -0800 Subject: [PATCH 15/34] Update serial_protocol.md --- serial_protocol.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index e535758f..56113681 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -119,16 +119,38 @@ Adds a value to the list located at the path provided and returns the key at whi ###Examples >>PUSH /user/aturning/login_timestamps 1455052043 <<+-K94eLnB0rAAvfkh_WC2 -##Push_BULK + +##PUSH_BULK Similar to PUSH but used to write multiline strings or raw binary data. 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 $DATA + PUSH_BULK $PATH $DATA_BYTE_COUNT $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 + +##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..} 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 + CANCEL_STREAM +###Response + $EVENT_NAME + $DATA + +OK +###Examples + >>STREAM /user/aturning/last_login + <<+PUT + <<#1455052043 + <<+PUT + <<#1455054063 + >>CANCEL_STREAM + <<+OK From ebb181b018a2c522c2b8a0e340d1abc1fcebca47 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:45:19 -0800 Subject: [PATCH 16/34] Update serial_protocol.md --- serial_protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial_protocol.md b/serial_protocol.md index 56113681..6bbd054e 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -74,7 +74,7 @@ Same as GET but will either return the value in the format specified (by the for <>GET? /user/aturing/first <<-ERROR_INCORRECT_FORMAT -##Set +##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 From 51921e3cfd64fe670c2f3e32fe0d5eea0488529b Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:48:29 -0800 Subject: [PATCH 17/34] Update serial_protocol.md --- serial_protocol.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 6bbd054e..822aa9ca 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -136,21 +136,21 @@ Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of ##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..} 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 (&). +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 CANCEL_STREAM ###Response - $EVENT_NAME + $EVENT_NAME $SUB_PATH $DATA +OK ###Examples - >>STREAM /user/aturning/last_login - <<+PUT + >>STREAM /user/aturning + <<+PUT /last_login <<#1455052043 - <<+PUT + <<+PUT /last_login <<#1455054063 >>CANCEL_STREAM <<+OK From 1b318b3200537464d5ae691b6c69bdfa84d16f6b Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:50:16 -0800 Subject: [PATCH 18/34] Update serial_protocol.md --- serial_protocol.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 822aa9ca..0c7e5e95 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -95,7 +95,7 @@ Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of -FAIL -FAIL_TIMEOUT ###Examples - >>SET /user/aturning/address 23 78 High Street, + >>SET /user/aturning/address 24 78 High Street, >>Hampton <<+OK @@ -150,7 +150,8 @@ The event stream will continue until you send CANCEL_STREAM. >>STREAM /user/aturning <<+PUT /last_login <<#1455052043 - <<+PUT /last_login - <<#1455054063 + <<+PUT /address + <<*24 78 High Street, + >>Hampton >>CANCEL_STREAM <<+OK From 629766093f4a7b483688e17a64abc3f056de82d0 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:50:39 -0800 Subject: [PATCH 19/34] Update serial_protocol.md --- serial_protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial_protocol.md b/serial_protocol.md index 0c7e5e95..44005045 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -152,6 +152,6 @@ The event stream will continue until you send CANCEL_STREAM. <<#1455052043 <<+PUT /address <<*24 78 High Street, - >>Hampton + <>CANCEL_STREAM <<+OK From ecea516a24a6118bb6f426f53c05ed95d5c6c77f Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:51:27 -0800 Subject: [PATCH 20/34] Update serial_protocol.md --- serial_protocol.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/serial_protocol.md b/serial_protocol.md index 44005045..9551f071 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -151,7 +151,8 @@ The event stream will continue until you send CANCEL_STREAM. <<+PUT /last_login <<#1455052043 <<+PUT /address - <<*24 78 High Street, + <<*24 + <<78 High Street, <>CANCEL_STREAM <<+OK From 6f304011f3b3f74f92812dcabba3f8d3846b87a3 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 13:59:27 -0800 Subject: [PATCH 21/34] Update serial_protocol.md --- serial_protocol.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 9551f071..2539729f 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -12,8 +12,8 @@ All responses will be prefixed with one of the following bytes signifying the re * If response is ok and a raw string value prefixed by count of bytes in response then new line. # If response is ok and a integer value. . If response is ok and a float value. - $ If response is ok and a boolean value. - & If response is ok and json formatted and prefixed by count of bytes in response then new line. + ? If response is ok and a boolean value. + $ If response is ok and json formatted and prefixed by count of bytes in response then new line. - If response is an error ``` ##NETWORK From 8dac3f3d8e47f5e2ec4827ccc5aaa139aafa9335 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 15:01:15 -0800 Subject: [PATCH 22/34] Update serial_protocol.md --- serial_protocol.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 2539729f..8848b8d8 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -84,18 +84,20 @@ Store the data provided at the path provided. This method should be used for sim ###Examples >>SET /user/aturning/first Alan <<+OK -##SET_BULK -Similar to SET above but used to write multiline strings or raw binary data. +##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_BULK $PATH $DATA_BYTE_COUNT $DATA + SET$ $PATH $DATA_BYTE_COUNT + $DATA ###Response +OK -FAIL -FAIL_TIMEOUT ###Examples - >>SET /user/aturning/address 24 78 High Street, + >>SET /user/aturning/address 24 + >>78 High Street, >>Hampton <<+OK @@ -120,16 +122,18 @@ Adds a value to the list located at the path provided and returns the key at whi >>PUSH /user/aturning/login_timestamps 1455052043 <<+-K94eLnB0rAAvfkh_WC2 -##PUSH_BULK -Similar to PUSH but used to write multiline strings or raw binary data. +##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. 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 $DATA + PUSH_BULK $PATH $DATA_BYTE_COUNT + $DATA ###Response $KEY ###Examples - >>PUSH /user/aturning/quotes 91 We can only see a short distance ahead, + >>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 From b0d90d2e1a2ffb897f112f47527bf13211f9f961 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 15:31:36 -0800 Subject: [PATCH 23/34] Added Serial client example. --- .../FirebaseSerialClient.ino | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 examples/FirebaseSerialClient/FirebaseSerialClient.ino diff --git a/examples/FirebaseSerialClient/FirebaseSerialClient.ino b/examples/FirebaseSerialClient/FirebaseSerialClient.ino new file mode 100644 index 00000000..10a32ad6 --- /dev/null +++ b/examples/FirebaseSerialClient/FirebaseSerialClient.ino @@ -0,0 +1,142 @@ +// +// Copyright 2015 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// FirebaseSerialClient is a sample that would sit on the other +// end of a serial connection and communicate with our chiplet. +// When you hold down the send button it will generate a random number +// of flashes and store that in Firebase. Then when you hold down the +// flash button it will read that value from Firebase and flash the +// led the appropriate number of times. If you hold both it will delete +// the stored value. +// This example touches most of the basic calls over the serial interface. + +// Set these parameters. + +const String network_ssid = ""; +const String host = ""; +const String auth = ""; + +bool initialized = false; + +void setup() { + // Connect to pc over usb. + Serial.begin(9600); + + // Connect to chiplet over the Serial1 port (pins 19 and 18). + // If you don't have a Serial1 port than remove all debug output and switch to Serial + Serial1.begin(9600); + + // Note, in production you only need to set NETWORK when your device changes location. + // It will persist through power cycles. + dataPrintLn(String("NETWORK ") + network_ssid); + String response = dataReadLn(); + if (response != "+CONNECTED") { + debugPrintLn("Failed to connect to network: " + response); + return; + } + debugPrintLn("Connected to " + network_ssid); + + dataPrintLn(String("INIT ") + host + " " + auth); + response = dataReadLn(); + if (response != "+OK") { + debugPrintLn("Failed to initalize: " + response); + return; + } + initialized = true; +} + +void loop() { + if (!initialized) { + return; + } + + if (SendButtonDown() && FlashButtonDown()) { + dataPrintLn("REMOVE /led_flashes"); + String response = dataReadLn(); + if (response != "+OK") { + debugPrintLn("Error during REMOVE: " + response); + } + + } else if (SendButtonDown()) { + debugPrintLn("Sending random number."); + int flashes = random(10); + + dataPrintLn(String("SET /led_flashes") + flashes); + String response = dataReadLn(); + if (response != "+OK") { + debugPrintLn("Error during SET: " + response); + } + + // Write to a log as well so we can see the history. + dataPrintLn(String("PUSH /led_flashes_log ") + flashes); + if (dataReadType() == '-') { + debugPrintLn("Error during PUSH: " + dataReadLn()); + } else { + // Drain input, we don't care about the new key. + dataReadLn(); + } + + debugPrintLn("Done sending random number."); + + } else if (FlashButtonDown()) { + debugPrintLn("Flashing LED."); + dataPrintLn(String("GET# /led_flashes")); + if (dataReadType() == '-') { + debugPrintLn("Error during GET: " + dataReadLn()); + } + + int flashes = atoi(dataReadLn().c_str()); + FlashLed(flashes); + + debugPrintLn("Done flashing LED."); + } +} + +bool SendButtonDown() { + //TODO Add detection for button on pin. + return false; +} + +bool FlashButtonDown() { + //TODO Add detection for button on pin. + return false; +} + +void FlashLed(int times) { + //TODO Add logic to flash led at high frequency <500ms between + // flashes so we don't take too long. +} + +void debugPrintLn(const String& message) { + Serial.println(message); +} + +void dataPrintLn(const String& message) { + Serial1.println(message); +} + +char dataReadType() { + return Serial1.read(); +} + +String dataReadLn() { + String line = Serial1.readStringUntil('\r'); + // Dump \r\n + Serial1.read(); + Serial1.read(); + return line; +} + From fc6a0f4d758d0b47d17be21fc98685e480dda4c7 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 15:39:08 -0800 Subject: [PATCH 24/34] Update FirebaseSerialClient.ino --- examples/FirebaseSerialClient/FirebaseSerialClient.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/FirebaseSerialClient/FirebaseSerialClient.ino b/examples/FirebaseSerialClient/FirebaseSerialClient.ino index 10a32ad6..28ed32a1 100644 --- a/examples/FirebaseSerialClient/FirebaseSerialClient.ino +++ b/examples/FirebaseSerialClient/FirebaseSerialClient.ino @@ -32,7 +32,7 @@ const String auth = ""; bool initialized = false; void setup() { - // Connect to pc over usb. + // Connect to pc over usb for debug output. Serial.begin(9600); // Connect to chiplet over the Serial1 port (pins 19 and 18). From 9f146de8878769e28ee0c0afb536e3c792108f24 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 16:40:33 -0800 Subject: [PATCH 25/34] Added buttons and led logic --- .../FirebaseSerialClient.ino | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/FirebaseSerialClient/FirebaseSerialClient.ino b/examples/FirebaseSerialClient/FirebaseSerialClient.ino index 10a32ad6..f7f5dc3e 100644 --- a/examples/FirebaseSerialClient/FirebaseSerialClient.ino +++ b/examples/FirebaseSerialClient/FirebaseSerialClient.ino @@ -23,8 +23,11 @@ // the stored value. // This example touches most of the basic calls over the serial interface. -// Set these parameters. +const int sendButtonPin = 4; +const int flashButtonPin = 5; +const int ledPin = 6; +// Set these parameters. const String network_ssid = ""; const String host = ""; const String auth = ""; @@ -32,6 +35,10 @@ const String auth = ""; bool initialized = false; void setup() { + pinMode(sendButtonPin, INPUT); + pinMode(flashButtonPin, INPUT); + pinMode(ledPin, OUTPUT); + // Connect to pc over usb. Serial.begin(9600); @@ -63,14 +70,14 @@ void loop() { return; } - if (SendButtonDown() && FlashButtonDown()) { + if (digitalRead(sendButtonPin) && digitalRead(flashButtonPin)) { dataPrintLn("REMOVE /led_flashes"); String response = dataReadLn(); if (response != "+OK") { debugPrintLn("Error during REMOVE: " + response); } - } else if (SendButtonDown()) { + } else if (digitalRead(sendButtonPin)) { debugPrintLn("Sending random number."); int flashes = random(10); @@ -91,7 +98,7 @@ void loop() { debugPrintLn("Done sending random number."); - } else if (FlashButtonDown()) { + } else if (digitalRead(flashButtonPin)) { debugPrintLn("Flashing LED."); dataPrintLn(String("GET# /led_flashes")); if (dataReadType() == '-') { @@ -99,25 +106,19 @@ void loop() { } int flashes = atoi(dataReadLn().c_str()); - FlashLed(flashes); + flashLed(flashes); debugPrintLn("Done flashing LED."); } } -bool SendButtonDown() { - //TODO Add detection for button on pin. - return false; -} - -bool FlashButtonDown() { - //TODO Add detection for button on pin. - return false; -} - -void FlashLed(int times) { - //TODO Add logic to flash led at high frequency <500ms between - // flashes so we don't take too long. +void flashLed(int times) { + for (int i=0; i < times; i++) { + digitalWrite(ledPin, HIGH); + delay(200); + digitalWrite(ledPin, LOW); + delay(300); + } } void debugPrintLn(const String& message) { From c39e37167cb71b1801ee2dbbfe33a8fb158990b5 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 17:11:39 -0800 Subject: [PATCH 26/34] Update serial_protocol.md --- serial_protocol.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 8848b8d8..a02349a2 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -1,7 +1,7 @@ #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 “INIT” call after which any subsequent calls can be made, until the connection is closed. +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. @@ -10,8 +10,7 @@ All responses will be prefixed with one of the following bytes signifying the re ``` + If response is ok and a raw string value. * If response is ok and a raw string value prefixed by count of bytes in response then new line. - # If response is ok and a integer value. - . If response is ok and a float value. + : If response is ok and a number, this could be float or int. ? If response is ok and a boolean value. $ If response is ok and json formatted and prefixed by count of bytes in response then new line. - If response is an error @@ -32,17 +31,17 @@ Only needs to be called when the chiplet is in a new environment and needs to co >> NETWORK home-guest << -UNABLE_TO_CONNECT -##INIT +##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 - INIT $Host - INIT $Host $Secret + BEGIN $Host + BEGIN $Host $Secret ###Response OK - Accepted initialization parameters ###Examples - >> INIT https://samplechat.firebaseio-demo.com + >> BEGIN https://samplechat.firebaseio-demo.com << +OK - >> INIT https://samplechat.firebaseio-demo.com nnz...sdf + >> 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. @@ -63,8 +62,7 @@ Same as GET but will either return the value in the format specified (by the for ###Usage GET+ $PATH GET* $PATH - GET# $PATH - GET. $PATH + GET: $PATH GET? $PATH GET$ $PATH ###Response @@ -153,7 +151,7 @@ The event stream will continue until you send CANCEL_STREAM. ###Examples >>STREAM /user/aturning <<+PUT /last_login - <<#1455052043 + <<:1455052043 <<+PUT /address <<*24 <<78 High Street, From 6ca12bebebf38ad88594557b954573121b741ce6 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 17:13:26 -0800 Subject: [PATCH 27/34] updated example for changes to protocol --- examples/FirebaseSerialClient/FirebaseSerialClient.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/FirebaseSerialClient/FirebaseSerialClient.ino b/examples/FirebaseSerialClient/FirebaseSerialClient.ino index a96e270f..425b14fc 100644 --- a/examples/FirebaseSerialClient/FirebaseSerialClient.ino +++ b/examples/FirebaseSerialClient/FirebaseSerialClient.ino @@ -56,7 +56,7 @@ void setup() { } debugPrintLn("Connected to " + network_ssid); - dataPrintLn(String("INIT ") + host + " " + auth); + dataPrintLn(String("BEGIN ") + host + " " + auth); response = dataReadLn(); if (response != "+OK") { debugPrintLn("Failed to initalize: " + response); @@ -100,7 +100,7 @@ void loop() { } else if (digitalRead(flashButtonPin)) { debugPrintLn("Flashing LED."); - dataPrintLn(String("GET# /led_flashes")); + dataPrintLn(String("GET: /led_flashes")); if (dataReadType() == '-') { debugPrintLn("Error during GET: " + dataReadLn()); } From 6be74cd4cd0959ccaf2e7b1259156bf18b2e673e Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 17:16:07 -0800 Subject: [PATCH 28/34] Update serial_protocol.md --- serial_protocol.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index a02349a2..46482d61 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -9,10 +9,9 @@ In the following examples we use $ to represent variables. For example $Host rep 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 and a raw string value prefixed by count of bytes in response then new line. + $ 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 ok and json formatted and prefixed by count of bytes in response then new line. - If response is an error ``` ##NETWORK @@ -54,14 +53,13 @@ Fetches the value at $Path and returns it on the serial line. If $PATH points to >>GET /user/aturing/first <<+Alan >>GET /user/aturing - <<&39 + <<$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 GET$ $PATH @@ -153,8 +151,7 @@ The event stream will continue until you send CANCEL_STREAM. <<+PUT /last_login <<:1455052043 <<+PUT /address - <<*24 - <<78 High Street, - <>CANCEL_STREAM <<+OK From e8c962309f469b4c9347eba545a04d5de6834b02 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 9 Feb 2016 17:20:07 -0800 Subject: [PATCH 29/34] Update serial_protocol.md --- serial_protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serial_protocol.md b/serial_protocol.md index 46482d61..613993e8 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -119,7 +119,7 @@ Adds a value to the list located at the path provided and returns the key at whi <<+-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. +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 From d9bdee645e838ff4aaf207aea83b2557bbd57c31 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Wed, 10 Feb 2016 10:48:04 -0800 Subject: [PATCH 30/34] Move serial client to another branch --- .../FirebaseSerialClient.ino | 143 ------------------ 1 file changed, 143 deletions(-) delete mode 100644 examples/FirebaseSerialClient/FirebaseSerialClient.ino diff --git a/examples/FirebaseSerialClient/FirebaseSerialClient.ino b/examples/FirebaseSerialClient/FirebaseSerialClient.ino deleted file mode 100644 index 425b14fc..00000000 --- a/examples/FirebaseSerialClient/FirebaseSerialClient.ino +++ /dev/null @@ -1,143 +0,0 @@ -// -// Copyright 2015 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -// FirebaseSerialClient is a sample that would sit on the other -// end of a serial connection and communicate with our chiplet. -// When you hold down the send button it will generate a random number -// of flashes and store that in Firebase. Then when you hold down the -// flash button it will read that value from Firebase and flash the -// led the appropriate number of times. If you hold both it will delete -// the stored value. -// This example touches most of the basic calls over the serial interface. - -const int sendButtonPin = 4; -const int flashButtonPin = 5; -const int ledPin = 6; - -// Set these parameters. -const String network_ssid = ""; -const String host = ""; -const String auth = ""; - -bool initialized = false; - -void setup() { - pinMode(sendButtonPin, INPUT); - pinMode(flashButtonPin, INPUT); - pinMode(ledPin, OUTPUT); - - // Connect to pc over usb for debug output. - Serial.begin(9600); - - // Connect to chiplet over the Serial1 port (pins 19 and 18). - // If you don't have a Serial1 port than remove all debug output and switch to Serial - Serial1.begin(9600); - - // Note, in production you only need to set NETWORK when your device changes location. - // It will persist through power cycles. - dataPrintLn(String("NETWORK ") + network_ssid); - String response = dataReadLn(); - if (response != "+CONNECTED") { - debugPrintLn("Failed to connect to network: " + response); - return; - } - debugPrintLn("Connected to " + network_ssid); - - dataPrintLn(String("BEGIN ") + host + " " + auth); - response = dataReadLn(); - if (response != "+OK") { - debugPrintLn("Failed to initalize: " + response); - return; - } - initialized = true; -} - -void loop() { - if (!initialized) { - return; - } - - if (digitalRead(sendButtonPin) && digitalRead(flashButtonPin)) { - dataPrintLn("REMOVE /led_flashes"); - String response = dataReadLn(); - if (response != "+OK") { - debugPrintLn("Error during REMOVE: " + response); - } - - } else if (digitalRead(sendButtonPin)) { - debugPrintLn("Sending random number."); - int flashes = random(10); - - dataPrintLn(String("SET /led_flashes") + flashes); - String response = dataReadLn(); - if (response != "+OK") { - debugPrintLn("Error during SET: " + response); - } - - // Write to a log as well so we can see the history. - dataPrintLn(String("PUSH /led_flashes_log ") + flashes); - if (dataReadType() == '-') { - debugPrintLn("Error during PUSH: " + dataReadLn()); - } else { - // Drain input, we don't care about the new key. - dataReadLn(); - } - - debugPrintLn("Done sending random number."); - - } else if (digitalRead(flashButtonPin)) { - debugPrintLn("Flashing LED."); - dataPrintLn(String("GET: /led_flashes")); - if (dataReadType() == '-') { - debugPrintLn("Error during GET: " + dataReadLn()); - } - - int flashes = atoi(dataReadLn().c_str()); - flashLed(flashes); - - debugPrintLn("Done flashing LED."); - } -} - -void flashLed(int times) { - for (int i=0; i < times; i++) { - digitalWrite(ledPin, HIGH); - delay(200); - digitalWrite(ledPin, LOW); - delay(300); - } -} - -void debugPrintLn(const String& message) { - Serial.println(message); -} - -void dataPrintLn(const String& message) { - Serial1.println(message); -} - -char dataReadType() { - return Serial1.read(); -} - -String dataReadLn() { - String line = Serial1.readStringUntil('\r'); - // Dump \r\n - Serial1.read(); - Serial1.read(); - return line; -} - From f004ae503ffd467c71ae82fadbf947777d71a443 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 16 Feb 2016 09:43:43 -0800 Subject: [PATCH 31/34] Update serial_protocol.md --- serial_protocol.md | 53 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 613993e8..facd438a 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -43,7 +43,7 @@ Must be called after creating a Serial connection, it can take either just a hos >> 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. +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. ###Usage GET $PATH ###Response @@ -78,10 +78,10 @@ Store the data provided at the path provided. This method should be used for sim +OK -FAIL ###Examples - >>SET /user/aturning/first Alan + >>SET /user/aturing/first Alan <<+OK ##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. +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. However which the batch string ($) return type returns data json escaped and quoted you may provide raw data and we will handle the escaping. Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. ###Usage @@ -92,10 +92,25 @@ Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of -FAIL -FAIL_TIMEOUT ###Examples - >>SET /user/aturning/address 24 + >>SET /user/aturing/address 24 >>78 High Street, >>Hampton <<+OK + +##SET{+,*,#,.,?} +Same as SET but will force the value to be stored in the given type or return an error if we cannot parse it as that type. +###Usage + SET+ $PATH $VALUE + SET: $PATH $VALUE + SET? $PATH $VALUE +###Response + +OK + -INCORRECT_TYPE +###Examples + >>SET? /user/aturing/was_human true + <<+OK + >>SET? /user/aturing/was_human He was not a computer. + <<-INCORRECT_TYPE ##REMOVE Deletes the value located at the path provided. @@ -105,7 +120,7 @@ Deletes the value located at the path provided. +OK -FAIL ###Examples - >>REMOVE /user/aturning + >>REMOVE /user/aturing <<+OK ##PUSH @@ -115,7 +130,7 @@ Adds a value to the list located at the path provided and returns the key at whi ###Response $KEY ###Examples - >>PUSH /user/aturning/login_timestamps 1455052043 + >>PUSH /user/aturing/login_timestamps 1455052043 <<+-K94eLnB0rAAvfkh_WC2 ##PUSH$ @@ -123,35 +138,47 @@ Similar to PUSH but used to write multiline strings or raw binary data. Data for 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 + PUSH$ $PATH $DATA_BYTE_COUNT $DATA ###Response $KEY ###Examples - >>PUSH /user/aturning/quotes 91 + >>PUSH /user/aturing/quotes 91 >>We can only see a short distance ahead, >>but we can see plenty there that needs to be done. <<+-K94eLnB0rAAvfkh_WC3 -##STREAM +##BEGIN_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 - CANCEL_STREAM + BEGIN_STREAM $PATH ###Response $EVENT_NAME $SUB_PATH $DATA +OK ###Examples - >>STREAM /user/aturning + >>BEGIN_STREAM /user/aturing <<+PUT /last_login <<:1455052043 <<+PUT /address <<$24 <<"78 High Street,\r\nHampton" - >>CANCEL_STREAM + +##END_STREAM +Used to stop listening to events at a given path. This must be the same path provided to a previous BEGIN_STREAM call. + +###Usage + END_STREAM $PATH +###Response + +OK + -NOT_STREAMING_PATH +###Examples + >>END_STREAM /user/aturing + <<-NOT_STREAMING_PATH + >>BEGIN_STREAM /user/aturing + >>END_STREAM /user/aturing <<+OK From bba8045fa1bdb2a150b75249013a3d9c38eab1bd Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 16 Feb 2016 11:54:30 -0800 Subject: [PATCH 32/34] Update serial_protocol.md --- serial_protocol.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serial_protocol.md b/serial_protocol.md index facd438a..62cb1064 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -154,6 +154,8 @@ Used to register to receive a stream of events that occur to the object at the p 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. + +When there is an ongoing event stream no other commands can be processed until you call END_STREAM as the event stream owns the return line. ###Usage BEGIN_STREAM $PATH ###Response From 8ced4fb51049ca33166b30dda6e5ea5ed1c74a20 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Fri, 25 Mar 2016 15:04:20 -0700 Subject: [PATCH 33/34] Update serial_protocol.md --- serial_protocol.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 62cb1064..2a055e8b 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -20,8 +20,8 @@ Only needs to be called when the chiplet is in a new environment and needs to co NETWORK $SSID NETWORK $SSID $PASSWORD ###Response - CONNECTED - When connected to new network - UNABLE_TO_CONNECT - When unable to connect + +CONNECTED - When connected to new network + -UNABLE_TO_CONNECT - When unable to connect ###Examples >> NETWORK home-guest << +CONNECTED @@ -36,7 +36,7 @@ Must be called after creating a Serial connection, it can take either just a hos BEGIN $Host BEGIN $Host $Secret ###Response - OK - Accepted initialization parameters + +OK - Accepted initialization parameters ###Examples >> BEGIN https://samplechat.firebaseio-demo.com << +OK @@ -85,14 +85,16 @@ Similar to SET above but used to write multiline strings or raw binary data. Dat 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 + SET$ $PATH + $DATA_BYTE_COUNT $DATA ###Response +OK -FAIL -FAIL_TIMEOUT ###Examples - >>SET /user/aturing/address 24 + >>SET /user/aturing/address + >>24 >>78 High Street, >>Hampton <<+OK @@ -143,7 +145,7 @@ Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of ###Response $KEY ###Examples - >>PUSH /user/aturing/quotes 91 + >>PUSH$ /user/aturing/quotes 91 >>We can only see a short distance ahead, >>but we can see plenty there that needs to be done. <<+-K94eLnB0rAAvfkh_WC3 @@ -153,7 +155,7 @@ Used to register to receive a stream of events that occur to the object at the p 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. +The event stream will continue until you send END_STREAM. When there is an ongoing event stream no other commands can be processed until you call END_STREAM as the event stream owns the return line. ###Usage From e5570d69b21b94584e9010c4e2db6b5ac2ba03b3 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Fri, 8 Apr 2016 13:21:50 -0700 Subject: [PATCH 34/34] switched variable marker from $ to %% --- serial_protocol.md | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/serial_protocol.md b/serial_protocol.md index 2a055e8b..41888faf 100644 --- a/serial_protocol.md +++ b/serial_protocol.md @@ -3,7 +3,7 @@ During the first use, or when the chiplet changes environments a “NETWORK” c 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. +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. @@ -17,8 +17,8 @@ All responses will be prefixed with one of the following bytes signifying the re ##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 + NETWORK %SSID% + NETWORK %SSID% %PASSWORD% ###Response +CONNECTED - When connected to new network -UNABLE_TO_CONNECT - When unable to connect @@ -33,8 +33,8 @@ Only needs to be called when the chiplet is in a new environment and needs to co ##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 + BEGIN %Host% + BEGIN %Host% %Secret% ###Response +OK - Accepted initialization parameters ###Examples @@ -43,12 +43,12 @@ Must be called after creating a Serial connection, it can take either just a hos >> 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. +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. ###Usage - GET $PATH + GET %PATH% ###Response - $DATA_AT_PATH - $JSON_DATA_BYTE_COUNT \n\r $JSON_DATA + %DATA_AT_PATH% + $%JSON_DATA_BYTE_COUNT% \r\n %JSON_DATA ###Examples >>GET /user/aturing/first <<+Alan @@ -59,12 +59,12 @@ Fetches the value at $PATH and returns it on the serial line. If $PATH points to ##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 + GET+ %PATH% + GET: %PATH% + GET? %PATH% + GET$ %PATH% ###Response - $FORMATED_RESPONSE + %FORMATED_RESPONSE% ###Examples >>GET? /user/aturing/was_human <>PUSH /user/aturing/login_timestamps 1455052043 <<+-K94eLnB0rAAvfkh_WC2 @@ -140,10 +140,10 @@ Similar to PUSH but used to write multiline strings or raw binary data. Data for Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again. ###Usage - PUSH$ $PATH $DATA_BYTE_COUNT - $DATA + PUSH$ %PATH% %DATA_BYTE_COUNT% + %DATA% ###Response - $KEY + %KEY% ###Examples >>PUSH$ /user/aturing/quotes 91 >>We can only see a short distance ahead, @@ -159,10 +159,10 @@ The event stream will continue until you send END_STREAM. When there is an ongoing event stream no other commands can be processed until you call END_STREAM as the event stream owns the return line. ###Usage - BEGIN_STREAM $PATH + BEGIN_STREAM %PATH% ###Response - $EVENT_NAME $SUB_PATH - $DATA + %EVENT_NAME% %SUB_PATH% + %DATA% +OK ###Examples >>BEGIN_STREAM /user/aturing @@ -176,7 +176,7 @@ When there is an ongoing event stream no other commands can be processed until y Used to stop listening to events at a given path. This must be the same path provided to a previous BEGIN_STREAM call. ###Usage - END_STREAM $PATH + END_STREAM %PATH% ###Response +OK -NOT_STREAMING_PATH