Go to file
Rick Carlino 8970c194e3 Upgrade ruby 2017-09-20 07:26:07 -05:00
app Extract row component 2017-09-19 09:45:18 -05:00
bin
config [UNSTABLE] Add name column, add #index 2017-09-18 13:16:47 -05:00
db [UNSTABLE] Saves, edits, deletes work. NEXT: tests 2017-09-19 13:28:19 -05:00
lib/tasks
public improve multiline messages and lang helper regex 2017-08-31 15:47:22 -07:00
spec plural webcam feed CRUD actions 2017-09-19 07:21:48 -05:00
typings
webpack Ready for testing 2017-09-20 07:19:35 -05:00
.buildpacks
.codeclimate.yml
.coveralls.yml
.gitignore update README instructions 2017-09-02 14:33:11 -07:00
.ruby-gemset
.ruby-version Upgrade ruby 2017-09-20 07:26:07 -05:00
.travis.yml
CONTRIBUTING.md
DEPLOYMENT.md
Gemfile Ready for testing 2017-09-20 07:19:35 -05:00
Gemfile.lock Ready for testing 2017-09-20 07:19:35 -05:00
ISSUE_TEMPLATE
LICENSE
Procfile.dev
README.md update README instructions 2017-09-02 14:33:11 -07:00
Rakefile
api_docs.md.erb
config.ru
favicon.ico
index.js
latest_corpus.rb
package.json 🎉 Upgrades complete 2017-09-01 11:13:28 -05:00
tsconfig.json
tslint.json
yarn.lock 🎉 Upgrades complete 2017-09-01 11:13:28 -05:00

README.md

codebeat badge

Coverage Status(Frontend)

codecov(API)

Q: Do I need this?

This repository is intended for software developers who wish to modify the Farmbot Web App. If you are not a developer, you are highly encouraged to use the publicly available web app. Running a server is a non-trivial task which will require an intermediate background in Ruby, SQL and Linux system administration.

If you are a developer interested in contributing or would like to provision your own server, you are in the right place.

Q: What is the Farmbot Web App?

This repo contains FarmBot's web based user interface, as well as a RESTful JSON API. The API stores data such as user account information, plant data, authorization tokens and a variety of other resources.

The key responsibility of the API is information and permissions management. This should not be confused with device control, which is done via MQTT.

Q: Can I see some example API requests?

For a list of example API requests and responses, see our reference documentation. If you wish to write an add-on application that uses the FarmBot API, please let us know in an issue. We are happy to answer any specific questions you may have.

Q: How do I Setup an instance locally?

Prerequisites

You will need the following:

  1. A Linux or Mac based machine. We do not support windows at this time.
  2. Ruby 2.4.1
  3. ImageMagick (brew install imagemagick (Mac) or sudo apt-get install imagemagick (Ubuntu))
  4. Node JS > v6
  5. libpq-dev and postgresql and postgresql-contrib
  6. gem install bundler

Setup

  1. git clone https://github.com/FarmBot/Farmbot-Web-App
  2. cd Farmbot-Web-App
  3. bundle install
  4. yarn install
  5. Database config: Copy config/database.example.yml to config/database.yml via cp config/database.example.yml config/database.yml
  6. App config: MOST IMPORTANT STEP. Copy config/application.example.yml to config/application.yml via mv config/application.example.yml config/application.yml. Please read the instructions inside the file. Replace the example values provided with real world values.
  7. Give permission to create a database*
  8. rake db:create:all db:migrate db:seed
  9. (optional) Verify installation with RAILS_ENV=test rake db:create db:migrate && rspec spec (API) and npm run test (Frontend).
  10. Start server with npm run dev. Make sure you set an MQTT_HOST entry in application.yml pointing to the IP address or domain of the (soon-to-be-installed) MQTT server. You will need to set that up next.
  11. Open localhost:3000.
  12. Although you can now try things out in your browser, you will still need to provision an MQTT server before you can control a FarmBot.
  13. Raise an issue if you hit problems with any of these steps. We can't fix issues we don't know about.

*Give permission to user to create database:

sudo -u postgres psql
CREATE USER "user" WITH SUPERUSER;

Q: Is Dokku / Docker supported?

Dokku (a Docker management system) is partially supported. Pull requests welcome. Please see deployment.md for more information.

Config Settings (important)

We try our best to follow the 12 Factor Methodology. Part of that means using ENV variables as a means of storing configuration. Your server won't run without setting ENV variables first.

You can accomplish this by setting the ENV variables directly from your shell / server management tool or by writing an application.yml file.

See config/application.example.yml for a list of all the variables that must be set.

Encryption keys: Encryption keys will be auto-generated if not present. They can be reset using rake keys:generate. If ENV['RSA_KEY'] is set, it will be used in place of the *.pem files. Useful for environments like Heroku, where file system access is not allowed.

We can't fix issues we don't know about. Please submit an issue if you are having trouble installing on your local machine.

Q: How can I Generate an API token?

You must pass a token string into most HTTP requests under the Authorization: request header.

Here's what a response looks like when you request a token:

{
    "token": {
        "unencoded": {
            "sub": "test123@test.com",
            "iat": 1459109728,
            "jti": "922a5a0d-0b3a-4767-9318-1e41ae600352",
            "iss": "http://localhost:3000/",
            "exp": 1459455328,
            "mqtt": "localhost",
            "bot": "aa7bb37f-5ba3-4654-b2e4-58ed5746508c"
        },
        "encoded":
        // THE IMPORTANT PART IS HERE!!:
         "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ0ZXN0MTIzQHRlc3QuY29tIiwiaWF0IjoxNDU5MTA5NzI4LCJqdGkiOiI5MjJhNWEwZC0wYjNhLTQ3NjctOTMxOC0xZTQxYWU2MDAzNTIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAvIiwiZXhwIjoxNDU5NDU1MzI4LCJtcXR0IjoibG9jYWxob3N0IiwiYm90IjoiYWE3YmIzN2YtNWJhMy00NjU0LWIyZTQtNThlZDU3NDY1MDhjIn0.KpkNGR9YH68AF3iHP48GormqXzspBJrDGm23aMFGyL_eRIN8iKzy4gw733SaJgFjmebJOqZkz3cly9P5ZpCKwlaxAyn9RvfjQgFcUK0mywWAAvKp5lHfOFLhBBGICTW1r4HcZBgY1zTzVBw4BqS4zM7Y0BAAsflYRdl4dDRG_236p9ETCj0MSYxFagfLLLq0W63943jSJtNwv_nzfqi3TTi0xASB14k5vYMzUDXrC-Z2iBdgmwAYUZUVTi2HsfzkIkRcTZGE7l-rF6lvYKIiKpYx23x_d7xGjnQb8hqbDmLDRXZJnSBY3zGY7oEURxncGBMUp4F_Yaf3ftg4Ry7CiA"
    }
}

Important: The response is provided as JSON for human readability. For your Authorization header, you will only be using data.token.encoded. In this example, it's the string starting with eyJ0eXAiOiJ...

Via CURL

curl -H "Content-Type: application/json" \
     -X POST \
     -d '{"user":{"email":"test123@test.com","password":"password123"}}' \
     https://my.farmbot.io/api/tokens

Via JQuery

Since the API supports CORS, you can generate your token right in the browser.

Here's an example:

$.ajax({
    url: "https://my.farmbot.io/api/tokens",
    type: "POST",
    data: JSON.stringify({user: {email: 'admin@admin.com', password: 'password123'}}),
    contentType: "application/json",
    success: function (data) {
                 // You can now use your token:
                 var MY_SHINY_TOKEN = data.token.encoded;
             }
});

Want to Help?

Low Hanging Fruit. Raise an issue if you have any questions.

Translating the web app into your language

Thanks for your interest in internationalizing the FarmBot web app! To add translations:

  1. Fork this repo
  2. Navigate to /public/app-resources/languages and run the command node _helper.js yy where yy is your language's language code. Eg: ru for Russian.
  3. Edit the translations in the file created in the previous step: "phrase": "translated phrase".
  4. When you have updated or added new translations, commit/push your changes and submit a pull request.