<commit_before>Protocol
========

This document is an inventary for the messages used between the bakend and the farmbot

Basics
------

The farmbot hardware communicates with the backend trough the skynet protocol, a machine instant messaging protocol. All information is packaged as JSON. A typical message in skynet looks like this:

```
{
  "devices"=>"44128811-8c59-11e3-b99a-11476114e05f", 
  "message"=>
  {
    "message_type"=>"confirmation", 
    "time_stamp"=>"1403894016.000322"
  }, 
  "fromUuid"=>"68591ebf-d354-4a3a-8b83-0453bf4e8b23"
}
````

Everything in the message variable is custom. Skynet itself will always use create the device, message and fromUuid variable.

For farmbot, two elements are always present in the message:

|variable|example value|description|
|--------|-------------|-----------|
|message\_type | single\_command|the type of message|
|time\_stamp|1403805036.4898174|a string value to make the message unique|

The message type is a string that defines what the message does. Current available message types are:

|send by backend        |response by farmbot      |
|-----------------------|-------------------------|
|single\_command        |confirmation             |
|read\_parameters       |read\_parameters_response|
|read\_status           |read\_status\_response   |
|read\_logs             |read\_logs\_response     |
|write\_parameters      |confirmation             |
|crop\_schedule\_update |confirmation             |

Confirmation
------------

Some messages get a short response as a confirmation from the farmbot that the message is read and processed. The farmbot puts into 'confirm_id' the 'time_stamp' of the message that is processed.

```
{
  "message_type"=>"confirmation", 
  "time_stamp"=>"1403894016.000322", 
  "confirm_id"=>"1403894021.7605221"
}
```

Basic movement
==============

To move the farmbot manually, a message is send with type 'single command'. The farmbot will put the command into the schedule for immediate execution. The message looks like:

```
{
  :message_type=>"single_command", 
  :time_stamp=>"1403805036.4898174", 
  :command=>
  {
    :action=>"MOVE RELATIVE", 
    :x=>0, 
    :y=>10, 
    :z=>0, 
    :speed=>"manouvering", 
    :amount=>0, 
    :delay=>0
  }
}
```

variable|type|desciption
--------|----|----------
action  |string |the action/movement to do
x       |decimal|in absolute mode, the new place to move to. in relative mode, the amount to move, in millimeter
y       |decimal|same as x
z       |decimal|same as x
speed   |string |speed for movements, as text. for example 'traveling', 'manouvering'
amount  |decimal|amount of mililiter of water to dose. always add parameter with default value
delay   |decimal|amount in seconds to delay the execution of a command
pin_nr    |decimal|the number of the pin to change or pin for servo, using arduino numbering
pin_value1|decimal|the value for the pin, for servo movement the angle
pin_value2|decimal|when using a pulse, this is the value for the second flank of the pulse
pin_mode  |decimal|for setting the I/O mode, 0 is input, 1 is output. For reading and writing, 0 is digital and 1 is analog
pin_time  |decimal||the time im seconds for a pulse



actions and parameters used:

action       |x      |y      |z      |speed|amount|delay|pin_nr|pin_value1|pin_value2|pin_mode|pin_time
-------------|-------|-------|-------|-----|------|-----|------|----------|----------|--------|--------
MOVE RELATIVE|X      |X      |X      |X    |      |X    |      |          |          |        |
MOVE ABSOLUTE|X      |X      |X      |X    |      |X    |      |          |          |        |
DOSE WATER   |       |       |       |     |X     |X    |      |          |          |        |
HOME X       |       |       |       |X    |      |X    |      |          |          |        |
HOME Y       |       |       |       |X    |      |X    |      |          |          |        |
HOME Z       |       |       |       |X    |      |X    |      |          |          |        |
PIN WRITE    |       |       |       |     |      |X    |X     |X         |          |X       |
PIN READ     |       |       |       |     |      |X    |X     |          |          |X       |
PIN MODE     |       |       |       |     |      |X    |X     |          |          |X       |
PIN PULSE    |       |       |       |     |      |X    |X     |X         |X         |X       |X
SERVO MOVE   |       |       |       |     |      |X    |X     |X         |          |        |


Device status
=============<commit_msg>fixed a few typos in protocols.md<commit_after>Protocol
========

This document is an inventory for the messages used between the backend and the farmbot.

Basics
------

The farmbot hardware communicates with the backend trough the skynet protocol, a machine instant messaging protocol. All information is packaged as JSON. A typical message in skynet looks like this:

```
{
  "devices"=>"44128811-8c59-11e3-b99a-11476114e05f", 
  "message"=>
  {
    "message_type"=>"confirmation", 
    "time_stamp"=>"1403894016.000322"
  }, 
  "fromUuid"=>"68591ebf-d354-4a3a-8b83-0453bf4e8b23"
}
````

Everything in the message variable is custom. Skynet itself will always use create the device, message and fromUuid variable.

For farmbot, two elements are always present in the message:

|variable|example value|description|
|--------|-------------|-----------|
|message\_type | single\_command|the type of message|
|time\_stamp|1403805036.4898174|a string value to make the message unique|

The message type is a string that defines what the message does. Current available message types are:

|send by backend        |response by farmbot      |
|-----------------------|-------------------------|
|single\_command        |confirmation             |
|read\_parameters       |read\_parameters_response|
|read\_status           |read\_status\_response   |
|read\_logs             |read\_logs\_response     |
|write\_parameters      |confirmation             |
|crop\_schedule\_update |confirmation             |

Confirmation
------------

Some messages get a short response as a confirmation from the farmbot that the message is read and processed. The farmbot puts into 'confirm_id' the 'time_stamp' of the message that is processed.

```
{
  "message_type"=>"confirmation", 
  "time_stamp"=>"1403894016.000322", 
  "confirm_id"=>"1403894021.7605221"
}
```

Basic movement
==============

To move the farmbot manually, a message is send with type 'single command'. The farmbot will put the command into the schedule for immediate execution. The message looks like:

```
{
  :message_type=>"single_command", 
  :time_stamp=>"1403805036.4898174", 
  :command=>
  {
    :action=>"MOVE RELATIVE", 
    :x=>0, 
    :y=>10, 
    :z=>0, 
    :speed=>"manouvering", 
    :amount=>0, 
    :delay=>0
  }
}
```

variable|type|desciption
--------|----|----------
action  |string |the action/movement to do
x       |decimal|in absolute mode, the new place to move to. in relative mode, the amount to move, in millimeter
y       |decimal|same as x
z       |decimal|same as x
speed   |string |speed for movements, as text. for example 'traveling', 'manouvering'
amount  |decimal|amount of mililiter of water to dose. always add parameter with default value
delay   |decimal|amount in seconds to delay the execution of a command
pin_nr    |decimal|the number of the pin to change or pin for servo, using arduino numbering
pin_value1|decimal|the value for the pin, for servo movement the angle
pin_value2|decimal|when using a pulse, this is the value for the second flank of the pulse
pin_mode  |decimal|for setting the I/O mode, 0 is input, 1 is output. For reading and writing, 0 is digital and 1 is analog
pin_time  |decimal||the time in seconds for a pulse



actions and parameters used:

action       |x      |y      |z      |speed|amount|delay|pin_nr|pin_value1|pin_value2|pin_mode|pin_time
-------------|-------|-------|-------|-----|------|-----|------|----------|----------|--------|--------
MOVE RELATIVE|X      |X      |X      |X    |      |X    |      |          |          |        |
MOVE ABSOLUTE|X      |X      |X      |X    |      |X    |      |          |          |        |
DOSE WATER   |       |       |       |     |X     |X    |      |          |          |        |
HOME X       |       |       |       |X    |      |X    |      |          |          |        |
HOME Y       |       |       |       |X    |      |X    |      |          |          |        |
HOME Z       |       |       |       |X    |      |X    |      |          |          |        |
PIN WRITE    |       |       |       |     |      |X    |X     |X         |          |X       |
PIN READ     |       |       |       |     |      |X    |X     |          |          |X       |
PIN MODE     |       |       |       |     |      |X    |X     |          |          |X       |
PIN PULSE    |       |       |       |     |      |X    |X     |X         |X         |X       |X
SERVO MOVE   |       |       |       |     |      |X    |X     |X         |          |        |


Device status
=============
{'fraction_non_alphanumeric': 0.1453986382604876, 'fraction_numerical': 0.031627498352734464, 'mean_word_length': 1.6722417840375587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2167286', 'n_tokens_mistral': 2932, 'n_tokens_neox': 2681, 'n_words': 841}