# Celery script export from sequences and compatiblity with cs\_eval()

**URL:** <https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188>\
**Category:** Software\
**Created:** [June 13, 2024, 9:57am UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188 "2024-06-13T09:57:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvillion](https://forum.farmbot.org/user_avatar/forum.farmbot.org/mvillion/32/5152_2.png) [@mvillion](https://forum.farmbot.org/u/mvillion)\
**Post date:** [June 13, 2024, 9:57am UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/1 "2024-06-13T09:57:27Z")

</div>

I have been testing the export from a simple WAIT statement to get the celery script to be able to contain it with LUA via the cs\_eval() function as some sequence statements are not directly drivable from LUA. My attempts to get the sequence I want failed so I went for something simple.

The celery script export from WAIT is

```auto
{
  "kind": "wait",
  "args": {
    "milliseconds": 1000
  }
}

```

embedding that into

```auto
cs_eval({
  "kind": "wait",
  "args": {
    "milliseconds": 1000
  }
}
)

```

creates this argument

![Screenshot 2024-06-13 at 10.57.01](https://forum.farmbot.org/uploads/default/original/2X/4/4df0e8ff477dd53655e739e9b911e480e9d3f192.png)

Looking at the examples in the documentation the syntax does not look the same.

Is the issue syntax, structure or something else.  
I was expecting to be able to cut paste from the displayed celery script into cs\_eval to obtain the same result.

Any ideas?

---

<div class="post-metadata">

**Author:** ![roryaronson](https://forum.farmbot.org/user_avatar/forum.farmbot.org/roryaronson/32/24_2.png) [@roryaronson](https://forum.farmbot.org/u/roryaronson)\
**Post date:** [June 13, 2024, 6:37pm UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/2 "2024-06-13T18:37:08Z")

</div>

> [@mvillion](#):
>
> Looking at the examples in the documentation the syntax does not look the same.

Please thoroughly read the documentation on the [advanced Lua functions page](https://developer.farm.bot/v15/lua/functions/advanced):

 ![Screenshot 2024-06-13 at 11.35.49 AM](https://forum.farmbot.org/uploads/default/original/2X/e/ed78d0a0292887eb5f18251ff471c8d83870d479.png)

---

<div class="post-metadata">

**Author:** ![mvillion](https://forum.farmbot.org/user_avatar/forum.farmbot.org/mvillion/32/5152_2.png) [@mvillion](https://forum.farmbot.org/u/mvillion)\
**Post date:** [June 13, 2024, 7:36pm UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/3 "2024-06-13T19:36:05Z")

</div>

I have tried that but it did not work. This was my attempt of code translation

From

```auto
{
  "kind": "wait",
  "args": {
    "milliseconds": 1000
  }
}

```

To

```auto
cs_eval({
  kind = "wait",
  args = {
    milliseconds = 1000
  }
})

```

Whilst I did not see the documentation (Now found), I modelled my code on this example which executes without issue. I have studied the syntax and cannot see any difference in the structure.

```auto
cs_eval({
  kind = "rpc_request",
  args = {
    label = "example",
    priority = 500
  },
  body = {
    {
      kind = "move_absolute",
      args = {
        location = {kind = "coordinate", args = {x = 2, y = 2, z = 2}},
        offset = {kind = "coordinate", args = {x = 0, y = 0, z = 0}},
        speed = 100
      }
    }
  }
})

```

As my code did not work, I asked the question from the beginning as I must be missing something so obvious. The only reason I am attempting to model WAIT is because it is so simple. I am trying to control the LED 3 and LED 4 from LUA which is only available in celery. As I could get that to work I assumed it was because I did not know something so I went for the easiest code possible - and I cannot get that to work either. LOL. I cannot see what I have missed.

I still get the same error and I am totally puzzled.

![Screenshot 2024-06-13 at 10.57.01](https://forum.farmbot.org/uploads/default/original/2X/4/4df0e8ff477dd53655e739e9b911e480e9d3f192.png)

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [June 14, 2024, 4:35am UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/4 "2024-06-14T04:35:02Z")

</div>

@mvillion I didn’t try to fix your example tl;dr but here’s how to use the (simpler) **rpc()** Lua function to control Box Leds 😯

 ![image](https://forum.farmbot.org/uploads/default/original/2X/d/dfc8ac86b02f6f637110c04cfcf8cb2df0435213.png)

---

<div class="post-metadata">

**Author:** ![mvillion](https://forum.farmbot.org/user_avatar/forum.farmbot.org/mvillion/32/5152_2.png) [@mvillion](https://forum.farmbot.org/u/mvillion)\
**Post date:** [June 14, 2024, 7:39am UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/5 "2024-06-14T07:39:41Z")

</div>

Thanks @jsimmonds. That worked perfectly.

```auto
rpc() worked
cs_eval() did not work

```

LED 3 ON

```auto
rpc({
  kind = "write_pin",
  args = {
    pin_value = 1,
    pin_mode = 0,
    pin_number = {
      kind = "named_pin",
      args = {
        pin_type = "BoxLed3",
        pin_id = -1
      }
    }
  }
})

```

I can now control more hardware from within LUA code. 😀

The documentation is a little light about the difference between them.  
Even now, rereading the documentation cs\_eval ‘looks’ like the right one to use, but hey ho.

@roryaronson Are you able to provide some clarity in the documentation about the usage for the two commands?

---

<div class="post-metadata">

**Author:** ![roryaronson](https://forum.farmbot.org/user_avatar/forum.farmbot.org/roryaronson/32/24_2.png) [@roryaronson](https://forum.farmbot.org/u/roryaronson)\
**Post date:** [June 14, 2024, 5:47pm UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/6 "2024-06-14T17:47:42Z")

</div>

Sorry for the confusion @mvillion! The issue with this:

```auto
cs_eval( {
    kind = "wait",
    args = {
      milliseconds = 1000
    }
  })

```

Is that `cs_eval()` is expecting an `rpc_request`, not the CeleryScript straight from the sequence editor. So the CeleryScript for the `wait` must be put into the `body` of an `rpc_request`:

```auto
cs_eval({
  kind = "rpc_request",
  args = {
    label = "example",
    priority = 500
  },
  body = {
   {
     kind = "wait",
     args = {
       milliseconds = 1000
     }
   }
  }
})

```

An RPC request is how commands are ultimately formed under the hood in FarmBot OS and used by the CeleryScript Virtual Machine (CSVM). Because it is a bit tedious to write out the full `rpc_request` syntax every time, we later created `rpc()` which does the wrapping for you. In taking this shortcut you forego the ability to custom set the `label` and `priority` fields of the RPC, but these are really not necessary for 3rd party developers to need to adjust. I would suggest not attempting to use these extra fields or dealing with the added syntax and just sticking with the simpler `rpc()` command.

I have just updated the developer documentation to point people looking at `cs_eval()` to use the simpler `rpc()` function. Hopefully it provides some more clarity.

---

<div class="post-metadata">

**Author:** ![mvillion](https://forum.farmbot.org/user_avatar/forum.farmbot.org/mvillion/32/5152_2.png) [@mvillion](https://forum.farmbot.org/u/mvillion)\
**Post date:** [June 14, 2024, 9:23pm UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/7 "2024-06-14T21:23:27Z")

</div>

I love the documentation update. Thank you

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [June 15, 2024, 10:01am UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/8 "2024-06-15T10:01:32Z")

</div>

> [@mvillion](#):
>
> Thanks @jsimmonds. That worked

Now my mission is to make that code use **parameterization** 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum.farmbot.org/user_avatar/forum.farmbot.org/system/32/4564_2.png) [@system](https://forum.farmbot.org/u/system)\
**Post date:** [July 15, 2024, 10:01am UTC](https://forum.farmbot.org/t/celery-script-export-from-sequences-and-compatiblity-with-cs-eval/9188/9 "2024-07-15T10:01:38Z")

</div>

Closed on July 15, 2024, 10:01am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
