-
Notifications
You must be signed in to change notification settings - Fork 492
Add serial protocol #59
Changes from 3 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,61 @@ | ||
#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 | ||
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. maybe we could have that 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. Hmm not sure about that one, INIT implies that it needs to be called everytime to initialize the connection. Maybe CONNECT $HOST $SECRET? Just It seems these should all be commands to the system and phrased as such where FIREBASE isn't really a command. 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 was thinking that if the CHIPLET was programmed with multiple APIs, it might expose similar commands derived from REST verbs over different APIs (hence the explicit 'FIREBASE'). But that may be a premature discussion, what about 'BEGIN' to make it Arduinoish? 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 got ya. Hadn't considered the other APIs. BEGIN works too, we can do BEGIN_FIREBASE if we want to leave the option open for other APIs. 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. Let's do only begin for now ;) I agree we should worry about multiple API when we have more than 1 binding ;) sorry for the disgression. 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. Then what about:
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 not really sold on adding an extra call. I think the fewer calls you need to make to get the env setup to start communicating the better. I guess for versions I would just change the begin call. i.e. create a BEGIN_FIREBASE2 if we ever need to implement a breaking change. 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. What I liked about the 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. Alright I am on board with something like that. We can have a concept of "default api" that will load at startup. So for now we can just leave this out all together and address it later on when we introduce other APIs or versions. 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.
Yes, so for now I think it's fine to just have |
||
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, in json, at $Path and returns it on the serial line. | ||
###Usage | ||
GET $PATH | ||
###Response | ||
$DATA_BYTE_COUNT $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. I wonder if that wouldn't be easier to just have it line delimited (since you can easily readline from 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 would have to escape newline in the value. Also it is nice to know how large the incoming message is so you can allocate a buffer for it. I guess it depends whether the common case is just grabbing an int value or grabbing data blobs or text. So what I currently use as a backend for my IoT projects in redis mostly because it has a very simple wire protocol that I can hack a library for in O(minutes). http://redis.io/topics/protocol They use the first byte of the response to dictate a type, being error, string, blob(bulkstring). I like the idea to address this problem as only large data types benefit from complexity like a size. But for those data types it is far easier to deal with them if you have the size ahead of time. We could just use their protocol, which would be nice for compatibility. 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.
Nice! We used something similar for error and logging in the [old serial bridge] 566c303#diff-dc3ebc3d309c06217829e6e5ed607be0R71, everything that started with a I'm wondering if we need to "always" prefix the type since the chiplet is meant to be used directly with Serial.readStringUntil and it's like that you already know if you want to read a json number, a string or a json body depending on the path you're It would look something like:
But maybe I'm being too naive. 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. ya I think this is getting back to two modes of operation. The "store a simple value" and "Store a binary blob or text". Maybe we should just separate them and have GET return the value alone but have a GET_BULK that will return the value prefixed by it's size. Eitherway when I think about it your example probably isn't what we want to encourage though. If we return an error than that will crash the board. Maybe we should have the forward prefix that you should always check and strip off so it would be 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.
Yes, you're right and if we end up prefixing the the result we might as well use that prefix a type hint: sold! 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. alright updated with prefixes and bulk mode. 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. Im thinking that the BULK mode would be better as a stateful MODE rather than a separate comment. Since you're likely to always want one or the other. re: prefix only on error: just for completeness of the argument what do think of the following client code:
Maybe the type prefix could come as a separate stateful mode, since you're likely to always want them or never. |
||
###Examples | ||
>>GET /user/aturing | ||
<<39 { "first" : "Alan", "last" : "Turing" } | ||
|
||
##GET_VALUE | ||
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 I feel that a goal of this project is to provide cloud backends for non-cloud users who have sofar stayed local or offline due to a reluctance to face the learning curve of cloud tech. json isn't a common protocol in the embedded world and is relatively hard/expensive to decode. |
||
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 | ||
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. What do you think of having For you second suggestion (disabling json by default): 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. Oh, I didn't realize that was how the REST interface already worked, I thought it always returned json. Ya if that will match the REST interface I am on board. 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.
Oups, sorry for the missunderstanding: the REST interface always return JSON, what I'm saying is that here we could return something closer to what the user is waiting for, i.e: if he is querying a leaf string or number, it's unlikely he want to unquote it himself. 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. Does it? (from the example app) I just get a raw integer back. I guess that raw integer could be valid json but it is not formatted in any special way. 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. Yes, raw integer is a valid json number, but everything json raw string needs to be "double quoted". |
||
###Response | ||
$DATA_BYTE_COUNT $DATA | ||
ERROR_NOT_LEAF_NODE | ||
###Examples | ||
>>GET_VALUE /user/aturing/first | ||
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/GET_VALUE/GET/g 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 |
||
<<4 Alan | ||
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. another issue with having the size 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. true but you can just read until whitespace. there is also Serial.parseInt() 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. Then what's the improvement over reading until \n? That you're guaranteed the size will never cross a given threshold (a few digits). Maybe this could come in the same kind of stateful 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. If you know on the outset the size of the value coming back you can prepare for it. For example you can allocate a buffer large enough to hold it without having to allocate a smaller buffer and grow it. You can also quickly decide if something is too large to process and close the connection. We could also return text without the json escaping which might be nice so the user doesn't need to unescape it themselves. For example if they wanted to send it directly to a display. |
||
>>GET_VALUE /user/aturing/last | ||
<<7 Turing | ||
>>GET_VALUE /user/aturing | ||
<<ERROR_NOT_LEAF_NODE | ||
|
||
##Set | ||
##Push | ||
##Remove | ||
##Stream |
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>