Function deviceEval

Evaluates some code on an Espruino device.

Options:

  • timeoutMs: how many millis to wait before assuming code failed. If not specified, device.evalTimeoutMs is used as a default.
  • assumeExlusive: assume device is not producing any other output than for our evaluation

A random string is created to pair eval requests and responses. code will be run on the device, with the result wrapped in JSON, and in turn wrapped in a object that is sent back.

The actual code that gets sent to the device is then: \x10${evalReplyPrefix}(JSON.stringify({reply:"${id}", result:JSON.stringify(${code})}))\n

For example, it might end up being: \x10Bluetooth.println(JSON.stringify({reply: "a35gP", result: "{ 'x': '10' }" }))\n

  • Parameters

    • code: string

      Code to evaluation

    • opts: EvalOpts = {}

      Options for evaluation

    • device: EspruinoDevice

      Device to execute on

    • evalReplyPrefix: string

      How to send code back (eg Bluetooth.println, console.log)

    • debug: boolean

      If true, the full evaled code is printed locally to the console

    • warn: ((m: string) => void)

      Callback to display warnings

        • (m): void
        • Parameters

          • m: string

          Returns void

    Returns Promise<string>