JS where can I find docs

I saw at FarmBot JS | FarmBot Developer Documentation that I can work with farmbot with javascript, or JS. There I saw a link “See the annotated type definitions for available methods and properties. – github. com/FarmBot/farmbot-js/blob/main/dist/farmbot.d.ts”

It redirected me to github into document farmbot.d.ts. But there were nothing that could help me (or I just didn’t saw it helpfull) - there were no commands like in this example:

bot
  .home({ axis: "x", speed: 800 })
  .then(function (ack) {
    console.log("X Axis is now at 0.");
  })
  .catch(function (err) {
    console.log("Failed to bring X axis home.");
  })

I saw that people know from somewhere about coding like in this topic - Turn on light using JS web and API

In his example there was return farmbot123.togglePin({ pin_number: 7 }); command.
From where can I access these commands? Or where can I get documentation about FarmBot JS?

Thanks!

Hi @Nikita

That file seems way too old . . .
I use farmbot-js/dist/farmbot.js at main · FarmBot/farmbot-js · GitHub

Note: bot control commands still use CeleryScript over MQTT underneath. bot resources are managed over the JSON WebApi.

2 Likes

Thank you, @jsimmonds ! One more question - I saw lines 139-142 with this code:

/** Bring a particular axis (or all of them) to position 0 in Z Y X order. */
        this.home = function (args) {
            return _this.send((0, util_1.rpcRequest)([{ kind: "home", args: args }]));
        };

If I am right, it sends all XYZ to their home position, that is 0,0,0. The code from example sends only X to its home position:

bot
  .home({ axis: "x", speed: 800 })
  .then(function (ack) {
    console.log("X Axis is now at 0.");
  })
  .catch(function (err) {
    console.log("Failed to bring X axis home.");
  })

How can I understand, how many parameters and which I have that I should input? In current example, I am calling .home({ axis: "x", speed: 800 }) - I have axis and speed in current example.

1 Like

I will reply soon to your question.

edit

Hi @Nikita please refer to farmbot-js/dist/corpus.d.ts at main · FarmBot/farmbot-js · GitHub

export declare type ALLOWED_AXIS = "all" | "x" | "y" | "z";

export interface Home {
    comment?: string | undefined;
    kind: "home";
    args: {
        axis: ALLOWED_AXIS;
        speed: CSInteger;
    };
    body?: HomeBodyItem[] | undefined;
}
1 Like

Yep, it works. Thank you! You are a live saver