Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 1c422b9

Browse files
committed
Merge branch 'Serial' of https://github.com/ed7coyne/firebase-arduino into Serial
2 parents 724fde5 + 8dac3f3 commit 1c422b9

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

serial_protocol.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#Protocol:
2+
During the first use, or when the chiplet changes environments a “NETWORK” call is expected to initialize the wifi parameters.
3+
4+
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.
5+
6+
In the following examples we use $ to represent variables. For example $Host represents your firebase host.
7+
8+
##Response Format Byte
9+
All responses will be prefixed with one of the following bytes signifying the response type.
10+
```
11+
+ If response is ok and a raw string value.
12+
* If response is ok and a raw string value prefixed by count of bytes in response then new line.
13+
# If response is ok and a integer value.
14+
. If response is ok and a float value.
15+
? If response is ok and a boolean value.
16+
$ If response is ok and json formatted and prefixed by count of bytes in response then new line.
17+
- If response is an error
18+
```
19+
##NETWORK
20+
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.
21+
###Usage
22+
NETWORK $SSID
23+
NETWORK $SSID $PASSWORD
24+
###Response
25+
CONNECTED - When connected to new network
26+
UNABLE_TO_CONNECT - When unable to connect
27+
###Examples
28+
>> NETWORK home-guest
29+
<< +CONNECTED
30+
>> NETWORK home-private MySecretPassword
31+
<< +CONNECTED
32+
>> NETWORK home-guest
33+
<< -UNABLE_TO_CONNECT
34+
35+
##INIT
36+
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.
37+
###Usage
38+
INIT $Host
39+
INIT $Host $Secret
40+
###Response
41+
OK - Accepted initialization parameters
42+
###Examples
43+
>> INIT https://samplechat.firebaseio-demo.com
44+
<< +OK
45+
>> INIT https://samplechat.firebaseio-demo.com nnz...sdf
46+
<< +OK
47+
##GET
48+
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.
49+
###Usage
50+
GET $PATH
51+
###Response
52+
$DATA_AT_PATH
53+
$JSON_DATA_BYTE_COUNT \n\r $JSON_DATA
54+
###Examples
55+
>>GET /user/aturing/first
56+
<<+Alan
57+
>>GET /user/aturing
58+
<<&39
59+
<<{ "first" : "Alan", "last" : "Turing" }
60+
61+
##GET{+,*,#,.,?,$}
62+
Same as GET but will either return the value in the format specified (by the format byte) or return an error.
63+
###Usage
64+
GET+ $PATH
65+
GET* $PATH
66+
GET# $PATH
67+
GET. $PATH
68+
GET? $PATH
69+
GET$ $PATH
70+
###Response
71+
$FORMATED_RESPONSE
72+
###Examples
73+
>>GET? /user/aturing/was_human
74+
<<?true
75+
>>GET? /user/aturing/first
76+
<<-ERROR_INCORRECT_FORMAT
77+
##SET
78+
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.
79+
###Usage
80+
SET $PATH $DATA
81+
###Response
82+
+OK
83+
-FAIL
84+
###Examples
85+
>>SET /user/aturning/first Alan
86+
<<+OK
87+
##SET$
88+
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.
89+
90+
Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again.
91+
###Usage
92+
SET$ $PATH $DATA_BYTE_COUNT
93+
$DATA
94+
###Response
95+
+OK
96+
-FAIL
97+
-FAIL_TIMEOUT
98+
###Examples
99+
>>SET /user/aturning/address 24
100+
>>78 High Street,
101+
>>Hampton
102+
<<+OK
103+
104+
##REMOVE
105+
Deletes the value located at the path provided.
106+
###Usage
107+
REMOVE $PATH
108+
###Response
109+
+OK
110+
-FAIL
111+
###Examples
112+
>>REMOVE /user/aturning
113+
<<+OK
114+
115+
##PUSH
116+
Adds a value to the list located at the path provided and returns the key at which the new object is located.
117+
###Usage
118+
PUSH $PATH $DATA
119+
###Response
120+
$KEY
121+
###Examples
122+
>>PUSH /user/aturning/login_timestamps 1455052043
123+
<<+-K94eLnB0rAAvfkh_WC2
124+
125+
##PUSH$
126+
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.
127+
128+
Receiver will wait until a timeout for client to send $DATA_BYTE_COUNT worth of data before becoming responsive again.
129+
###Usage
130+
PUSH_BULK $PATH $DATA_BYTE_COUNT
131+
$DATA
132+
###Response
133+
$KEY
134+
###Examples
135+
>>PUSH /user/aturning/quotes 91
136+
>>We can only see a short distance ahead,
137+
>>but we can see plenty there that needs to be done.
138+
<<+-K94eLnB0rAAvfkh_WC3
139+
140+
##STREAM
141+
Used to register to receive a stream of events that occur to the object at the provided path.
142+
143+
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 (&).
144+
145+
The event stream will continue until you send CANCEL_STREAM.
146+
###Usage
147+
STREAM $PATH
148+
CANCEL_STREAM
149+
###Response
150+
$EVENT_NAME $SUB_PATH
151+
$DATA
152+
+OK
153+
###Examples
154+
>>STREAM /user/aturning
155+
<<+PUT /last_login
156+
<<#1455052043
157+
<<+PUT /address
158+
<<*24
159+
<<78 High Street,
160+
<<Hampton
161+
>>CANCEL_STREAM
162+
<<+OK

0 commit comments

Comments
 (0)